Line/arrow annotations added with Aspose.PDF for Java do not display in Chrome’s built-in PDF viewer. They do display when the PDF is viewed with Acrobat, Acrobat Reader and the Preview app on macOS. Note that line annotations created directly in Acrobat display in Chrome wthout issue.
Below is an example that produces a PDF demonstrating the issue. An input document to use with the example is attached.
input_document.pdf (30.7 KB)
Versions used to test this issue…
- Aspose.PDF for Java com.aspose:aspose-pdf:21.6
- Chrome for macOS Version 102.0.5005.61 (Official Build) (x86_64)
- Chrome for Windows Version 102.0.5005.63 (Official Build) (64-bit)
Example code…
public class LineAnnotationBug {
public static void main(String[] args) {
Document inputDoc = null;
try {
// Set to the path of your Aspose license file or comment out
License pdfLicense = new License();
pdfLicense.setLicense("aspose.lic");
// Open input document
inputDoc = new Document("input_document.pdf");
// Example code directly from....
// https://docs.aspose.com/pdf/java/figures-annotation/#how-to-add-line-annotation-into-existing-pdf-file
Page page = inputDoc.getPages().get_Item(1);
// Add line annotation to the page
LineAnnotation lineAnnotation = new LineAnnotation(page, new Rectangle(550, 93, 562, 439),
new Point(556, 99), new Point(556, 443));
lineAnnotation.setTitle("John Smith");
lineAnnotation.setColor(Color.getRed());
lineAnnotation.setWidth(3);
lineAnnotation.setStartingStyle(LineEnding.OpenArrow);
lineAnnotation.setEndingStyle(LineEnding.OpenArrow);
lineAnnotation.setPopup(new PopupAnnotation(page, new Rectangle(842, 124, 1021, 266)));
page.getAnnotations().add(lineAnnotation);
// Save output document
inputDoc.save("output_document.pdf");
} catch(Exception ex) {
System.err.printf("An exception occurred: %s%n", ex.getLocalizedMessage());
System.exit(1);
} finally {
if (inputDoc != null) {
inputDoc.close();
inputDoc.dispose();
}
}
}
}