Dear Support,
I’m trying to import annotations into a PDF from an xFDF file using the Aspose.PDF library. The process works well for most of my requirements, but I am encountering an issue with importing bold fonts.
To investigate, I first decided to check how Aspose.PDF exports such fonts to xFDF, so I used the following code:
private void exportXfdf(Task task, String pdfPath) throws IOException {
PdfAnnotationEditor editor = new PdfAnnotationEditor();
editor.bindPdf(pdfPath);
FileOutputStream fileStream = new FileOutputStream(Paths.get(task.getDocDir().toString(), "exported.fdf").toString());
editor.exportAnnotationsToXfdf(fileStream);
editor.close();
fileStream.close();
}
Then, I attempted to import same annotations back into the PDF using this code:
private void importXfdfToPdf(Task task, String pdfPath, String fdfPath) {
try (PdfAnnotationEditor editor = new PdfAnnotationEditor()) {
editor.bindPdf(pdfPath);
editor.importAnnotationsFromXfdf(fdfPath, new AnnotationType[]{AnnotationType.FreeText, AnnotationType.Highlight});
editor.save(*some output path*);
} catch (Exception e) {
throw new NnpMigrationDocToolsException("Error merging PDF and xFDF files!", e);
}
}
The annotations were imported correctly, but the annotation with the bold font was displayed incorrectly. The font was neither bold nor Arial:
annot_before.png (2.1 KB)
After I clicked on the text of this annotation in Adobe, the text began to display correctly:
annot_after.png (2.0 KB)
However, I received the following error:
error.png (5.1 KB)
Could you please advise whether this issue is related to the API itself or if it is caused by an incorrect xFDF file configuration? May it be connected to font embedding? Any guidance would be greatly appreciated, as this issue is currently a blocker for my project’s progress.
I have also attached three documents: the original PDF, the xFDF file, and the output PDF after the import attempt:
files.zip (866.0 KB)
Thank you in advance for your assistance!