Page 1 of 1

layout and header, footer not present in PDF

PostPosted: Thu Sep 19, 2013 6:37 pm
by sunny8875
Hi,
I am trying to create word document programatically as mentioned below, But I am facing problem while converting the generated word document as explained below

Code: Select all
WordprocessingMLPackage wordprocessingMLPackage = WordprocessingMLPackage.createPackage();
// Add all the data including header, footer to the document
PdfConversion conversion = new Conversion(wordMLPackage);
conversion.output(byteArrayOutputStream, new PdfSettings());

The pdf generated from above is not containing the header and footer parts and even some of the colors are not being applied on the content, And the table header that is generated in all pages of word document is not present in all pages of PDF.

Whereas after creating the word document, save it and then read it using as mentioned in the below code and then convert it to pdf it is working fine
Code: Select all
WordprocessingMLPackage.load(new java.io.File("file path of the document generate programatically"));


What should I do to make it work even when the document is generated programatically, I am using docx4j 2.8.1 downloaded from maven central. Please help me out in resolving this issue.

Thanks

Re: layout and header, footer not present in PDF

PostPosted: Thu Sep 19, 2013 11:25 pm
by jason
Are you saying that PDF output only works correctly with docx4j 2.8.1, if you save the docx you created programmatically and re-open it first?

If that is so, it may be because there are some data structures which are not updated to match your programmatic alterations.

A workaround would be to save your docx pkg to a byte array, and then open that as a new pkg.

Re: layout and header, footer not present in PDF

PostPosted: Fri Sep 20, 2013 12:48 am
by sunny8875
Hi Jason,
Thanks for your quick reply. Please find below my two cases explained

Case 1: Using the below code the colors, header, footer etc.. are not reflected in the PDF document
Code: Select all
// 1. Create the document programatically
WordprocessingMLPackage wordprocessingMLPackage = WordprocessingMLPackage.createPackage();
// Add all the data including header, footer to the document
// 2. Convert the created document to PDF
PdfConversion conversion = new Conversion(wordMLPackage);
conversion.output(byteArrayOutputStream, new PdfSettings());


Case 2: The PDF is containing all the data if the document is save first and then read it and then converted as mentioned below
Code: Select all
/ 1. Create the document programatically
WordprocessingMLPackage wordprocessingMLPackage = WordprocessingMLPackage.createPackage();
// Add all the data including header, footer to the document
// 2. Now save the created document
new SaveToZipFile(wordMLPackage).save(outputStream);
// 3. Load/read the saved document
WordprocessingMLPackage newWordprocessingMLPackage = WordprocessingMLPackage.load(new java.io.File("path of the document generated in the above step"));
// 4. Convert the newly loaded document to PDF
PdfConversion conversion = new Conversion(newWordprocessingMLPackage);
conversion.output(outputStreamForpdf, new PdfSettings());


Please let me know how should I handle this. And also the table header row which is repeated in all pages in word document is not repeated and displayed in all pages of PDF - Is there any work around to do this.

Thanks