PDF Annotations Sample Code: Ink, Link, Polygon, and More

PDF Annotations Sample Code: Ink, Link, Polygon, and More

Published September 4, 2024

Whether you’re reviewing documents, providing feedback, or keeping track of important details, PDF software makes it easy to highlight, comment, and mark up files with precision using annotations.

Adobe PDF Library has a bunch of options for using annotations in PDFs, let's take a look at the code sample descriptions to see what options are available for PDF developers. 

Annotation Copy/Paste

Copy/pasting the annotations from one PDF file to another PDF file is helpful if you are working on multiple documents or versions of a report, and you want to make sure that the same comments, highlights, or notes are present across all files to maintain consistency. 

Instead of manually recreating annotations, copying and pasting saves time, especially when the same feedback or markup is relevant to multiple documents. In a collaborative environment, one person might review and annotate a document, and those annotations may need to be transferred to another version of the document that someone else is working on.

Ink Annotations

An Ink annotation is a freeform line, like what you would create with a pen, or with a stylus on a mobile device. With ink annotations, you specify the vertices, and the PDF viewer will automatically draw smoothened curves linking them. This means that you do not have to record all the movements of a graphic pen on your PDF viewer. In collaborative environments, ink annotations provide a way to offer visual feedback that is more expressive than text alone. Reviewers can circle errors, draw arrows to indicate changes, or add handwritten comments, making the feedback process more dynamic and clear. 

Diagrams, sketches, or quick illustrations can be more easily conveyed through ink annotations, especially in technical fields where visual representations are crucial for understanding complex concepts. With a stylus or touch-enabled device, adding ink annotations can be faster and more intuitive than typing, especially for quick notes or when on the go.

Link Annotations

Link annotations create a PDF file with an embedded hyperlink, which takes the reader to the second page of the document. Sometimes you may want to add links into your PDF to direct viewers to a different portion of the file for easy referencing or to external locations such as a URL or another PDF document. Programmatically modifying Link annotations can reduce manual efforts when the destination reference has changed (e.g. if the destination http address has changed). 

Link annotations make it easy to navigate between different sections within the same document or to external resources like websites or other documents. This improves the reader's experience by providing quick access to relevant information. By linking to external sources or related documents, users can access additional data without leaving the PDF. This is particularly useful for referencing supporting materials, citations, or further reading.

Did you know you can also extract text from annotations? Check out our blog on extraction code samples to learn more. 

Polygon Annotations

Polygon annotations generate a polygon shape (a triangle) as an annotation to the file. Polygon annotations can be used where complex polygons are needed, rather than rectangles, to define the shape and location of the object in a more precise way. Unlike simple rectangular highlights, polygon annotations allow users to draw attention to irregular or complex areas within a document, such as specific parts of a diagram, image, or map. Polygon annotations offer more precise marking, especially when dealing with non-linear content. This is particularly useful in technical documents, architectural plans, or any content that doesn't conform to standard shapes. Users can customize the shape, size, and angle of a polygon annotation to better fit their needs, making it a flexible tool for different types of content.

Poly Line Annotations

A polyline can trace a specific path or route on a map or diagram, making it easy to visualize directions, boundaries, or progressions. In technical drawings, blueprints, or architectural plans, polylines can outline areas of interest, like rooms, zones, or sections that need attention. Polylines can be used to draw attention to specific sections of text or images, allowing users to make clear visual comments or suggestions.

In diagrams or flowcharts, polylines can illustrate the flow of processes, connections between elements, or movement paths. Unlike simple lines, polylines can have multiple segments, allowing for more complex and precise annotations. This is especially helpful in detailed technical or scientific documents. Polylines can also be customized with different colors, thicknesses, and styles, making them a versatile tool for various annotation needs.

Learn More about PDF Annotations

If you want to learn more about PDF annotations, our documentation has more information on using annotations with Adobe PDF Library.