PdfAnnotationEditor

Inheritance: java.lang.Object, com.aspose.pdf.facades.IVentureLicenseTarget, com.aspose.pdf.facades.Facade, com.aspose.pdf.facades.SaveableFacade

public final class PdfAnnotationEditor extends SaveableFacade

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

Constructors

ConstructorDescription
PdfAnnotationEditor()Initializes new PdfAnnotationEditor object.
PdfAnnotationEditor(IDocument document)Initializes new PdfAnnotationEditor object on base of the document .

Methods

MethodDescription
importAnnotationsFromXfdf(String xfdfFile)Imports all annotations from XFDF file.
importAnnotationFromXfdf(String xfdfFile)Imports all annotations from XFDF file.
importAnnotationsFromXfdf(String xfdfFile, AnnotationType[] annotType)Imports the specified annotations from XFDF file.
importAnnotationsFromXfdf(InputStream xfdfStream, AnnotationType[] annotType)Imports the specified annotations from XFDF data stream.
importAnnotationsFromXfdf(InputStream xfdfSteam)Imports all annotations from XFDF data stream.
importAnnotationFromXfdf(InputStream xfdfStream)Imports all annotations from XFDF data stream.
importAnnotations(String[] annotFile, AnnotationType[] annotType)Imports the specified annotations into document from array of another PDF documents.
importAnnotations(String[] annotFile)Imports annotations into document from array of another PDF documents.
importAnnotations(InputStream[] annotFileInputStream, AnnotationType[] annotType)Imports the specified annotations into document from array of another PDF document streams.
importAnnotations(InputStream[] annotFileInputStream)Imports annotations into document from array of another PDF document streams.
modifyAnnotations(int start, int end, int annotType, Annotation annotation)“Use modifyAnnotations(int start, int end, Annotation annotation) instead.”
modifyAnnotationsAuthor(int start, int end, String srcAuthor, String desAuthor)Modifies the author of annotations on the specified page range.
flatteningAnnotations()Flattens all annotations in the document.
flatteningAnnotations(Form.FlattenSettings flattenSettings)Flattens all annotations in the document.
flatteningAnnotations(int start, int end, AnnotationType[] annotType)Flattens the annotations of the specified types.
deleteAnnotations()Deletes all annotations in the document.
deleteAnnotations(String annotType)Deletes all annotations of the specified type in the document.
deleteAnnotation(String annotName)Deletes the annotation with specified annotation name.
exportAnnotationsXfdf(OutputStream xmlOutputStream, int start, int end, String[] annotTypes)Exports the content of the specified annotations types into XFDF
exportAnnotationsToXfdf(OutputStream xmlOutputStream)Exports annotations to stream.
exportAnnotationsXfdf(OutputStream xmlOutputStream, int start, int end, AnnotationType[] annotTypes)Exports the content of the specified annotation types into XFDF
extractAnnotations(int start, int end, String[] annotTypes)Gets the list of annotations of the specified types.
extractAnnotations(int start, int end, AnnotationType[] annotTypes)Gets the list of annotations of the specified types.
save(String outputFile)Saves the result PDF to file.
save(OutputStream outputStream)Saves the result PDF to stream.
modifyAnnotations(int start, int end, Annotation annotation)Modifies the annotations of the specifed type on the specified page range.
redactArea(int pageIndex, Rectangle rect, Color color)Redacts area on the specified page.
redactExactArea(int pageIndex, Rectangle rect, Color color)Redacts area on the specified page.

PdfAnnotationEditor()

public PdfAnnotationEditor()

Initializes new PdfAnnotationEditor object.

PdfAnnotationEditor(IDocument document)

public PdfAnnotationEditor(IDocument document)

Initializes new PdfAnnotationEditor object on base of the document .

Parameters:

ParameterTypeDescription
documentIDocumentPdf document.

importAnnotationsFromXfdf(String xfdfFile)

public void importAnnotationsFromXfdf(String xfdfFile)

Imports all annotations from XFDF file.


PdfAnnotationEditor editor = new PdfAnnotationEditor();
 editor.bindPdf("example.pdf");
 editor.importAnnotationsFromXfdf("annots.xfdf");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
xfdfFilejava.lang.StringThe input XFDF file.

importAnnotationFromXfdf(String xfdfFile)

public final 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:

ParameterTypeDescription
xfdfFilejava.lang.StringThe input XFDF file.

importAnnotationsFromXfdf(String xfdfFile, AnnotationType[] annotType)

public void importAnnotationsFromXfdf(String xfdfFile, AnnotationType[] 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:

ParameterTypeDescription
xfdfFilejava.lang.StringThe input XFDF file.
annotTypeAnnotationType[]The annotations array to be imported.

importAnnotationsFromXfdf(InputStream xfdfStream, AnnotationType[] annotType)

public void importAnnotationsFromXfdf(InputStream xfdfStream, AnnotationType[] 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:

ParameterTypeDescription
xfdfStreamjava.io.InputStreamThe input XFDF data stream.
annotTypeAnnotationType[]The array of annotation types to be imported.

importAnnotationsFromXfdf(InputStream xfdfSteam)

public void importAnnotationsFromXfdf(InputStream xfdfSteam)

Imports all annotations from XFDF data stream.


PdfAnnotationEditor editor = new PdfAnnotationEditor();
 editor.bindPdf("example.pdf");
 editor.importAnnotationsFromXfdf(new FileInputStream("annots.xfdf"));
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
xfdfSteamjava.io.InputStreamThe input XFDF data stream.

importAnnotationFromXfdf(InputStream xfdfStream)

public final void importAnnotationFromXfdf(InputStream xfdfStream)

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:

ParameterTypeDescription
xfdfStreamjava.io.InputStreamThe input XFDF data stream.

importAnnotations(String[] annotFile, AnnotationType[] annotType)

public void importAnnotations(String[] annotFile, AnnotationType[] 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:

ParameterTypeDescription
annotFilejava.lang.String[]The array of paths of PDF documents that contain source annotations.
annotTypeAnnotationType[]The array of annotation types to be imported.

importAnnotations(String[] annotFile)

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:

ParameterTypeDescription
annotFilejava.lang.String[]The array of paths of PDF documents that contain source annotations.

importAnnotations(InputStream[] annotFileInputStream, AnnotationType[] annotType)

public void importAnnotations(InputStream[] annotFileInputStream, AnnotationType[] 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:

ParameterTypeDescription
annotFileInputStreamjava.io.InputStream[]The array of streams of PDF documents that contain source annotations.
annotTypeAnnotationType[]The annotation types to be imported.

importAnnotations(InputStream[] annotFileInputStream)

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:

ParameterTypeDescription
annotFileInputStreamjava.io.InputStream[]The array of streams of PDF documents that contain source annotations.

modifyAnnotations(int start, int end, int annotType, Annotation annotation)

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

“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:

ParameterTypeDescription
startintThe start page number.
endintThe end page number.
annotTypeintThe annotation type.
annotationAnnotationThe annotation object contains new properties.

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

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:

ParameterTypeDescription
startintThe start page number.
endintThe end page number.
srcAuthorjava.lang.StringThe author that must be modified.
desAuthorjava.lang.StringThe 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(Form.FlattenSettings flattenSettings)

public final void flatteningAnnotations(Form.FlattenSettings flattenSettings)

Flattens all annotations in the document.

Parameters:

ParameterTypeDescription
flattenSettingsFlattenSettingsSpecifies modes of flattening.

flatteningAnnotations(int start, int end, AnnotationType[] annotType)

public void flatteningAnnotations(int start, int end, AnnotationType[] 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:

ParameterTypeDescription
startintThe start page.
endintThen end page.
annotTypeAnnotationType[]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(String annotType)

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:

ParameterTypeDescription
annotTypejava.lang.StringThe type of annotation will be deleted.

deleteAnnotation(String annotName)

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:

ParameterTypeDescription
annotNamejava.lang.StringThe annotation name

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

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

Exports the content of the specified annotations 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:

ParameterTypeDescription
xmlOutputStreamjava.io.OutputStreamThe output XFDF stream.
startintStart page from which the annotations of the document will be exported.
endintEnd page to which the annotations of the document will be exported.
annotTypesjava.lang.String[]The array of annotation types need be exported.

exportAnnotationsToXfdf(OutputStream xmlOutputStream)

public final void exportAnnotationsToXfdf(OutputStream xmlOutputStream)

Exports annotations to stream.

Parameters:

ParameterTypeDescription
xmlOutputStreamjava.io.OutputStreamOutputStream instance (Output stream)

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

public void exportAnnotationsXfdf(OutputStream xmlOutputStream, int start, int end, AnnotationType[] 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:

ParameterTypeDescription
xmlOutputStreamjava.io.OutputStreamThe output XFDF stream.
startintStart page from which the annotations of the document will be exported.
endintEnd page to which the annotations of the document will be exported.
annotTypesAnnotationType[]The array of annotation types need be exported.

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

public List<Annotation> 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:

ParameterTypeDescription
startintStart page from which the annotations will be selected.
endintEnd page to which the annotations will be selected.
annotTypesjava.lang.String[]The array of needed annotation types.

Returns: java.util.List<com.aspose.pdf.Annotation> - Annotations list.

extractAnnotations(int start, int end, AnnotationType[] annotTypes)

public List<Annotation> extractAnnotations(int start, int end, AnnotationType[] 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:

ParameterTypeDescription
startintStart page from which the annotations will be selected.
endintEnd page to which the annotations will be selected.
annotTypesAnnotationType[]The array of needed annotation types.

Returns: java.util.List<com.aspose.pdf.Annotation> - Annotations list.

save(String outputFile)

public void save(String outputFile)

Saves the result PDF to file.

Parameters:

ParameterTypeDescription
outputFilejava.lang.StringOutput PDF file

save(OutputStream outputStream)

public void save(OutputStream outputStream)

Saves the result PDF to stream.

Parameters:

ParameterTypeDescription
outputStreamjava.io.OutputStreamOutput PDF stream

modifyAnnotations(int start, int end, Annotation annotation)

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:

ParameterTypeDescription
startintThe start page number.
endintThe end page number.
annotationAnnotationThe annotation object contains new properties.

redactArea(int pageIndex, Rectangle rect, Color color)

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

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

Parameters:

ParameterTypeDescription
pageIndexintIndex of the page.
rectRectangleArea rectangle.
colorjava.awt.ColorFilling color.

redactExactArea(int pageIndex, Rectangle rect, Color color)

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

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

Parameters:

ParameterTypeDescription
pageIndexintIndex of the page.
rectRectangleArea rectangle.
colorjava.awt.ColorFilling color.