Can't import Text Annotations using importFdf() method

Hi! I’m currently experiencing an issue with the Aspose.PDF for Java library, specifically when attempting to import Text Annotations from an FDF file into a PDF document using the ‘importFdf()’ method.

Despite following the documented procedure for importing FDF data into a PDF file, the text annotations do not appear in the PDF after the import process is completed. The FDF file contains text annotations that need to be merged into the existing PDF document.

Code:

private void importFdfToPdf(String pdfPath, String fdfPath) throws IOException {

// Open document
com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form();
form.bindPdf(pdfPath);

// Open FDF file
java.io.FileInputStream fdfInputStream = new FileInputStream(fdfPath);

// Import FDF data
form.importFdf(fdfInputStream);

 // Close file stream
fdfInputStream.close();

// Save updated PDF
form.save("C:\\Users\\ixtadmin\\Desktop\\merged.pdf");

// Dispose the form object
form.dispose();

}

I have attached the relevant PDF and FDF files for your review. Could anyone assist me in resolving this issue? If there is a known bug or if I’m missing a step in the process, any guidance or workaround would be greatly appreciated.

files.zip (17.7 KB)

Environment Details:

  • Aspose.PDF for Java version: 20.12
  • Java version: 11
  • Operating System: Windows

Thank you!

@grigonaz

Please check the output file that we generated using 24.3 version of the API in our environment and let us know if you still notice any issues in it.
merged.pdf (20.9 KB)

Hi! Thank you for your reply. The document was merged correctly. Do I understand correctly that you used the exact same code? If so, could the issue be with the API version that I’m using?

@grigonaz

We used the exact same code as you shared. The only difference is the API version. Please try to use the latest version of the API and let us know if you still face any issues.

1 Like

@asad.ali

I was able to import annotations into a PDF from an xFDF format using that code in version 20.12:

private void importAnnotationsToPdf(Task task, String pdfPath, String fdfPath) {
    PdfAnnotationEditor editor = new PdfAnnotationEditor();
    try {
        editor.bindPdf(pdfPath);
        editor.importAnnotationsFromXfdf(fdfPath);
        editor.save(Paths.get(task.getDocDir().toString(), "merged.pdf").toString());
        LOGGER.info("Document '{}': PDF and xFDF files were successfully merged.", this.documentLogName);
    } catch (Exception e) {
        LOGGER.error("Document '{}': Error merging PDF and xFDF files! {}", this.documentLogName, e.getMessage());
        throw new Exception("Error merging PDF and xFDF files!", e);
    } finally {
        editor.dispose();
    }
}

Thanks!

@grigonaz

Its nice to know that things have worked at your end. Please feel free to create a new topic in case you need any kind of assistance.