com.aspose.pdf.facades

Class PdfAnnotationEditor

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IFacade, ISaveableFacade


    public final class PdfAnnotationEditor
    extends SaveableFacade

    Represents a class for work with PDF document annotations (comments).

    • Constructor Detail

      • PdfAnnotationEditor

        public PdfAnnotationEditor()

        Initializes new PdfAnnotationEditor object.

      • PdfAnnotationEditor

        public PdfAnnotationEditor(IDocument document)

        Initializes new PdfAnnotationEditor object on base of the document.

        Parameters:
        document - Pdf document.
    • Method Detail

      • importAnnotationFromXfdf

        public void importAnnotationFromXfdf(String xfdfFile)

        Imports all annotations from XFDF file.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.importAnnotationFromXfdf("annots.xfdf");
         editor.save("example_out.pdf");
         
        Parameters:
        xfdfFile - The input XFDF file.
      • importAnnotationFromXfdf

        public void importAnnotationFromXfdf(String xfdfFile,
                                    int[] annotType)

        Imports the specified annotations from XFDF file.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         int[] annotTypes = {AnnotationType.Highlight, AnnotationType.Text};
         editor.importAnnotationFromXfdf("annots.xfdf", annotTypes);
         editor.save("example_out.pdf");
         
        Parameters:
        xfdfFile - The input XFDF file.
        annotType - The annotations array to be imported.
      • importAnnotationFromXfdf

        public void importAnnotationFromXfdf(InputStream xfdfStream,
                                    int[] annotType)

        Imports the specified annotations from XFDF data stream.


         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         int[] annotTypes ={ AnnotationType.Highlight, AnnotationType.Line };
         editor.importAnnotationFromXfdf(new FileInputStream("annots.xfdf"), annotTypes);
         editor.save("example_out.pdf");
         
        Parameters:
        xfdfStream - The input XFDF data stream.
        annotType - The array of annotation types to be imported.
      • importAnnotationFromXfdf

        public void importAnnotationFromXfdf(InputStream xfdfSteam)

        Imports all annotations from XFDF data stream.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.importAnnotationFromXfdf(new FileInputStream("annots.xfdf"));
         editor.save("example_out.pdf");
         
        Parameters:
        xfdfSteam - The input XFDF data stream.
      • importAnnotations

        public void importAnnotations(String[] annotFile,
                             int[] annotType)

        Imports the specified annotations into document from array of another PDF documents.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         string[] paths = new string[2] {"with_annots1.pdf", "with_annots2.pdf"};
         int[] annotTypes = {AnnotationType.Highlight, AnnotationType.Text};
         editor.importAnnotations(paths, annotTypes);
         editor.save("example_out.pdf");
         
        Parameters:
        annotFile - The array of paths of PDF documents that contain source annotations.
        annotType - The array of annotation types to be imported.
      • importAnnotations

        public void importAnnotations(String[] annotFile)

        Imports annotations into document from array of another PDF documents.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         string[] paths = new string[2] {"with_annots1.pdf", "with_annots2.pdf"};
         editor.importAnnotations(paths);
         editor.save("example_out.pdf");
         
        Parameters:
        annotFile - The array of paths of PDF documents that contain source annotations.
      • importAnnotations

        public void importAnnotations(InputStream[] annotFileInputStream,
                             int[] annotType)

        Imports the specified annotations into document from array of another PDF document streams.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         InputStream[] streams = new FileInputStream[2];
         streams[0]= new FileInputStream("with_annots1.pdf");
         streams[1]= new FileInputStream("with_annots2.pdf");
         int[] annotTypes = {AnnotationType.Highlight, AnnotationType.Text};
         editor.importAnnotations(streams, annotTypes);
         editor.save("example_out.pdf");
         streams[0].close();
         streams[1].close();
         
        Parameters:
        annotFileInputStream - The array of streams of PDF documents that contain source annotations.
        annotType - The annotation types to be imported.
      • importAnnotations

        public void importAnnotations(InputStream[] annotFileInputStream)

        Imports annotations into document from array of another PDF document streams.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         InputStream[] streams = new FileInputStream[2];
         streams[0]= new FileInputStream("with_annots1.pdf");
         streams[1]= new FileInputStream("with_annots2.pdf");
         editor.importAnnotations(streams);
         editor.save("example_out.pdf");
         streams[0].Close();
         streams[1].Close();
         
        Parameters:
        annotFileInputStream - The array of streams of PDF documents that contain source annotations.
      • modifyAnnotations

        @Deprecated
        public void modifyAnnotations(int start,
                                        int end,
                                        int annotType,
                                        Annotation annotation)
        Deprecated. 
        "Use modifyAnnotations(int start, int end, Annotation annotation) instead."

        Modifies the annotations of the specifed type on the specified page range. It supports to modify next annotation properties: Modified, Title, Contents, Color, Subject and Open.


         
         
                      PdfAnnotationEditor editor = new PdfAnnotationEditor();
                      editor.bindPdf("example.pdf");
                      com.aspose.pdf.TextAnnotation annot = new com.aspose.pdf.TextAnnotation();
                      annot.setModified ( new java.util.Date());
                      annot.setTitle ( "NEW AUTHOR");
                      annot.setContents ( "NEW CONTENTS");
                      annot.setColor (com.aspose.pdf.Color.getRed());
                      annot.setSubject ( "NEW SUBJECT");
                      annot.setOpen ( true);
                      editor.modifyAnnotations(1, 2, com.aspose.pdf.AnnotationType.Text, annot);
                      editor.save("example_out.pdf");
         
        Parameters:
        start - The start page number.
        end - The end page number.
        annotType - The annotation type.
        annotation - The annotation object contains new properties.
      • modifyAnnotationsAuthor

        public void modifyAnnotationsAuthor(int start,
                                   int end,
                                   String srcAuthor,
                                   String desAuthor)

        Modifies the author of annotations on the specified page range.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.modifyAnnotationsAuthor(1, 2, "PREV AUTHOR", "NEW AUTHOR");
         editor.save("example_out.pdf");
         
        Parameters:
        start - The start page number.
        end - The end page number.
        srcAuthor - The author that must be modified.
        desAuthor - The new author.
      • flatteningAnnotations

        public void flatteningAnnotations()

        Flattens all annotations in the document.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.flatteningAnnotations();
         editor.save(example_out.pdf");
         
      • flatteningAnnotations

        public void flatteningAnnotations(int start,
                                 int end,
                                 int[] annotType)

        Flattens the annotations of the specified types.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         int[] annotTypes ={AnnotationType.Line, AnnotationType.FreeText};
         editor.flatteningAnnotations(1, 2, annotTypes);
         editor.save("example_out.pdf");
         
        Parameters:
        start - The start page.
        end - Then end page.
        annotType - The annotation types should be flattened.
      • deleteAnnotations

        public void deleteAnnotations()

        Deletes all annotations in the document.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.deleteAnnotations();
         editor.save("example_out.pdf");
         
      • deleteAnnotations

        public void deleteAnnotations(String annotType)

        Deletes all annotations of the specified type in the document.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.deleteAnnotations("Text");
         editor.save("example_out.pdf");
         
        Parameters:
        annotType - The type of annotation will be deleted.
      • deleteAnnotation

        public void deleteAnnotation(String annotName)

        Deletes the annotation with specified annotation name.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         editor.deleteAnnotation("4cfa69cd-9bff-49e0-9005-e22a77cebf38");
         editor.save("example_out.pdf");
         
        Parameters:
        annotName - The annotation name
      • exportAnnotationsXfdf

        public void exportAnnotationsXfdf(OutputStream xmlOutputStream,
                                 int start,
                                 int end,
                                 String[] annotTypes)

        Exports the content of the specified annotation types into XFDF


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         String[] annotTypes = new String[] {"Text", "Highlight"};
         OutputStream stream = new FileOutputStream("example.xfdf");
         editor.exportAnnotationsXfdf(stream, 1, 2, annotTypes);
         stream.close();
         
        Parameters:
        xmlOutputStream - The output XFDF stream.
        start - Start page from which the annotations of the document will be exported.
        end - End page to which the annotations of the document will be exported.
        annotTypes - The array of annotation types need be exported.
      • exportAnnotationsXfdf

        public void exportAnnotationsXfdf(OutputStream xmlOutputStream,
                                 int start,
                                 int end,
                                 int[] annotTypes)

        Exports the content of the specified annotation types into XFDF


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         int[] annotTypes = new int[] {AnnotationType.Text, AnnotationType.Highlight};
         OutputStream stream = new FileOutputStream("example.xfdf");
             editor.exportAnnotationsXfdf(stream, 1, 2, annotTypes);
         stream.close();
         
        Parameters:
        xmlOutputStream - The output XFDF stream.
        start - Start page from which the annotations of the document will be exported.
        end - End page to which the annotations of the document will be exported.
        annotTypes - The array of annotation types need be exported.
      • extractAnnotations

        public Iterable extractAnnotations(int start,
                                  int end,
                                  String[] annotTypes)

        Gets the list of annotations of the specified types.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         String[] annotTypes = new String[] {"Text", "Highlight"};
         List annotList = (List)editor.extractAnnotations(1, 2 , annotTypes);
         
        Parameters:
        start - Start page from which the annotations will be selected.
        end - End page to which the annotations will be selected.
        annotTypes - The array of needed annotation types.
        Returns:
        Annotations list.
      • extractAnnotations

        public List<Annotation> extractAnnotations(int start,
                                          int end,
                                          int[] annotTypes)

        Gets the list of annotations of the specified types.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         int[] annotTypes = new int[] {AnnotationType.Text, AnnotationType.Highlight};
         List annotList = (List)editor.extractAnnotations(1, 2 , annotTypes);
         
        Parameters:
        start - Start page from which the annotations will be selected.
        end - End page to which the annotations will be selected.
        annotTypes - The array of needed annotation types.
        Returns:
        Annotations list.
      • modifyAnnotations

        public void modifyAnnotations(int start,
                             int end,
                             Annotation annotation)

        Modifies the annotations of the specifed type on the specified page range. It supports to modify next annotation properties: Modified, Title, Contents, Color, Subject and Open.


         
         
         PdfAnnotationEditor editor = new PdfAnnotationEditor();
         editor.bindPdf("example.pdf");
         TextAnnotation annot = new TextAnnotation();
         annot.setModified ( new Date());
         annot.setTitle ( "NEW AUTHOR");
         annot.setContents ( "NEW CONTENTS");
         annot.setColor ( Color.RED);
         annot.setSubject ( "NEW SUBJECT");
         annot.setOpen ( true);
         editor.modifyAnnotations(1, 2, annot);
         editor.save("example_out.pdf");
         
        Parameters:
        start - The start page number.
        end - The end page number.
        annotation - The annotation object contains new properties.
      • redactArea

        public void redactArea(int pageIndex,
                      Rectangle rect,
                      Color color)

        Redacts area on the specified page. All contents is removed.

        Parameters:
        pageIndex - Index of the page.
        rect - Area rectangle.
        color - Filling color.