Hi Team,
When I am converting doc to pdf, I am getting “Error! Reference source not found.” in pdf file and if I use pdfSaveOptions.setUpdateFields(false), table of contents is showing incorrect page numbers in pdf file.
Please suggest.
private static void docToPdf() throws IOException {
// InputStream stream = FileUtils.openInputStream(new File("/home/govindsharma/Downloads/WH02EU Service Wholesale Agreement-EU_Non EU EFTA (COT01019).docx"));
InputStream stream = FileUtils.openInputStream(new File("/home/govindsharma/Downloads/Distributörsavtal SE Sverige-Alcadon Group AB v_1_2 2023-05-19.docx"));
try {
LoadOptions lo = new LoadOptions();
lo.setPreserveIncludePictureField(true);
// lo.setUpdateDirtyFields(true);
Document document = new Document(stream, lo);
// document.updateFields();
// File file = new File("/home/govindsharma/Downloads/WH02EU Service Wholesale Agreement-EU_Non EU EFTA (COT01019).pdf");
File file = new File("/home/govindsharma/Downloads/Distributörsavtal SE Sverige-Alcadon Group AB v_1_2 2023-05-19.pdf");
FileOutputStream faos = new FileOutputStream(file);
// lockFileNameFieldInDocument(document);
com.aspose.words.PdfSaveOptions pdfSaveOptions = new com.aspose.words.PdfSaveOptions();
pdfSaveOptions.setUpdateFields(true);
// pdfSaveOptions.setUpdateFields(false);
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);
pdfSaveOptions.setMemoryOptimization(true);
document.save(faos, pdfSaveOptions);
} catch (Exception ex) {
}
}