- Code: Select all
<w:document xmlns:w=tons of different schemas">
<w:body>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840" w:code="1" />
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" />
</w:sectPr>
</w:body>
</w:document>
The following makes it invisible
- Code: Select all
drawing = newImage(titleImageFile, null, null, 0, 1);
p.getContent().add(r);
r.getContent().add(drawing);
p.getPPr().getJc().setVal(JcEnumeration.RIGHT);
docx.getMainDocumentPart().addObject(p);
So does
- Code: Select all
drawing = newImage(titleImageFile, null, null, 0, 1);
p.getContent().add(r);
r.getContent().add(drawing);
Ind ind = p.getPPr().getInd();
ind.setFirstLine(BigInteger.valueOf(DocxSupport.inchToDXA((float) 0.5)));
ind.setLeft(BigInteger.valueOf(DocxSupport.inchToDXA((float) 4.0)));
But the plain old way works fine:
- Code: Select all
drawing = newImage(titleImageFile, null, null, 0, 1);
p.getContent().add(r);
r.getContent().add(drawing);
docx.getMainDocumentPart().addObject(p);
Any ideas why this is happening? For reference, the newImage function I'm using (almost exactly from the example):
- Code: Select all
private org.docx4j.wml.P newImage(File file, String filenameHint, String altText, int id1, int id2) throws Exception {
java.io.InputStream is = new java.io.FileInputStream(file);
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
if (length > Integer.MAX_VALUE) {
System.out.println("File too large!!");
return null;
}
byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
System.out.println("Could not completely read file " + file.getName());
return null;
}
is.close();
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(docx, bytes);
org.docx4j.dml.wordprocessingDrawing.Inline inline = imagePart.createImageInline(filenameHint, altText,
id1, id2, false);
// Now add the inline in w:p/w:r/w:drawing
org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
org.docx4j.wml.P p = factory.createP();
org.docx4j.wml.R run = factory.createR();
p.getContent().add(run);
org.docx4j.wml.Drawing drawing = factory.createDrawing();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
return p;
}