I'm using docx4j to convert docx files to PDFs.
Page numbers in the footer are not being rendered correctly though.
Suppose I have a 3 page docx document: each page in the generated pdf file will have the same page number, and this page number is either 1 or the max page number.
I'm using the org.docx4j.convert.out.pdf.viaXSLFO.Conversion converter - overall it produces really good results.
Any help or pointers resolving this would be very much appreciated.
Thanks.
Sample code...
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
public class DocxToPdfTest {
public static void test() throws Exception {
String docxFile = "test-file-with-page-numbers-r.docx";
WordprocessingMLPackage pkg = WordprocessingMLPackage.load(new File(docxFile));
org.docx4j.convert.out.pdf.PdfConversion c
= new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(pkg);
// = new org.docx4j.convert.out.pdf.viaIText.Conversion(pkg);
String pdfFile = changeExtensionToPdf(docxFile);
OutputStream os = new FileOutputStream(pdfFile);
c.output(os);
os.close();
System.out.println("Finished");
}
private static String changeExtensionToPdf(String path) {
int markerIndex = path.lastIndexOf(".docx");
String pdfFile = path.substring(0, markerIndex) + ".pdf";
return pdfFile;
}
public static void main(String[] args) {
try {
DocxToPdfTest.test();
} catch (Exception e) {
e.printStackTrace();
}
}
}