Class AnnotationWriter


  • public class AnnotationWriter
    extends Object
    Class writes annotations to PDF file

    Example:

    
    
     File inputFile = new File("location of input pdf file");
     File outputFile = new File("location of output pdf file");
    
     //usage of text annotation
     TextAnnotation a1 = new TextAnnotation(0, 100, 100, 200, 150, "sticky note");
    
     //usage of freetext annotation
     FreeTextAnnotation a2 = new FreeTextAnnotation(0, 300, 150, 200, 200, "free text");
    
     //usage of line annotation
     LineAnnotation a3 = new LineAnnotation(0, 100, 200, 200, 250, 100, 200, 200, 250);
    
     //usage of link annotation
     LinkAnnotation a4 = new LinkAnnotation(0, 100, 250, 200, 300, "http://www.google.com");
    
     //usage of polygon annotation
     PolygonAnnotation a5 = new PolygonAnnotation(0, 100, 300, 200, 350, new float[]{120, 310, 170, 325, 110, 340});
     a5.setNonStrokeColor(Color.YELLOW);
    
     //usage of polyline annotation
     PolyLineAnnotation a6 = new PolyLineAnnotation(0, 100, 350, 200, 400, new float[]{120, 360, 170, 385, 110, 390});
     a6.setNonStrokeColor(Color.BLUE);
    
     //usage of square annotation
     SquareAnnotation a7 = new SquareAnnotation(0, 100, 400, 200, 450);
     a7.setNonStrokeColor(Color.PINK);
    
     //usage of circle annotation
     CircleAnnotation a8 = new CircleAnnotation(0, 100, 450, 200, 500);
     a8.setNonStrokeColor(Color.ORANGE);
    
     //usage of ink annotation
     float[] curve1 = {110, 510, 110, 540};
     float[] curve2 = {150, 510, 110, 525, 150, 540};
     ArrayList<float[]> linkList = new ArrayList<float[]>();
     linkList.add(curve1);
     linkList.add(curve2);
     InkAnnotation a9 = new InkAnnotation(0, 100, 500, 200, 550, linkList);
     a9.setStrokeColor(Color.BLUE);
    
     //usage of Highlight Annotation
     float[] quadPoints = new float[]{200, 200, 300, 200, 200, 100, 300, 100};
     HighlightAnnotation a10 = new HighlightAnnotation(0, 200, 100, 300, 200, quadPoints);
    
     //now writeout all annotation to file
     writeAnnotations(inputFile, outputFile, new WritableAnnotation[]{a1, a2, a3, a4, a5, a6, a7, a8, a9, a10});
    
     
    • Constructor Detail

      • AnnotationWriter

        public AnnotationWriter()
    • Method Detail

      • writeAnnotations

        public static void writeAnnotations​(File input,
                                            File output,
                                            WritableAnnotation[] annotArr)
                                     throws IOException
        Method writes annotations to file
        Parameters:
        input - pdf file
        output - pdf file
        annotArr - Array of writable annotations
        Throws:
        IOException - IOException