Hi there,
I got missing pages problem when I transform existed word file to pdf format.
The detail steps are shown below
Step 1. Use word template file to generate temp word file.
Step 2. Transform generated temp word file to PDF.
In step 1, I just want to check whether or not the mail merge works and it does work. But in step 2, I get a missing pages PDF.
Does anyone get this problem before ? How could I get the right PDF file ?
All related files are enclosed.
CAAML_natural.docx is the template file;
CAAML_natural_tmp.docx is the generated temp file;
CAAML_natural.pdf is the missing pages file.
My testing code is:
public static void main(String… args) throws Exception {
Document doc = new Document(getMyDir() + "CAAML_natural.docx");
final String[] keysArray = {"background"};
final Object[] valuesArray = {testStr2};
final FormFieldCollection formFields = doc.getRange().getFormFields();
for (final FormField field : formFields) {
if ("background".equals(field.getName())) {
field.setResult(testStr2);
}
}
doc.getMailMergeSettings().setViewMergedData(true);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
doc.getMailMerge().execute(keysArray, valuesArray);
doc.save(getMyDir() + "CAAML_natural_tmp.docx", SaveFormat.DOCX);
Document doc2 = new Document(getMyDir() + "CAAML_natural_tmp.docx");
System.out.println("doc2.getPageCount():" + doc2.getPageCount());
doc2.save(getMyDir() + "CAAML_natural.pdf", SaveFormat.PDF);
}