Adding sticky note annotations to a PDF document
Adding sticky note annotations to PDFs programmatically enables teams to automate document review workflows, build commenting systems, and implement collaborative feedback pipelines. Whether you’re creating automated review comments, building document feedback tools, implementing quality assurance workflows, creating annotation systems for technical reviews, or building collaborative editing platforms, sticky note annotations provide icon-based comment markers that display text content when clicked. Unlike free text annotations that render text directly on the page, sticky note annotations appear as compact icons that expand to show full comment content, conserving page space while enabling detailed feedback.
How Nutrient helps you achieve this
Nutrient Java SDK handles PDF sticky note annotation structures and appearance generation. With the SDK, you don’t need to worry about:
- Parsing text annotation dictionaries and popup window configurations
- Managing sticky note icon styles and appearance states
- Handling annotation author metadata and timestamp formatting
- Complex annotation popup positioning and content rendering
Instead, Nutrient provides an API that handles all the complexity behind the scenes, letting you focus on your business logic.
Complete implementation
Below is a complete working example that demonstrates adding sticky note annotations with various colors to a PDF. The following lines set up the Java application. The package declaration and import statements bring in all necessary classes from the Nutrient SDK:
package io.nutrient.Sample;
import io.nutrient.sdk.Document;import io.nutrient.sdk.types.Color;import io.nutrient.sdk.editors.PdfEditor;import io.nutrient.sdk.editors.pdf.pages.PdfPageCollection;import io.nutrient.sdk.editors.pdf.pages.PdfPage;import io.nutrient.sdk.editors.pdf.annotations.PdfAnnotationCollection;import io.nutrient.sdk.editors.pdf.annotations.PdfTextAnnotation;
public class StickyNoteAnnotations {The main method defines the entry point that will contain the sticky note annotation creation logic:
public static void main(String[] args) {Working with sticky note annotations
The Document.open() call opens the PDF document. The try-with-resources statement ensures the document is automatically closed when you’re done, preventing resource leaks. The following code creates a PDF editor, accesses the page collection, ensures at least one page exists by adding a letter-size page (612×792 points) if the document is empty, and retrieves the annotation collection from the first page:
try (Document document = Document.open("input.pdf")) { PdfEditor editor = PdfEditor.edit(document); PdfPageCollection pages = editor.getPageCollection();
if (pages.getCount() == 0) { pages.add(612.0f, 792.0f); }
PdfPage page = pages.getFirst(); PdfAnnotationCollection annotations = page.getAnnotationCollection();Adding a sticky note annotation
The following code adds a sticky note annotation at coordinates (100, 700). The addStickyNote() method creates a sticky note icon with position parameters (x, y), author name, subject line, and detailed contents text. Sticky note annotations are created with a default yellow color (ARGB: 255, 255, 255, 0) and render as a compact icon that expands to display a popup window containing the subject and contents when clicked. The icon position (100, 700) places it near the top-left area of the page, making it visible for reviewers while not obscuring important content:
PdfTextAnnotation stickyNote = annotations.addStickyNote( 100.0f, 700.0f, "Review Author", "Clarification Needed", "This section needs clarification. Please add more details about the implementation." );Adding multiple sticky notes
The following code demonstrates adding multiple sticky notes with customized colors to categorize comment types. The first sticky note is positioned at coordinates (100, 600) and customized with a red color using ARGB values (255, 255, 0, 0) via the setColor() method. Red sticky notes are commonly used for urgent issues, blocking problems, or critical feedback requiring immediate attention. The second sticky note is positioned at coordinates (100, 500) and customized with a green color using ARGB values (255, 0, 255, 0). Green sticky notes are commonly used for approval indicators, positive feedback, or resolved issues. The vertical spacing of 100 points between notes (700, 600, 500) prevents icon overlap while keeping all comments visible in the same page region:
PdfTextAnnotation urgentNote = annotations.addStickyNote( 100.0f, 600.0f, "Reviewer", "Urgent Issue", "This issue must be addressed before release." ); // Optionally customize the color urgentNote.setColor(Color.fromArgb(255, 255, 0, 0));
PdfTextAnnotation approvalNote = annotations.addStickyNote( 100.0f, 500.0f, "Approver", "Approved", "This section looks good." ); // Optionally customize the color approvalNote.setColor(Color.fromArgb(255, 0, 255, 0));Saving the document
The final code block saves the document with all sticky note annotations and closes the editor:
editor.saveAs("output.pdf"); editor.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); } }}Conclusion
The sticky note annotation workflow consists of several key operations:
- Open the document and create an editor.
- Access the page collection and ensure at least one page exists.
- Retrieve the annotation collection for the target page.
- Add basic sticky note annotations with default yellow color at specified coordinates.
- Specify author, subject, and detailed contents for each sticky note.
- Customize sticky note colors using
setColor()with ARGB values for categorization. - Use red sticky notes for urgent issues and critical feedback.
- Use green sticky notes for approvals and positive feedback.
- Position sticky notes with appropriate vertical spacing to prevent icon overlap.
- Save and close the editor.
Nutrient handles text annotation dictionary structures, popup window configurations, sticky note icon rendering, and appearance state management so you don’t need to understand PDF text annotation specifications or manage annotation popup positioning manually. The sticky note annotation system provides compact icon-based comment markers for document review workflows, collaborative feedback systems, quality assurance processes, and technical review platforms where detailed comments need to be attached to specific page locations without obscuring document content.