PdfContentEditor

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

public final class PdfContentEditor extends SaveableFacade

Represents a class to edit PDF file’s content.

Constructors

ConstructorDescription
PdfContentEditor()The constructor of the PdfContentEditor object.
PdfContentEditor(IDocument document)Initializes new PdfContentEditor object on base of the document .

Fields

FieldDescription
DOCUMENT_OPENA document event type.
DOCUMENT_CLOSEA document event type.
DOCUMENT_WILL_SAVEA document event type.
DOCUMENT_SAVEDA document event type.
DOCUMENT_WILL_PRINTA document event type.
DOCUMENT_PRINTEDA document event type.

Methods

MethodDescription
getTextSearchOptions()Gets text search options.
setTextSearchOptions(TextSearchOptions value)Sets text search options.
getTextEditOptions()Gets text edit options.
setTextEditOptions(TextEditOptions value)Sets text edit options.
getTextReplaceOptions()Gets text replace options.
setTextReplaceOptions(TextReplaceOptions value)Sets text replace options.
getReplaceTextStrategy()Get a set of parameters for replace text operation
setReplaceTextStrategy(ReplaceTextStrategy value)Set a set of parameters for replace text operation
bindPdf(String inputFile)Binds a PDF file for editing.
bindPdf(InputStream inputStream)Binds a PDF stream for editing.
extractLink()Extracts the collection of Link instances contained in PDF document.
createWebLink(Rectangle rect, String url, int originalPage, Color clr, int[] actionName)Creates a web link in PDF document.
createWebLink(Rectangle rect, String url, int originalPage, Color clr)Creates a web link in PDF document.
createWebLink(Rectangle rect, String url, int originalPage)Creates a web link in PDF document.
createLocalLink(Rectangle rect, int desPage, int originalPage, Color clr, int[] actionName)Creates a local link in PDF document.
createLocalLink(Rectangle rect, int desPage, int originalPage, Color clr)Creates a local link in PDF document.
createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage, Color clr, int[] actionName)Creates a link to another PDF document page.
createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage, Color clr)Creates a link to another PDF document page.
createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage)Creates a link to another PDF document page.
createCustomActionLink(Rectangle rect, int originalPage, Color color, int[] actionName)Creates a link to custom actions in PDF document.
createApplicationLink(Rectangle rect, String application, int page, Color clr, int[] actionName)Creates a link to launch an application in PDF document.
createApplicationLink(Rectangle rect, String application, int page, Color clr)Creates a link to launch an application in PDF document.
createApplicationLink(Rectangle rect, String application, int page)Creates a link to launch an application in PDF document.
createJavaScriptLink(String code, Rectangle rect, int originalPage, Color color)Creates a link to JavaScript in PDF document.
createText(Rectangle rect, String title, String contents, boolean open, String icon, int page)Creates text annotation in PDF document
createFreeText(Rectangle rect, String contents, int page)Creates free text annotation in PDF document
createMarkup(Rectangle rect, String contents, int type, int page, Color clr)Creates markup annotation it PDF document.
createPopup(Rectangle rect, String contents, boolean open, int page)Creates popup annotation in PDF document.
createFileAttachment(Rectangle rect, String contents, String filePath, int page, String name)Creates file attachment annotation.
createFileAttachment(Rectangle rect, String contents, InputStream attachmentStream, String attachmentName, int page, String name)Creates file attachment annotation.
addDocumentAttachment(String fileAttachmentPath, String description)Adds document attachment with no annotation.
addDocumentAttachment(InputStream fileAttachmentStream, String fileAttachmentName, String description)Adds document attachment with no annotation.
deleteAttachments()Deletes all attachments in PDF document.
createLine(Rectangle rect, String contents, float x1, float y1, float x2, float y2, int page, int border, Color clr, String borderStyle, int[] dashArray, String[] LEArray)Creates line annotation.
createSquareCircle(Rectangle rect, String contents, Color clr, boolean square, int page, int borderWidth)Creates square-circle annotation.
drawCurve(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)Creates curve annotation.
createPolygon(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)Creates polygon annotation.
createPolyLine(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)Creates polyline annotation.
createCaret(int page, Rectangle annotRect, Rectangle caretRect, String symbol, String annotContents, Color color)Creates caret annotation.
createRubberStamp(int page, Rectangle annotRect, String icon, String annotContents, Color color)Creates a rubber stamp annotation.
createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, String appearanceFile)Creates a rubber stamp annotation.
createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, InputStream appearanceStream)Creates a rubber stamp annotation.
createBookmarksAction(String title, Color color, boolean boldFlag, boolean italicFlag, String file, String actionType, String destination)Creates a bookmark with the specified action.
addDocumentAdditionalAction(String eventType, String code)Adds additional action for document event.
removeDocumentOpenAction()Removes open action from the document.
changeViewerPreference(int viewerAttribution)Changes the view preference.
getViewerPreference()Returns the view preference.
replaceImage(int pageNumber, int index, String imageFile)Replaces the specified image on the specified page of PDF document with another image.
deleteImage(int pageNumber, int[] index)Deletes the specified images on the specified page.
deleteImage()Deletes all images from PDF document.
replaceText(String srcString, int thePage, String destString, TextState textState)Replaces text in the PDF file on the specified page.
replaceText(String srcString, String destString)Replaces text in the PDF file.
replaceText(String srcString, int thePage, String destString)Replaces text in the PDF file on the specified page.
replaceText(String srcString, String destString, TextState textState)Replaces text in the PDF file using specified TextState object.
createMovie(Rectangle rect, String filePath, int page)
createSound(Rectangle rect, String filePath, String name, int page, String rate)
deleteStamp(int pageNumber, int[] index)Deletes multiple stamps on the specified page by stamp indexes.
deleteStampByIds(int[] stampIds)Deletes stamps with specified IDs from all pages of the document.
deleteStampByIds(int pageNumber, int[] stampIds)Deletes stamps on the specified page by multiple stamp IDs.
deleteStampById(int pageNumber, int stampId)Deletes stamp on the specified page by stamp ID.
hideStampById(int pageNumber, int stampId)Hides the stamp.
showStampById(int pageNumber, int stampId)Shows stamp which was hidden by HiddenStampById.
moveStampById(int pageNumber, int stampId, double x, double y)Changes position of the stamp on page.
moveStamp(int pageNumber, int stampIndex, double x, double y)Changes position of the stamp on page.
deleteStampById(int stampId)Delete stamp by ID from all pages of the document.
createLocalLink(Rectangle rect, int desPage, int originalPage)Creates a local link in PDF document.
replaceText(String srcString, String destString, int fontSize)Replaces text in the PDF file and sets font size.
getStamps(int pageNumber)Returns array of stamps on the page.
close()Closes opened document.

PdfContentEditor()

public PdfContentEditor()

The constructor of the PdfContentEditor object.

PdfContentEditor(IDocument document)

public PdfContentEditor(IDocument document)

Initializes new PdfContentEditor object on base of the document .

Parameters:

ParameterTypeDescription
documentIDocumentPdf document.

DOCUMENT_OPEN

public static final String DOCUMENT_OPEN

A document event type. Opens a document.

DOCUMENT_CLOSE

public static final String DOCUMENT_CLOSE

A document event type. Closes a document.

DOCUMENT_WILL_SAVE

public static final String DOCUMENT_WILL_SAVE

A document event type. Excute a action before saving.

DOCUMENT_SAVED

public static final String DOCUMENT_SAVED

A document event type. Excute a action after saving.

DOCUMENT_WILL_PRINT

public static final String DOCUMENT_WILL_PRINT

A document event type. Excute a action before printing.

DOCUMENT_PRINTED

public static final String DOCUMENT_PRINTED

A document event type. Excute a action after printing.

getTextSearchOptions()

public TextSearchOptions getTextSearchOptions()

Gets text search options.

Returns: TextSearchOptions - TextSearchOptions element

setTextSearchOptions(TextSearchOptions value)

public void setTextSearchOptions(TextSearchOptions value)

Sets text search options.

Parameters:

ParameterTypeDescription
valueTextSearchOptionsTextSearchOptions element

getTextEditOptions()

public TextEditOptions getTextEditOptions()

Gets text edit options.

Returns: TextEditOptions - TextEditOptions element

setTextEditOptions(TextEditOptions value)

public void setTextEditOptions(TextEditOptions value)

Sets text edit options.

Parameters:

ParameterTypeDescription
valueTextEditOptionssetTextEditOptions element

getTextReplaceOptions()

public TextReplaceOptions getTextReplaceOptions()

Gets text replace options.

Returns: TextReplaceOptions - TextReplaceOptions element

setTextReplaceOptions(TextReplaceOptions value)

public void setTextReplaceOptions(TextReplaceOptions value)

Sets text replace options.

Parameters:

ParameterTypeDescription
valueTextReplaceOptionsTextReplaceOptions element

getReplaceTextStrategy()

public ReplaceTextStrategy getReplaceTextStrategy()

Get a set of parameters for replace text operation

Returns: ReplaceTextStrategy - ReplaceTextStrategy element

setReplaceTextStrategy(ReplaceTextStrategy value)

public void setReplaceTextStrategy(ReplaceTextStrategy value)

Set a set of parameters for replace text operation

Parameters:

ParameterTypeDescription
valueReplaceTextStrategyReplaceTextStrategy element

bindPdf(String inputFile)

public void bindPdf(String inputFile)

Binds a PDF file for editing.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringA PDF file to be edited.

bindPdf(InputStream inputStream)

public void bindPdf(InputStream inputStream)

Binds a PDF stream for editing.

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStreamA PDF stream to be edited.
public List<Annotation> extractLink()

Extracts the collection of Link instances contained in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 List links = editor.extractLink();
 for (object obj : links)
 {
     Link link = (Link)obj;
     // work with Link instance
 }

Returns: java.util.List<com.aspose.pdf.Annotation> - The collection of Link objects

public void createWebLink(Rectangle rect, String url, int originalPage, Color clr, int[] actionName)

Creates a web link in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createWebLink(new Rectangle(0, 0, 100, 100),
     "http://www.aspose.com", 1, Color.red,
     new int[] { PredefinedAction.FirstPage, PredefinedAction.PrintDialog });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
urljava.lang.StringThe web link destination.
originalPageintThe number of original page on which rectangle bound with web link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
actionNameint[]The array of actions (members of PredefinedAction enum) corresponding to executing menu items in Acrobat viewer.
public void createWebLink(Rectangle rect, String url, int originalPage, Color clr)

Creates a web link in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createWebLink(new Rectangle(0, 0, 100, 100),
     "http://www.aspose.com", 1, Color.red });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
urljava.lang.StringThe web link destination.
originalPageintThe number of original page where rectangle bound with web link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
public void createWebLink(Rectangle rect, String url, int originalPage)

Creates a web link in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createWebLink(new Rectangle(0, 0, 100, 100), "http://www.aspose.com", 1 });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
urljava.lang.StringThe web link destination.
originalPageintThe number of original page where rectangle bound with web link will be created.
public void createLocalLink(Rectangle rect, int desPage, int originalPage, Color clr, int[] actionName)

Creates a local link in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createLocalLink(new Rectangle(0, 0, 100, 100),
     2, 1, Color.red,
     new int[] { PredefinedAction.FirstPage, PredefinedAction.PrintDialog });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
desPageintThe destination page.
originalPageintThe number of original page where rectangle bound with local link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
actionNameint[]The array of actions (members of PredefinedAction enum) corresponding to executing menu items in Acrobat viewer.
public void createLocalLink(Rectangle rect, int desPage, int originalPage, Color clr)

Creates a local link in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createLocalLink(new Rectangle(0, 0, 100, 100),
     2, 1, Color.red });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
desPageintThe destination page.
originalPageintThe number of original page where rectangle bound with local link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
public void createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage, Color clr, int[] actionName)

Creates a link to another PDF document page.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createPdfDocumentLink(new Rectangle(0, 0, 100, 100),
     "another_example.pdf", 1, 1, Color.red,
     new int[] { PredefinedAction.FirstPage, PredefinedAction.PrintDialog });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
remotePdfjava.lang.StringThe PDF document which page will be opened.
originalPageintThe number of original page where rectangle bound with link will be created.
destinationPageintThe destination page.
clrjava.awt.ColorThe color of rectangle for active click.
actionNameint[]The array of actions (members of PredefinedAction enum) corresponding to executing menu items in Acrobat viewer.
public void createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage, Color clr)

Creates a link to another PDF document page.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createPdfDocumentLink(new Rectangle(0, 0, 100, 100),
     "another_example.pdf", 1, 1, Color.red });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
remotePdfjava.lang.StringThe PDF document which page will be opened.
originalPageintThe number of original page where rectangle bound with link will be created.
destinationPageintThe destination page.
clrjava.awt.ColorThe color of rectangle for active click.
public void createPdfDocumentLink(Rectangle rect, String remotePdf, int originalPage, int destinationPage)

Creates a link to another PDF document page.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createPdfDocumentLink(new Rectangle(0, 0, 100, 100), "another_example.pdf", 1, 1 });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
remotePdfjava.lang.StringThe PDF document which page will be opened.
originalPageintThe number of original page where rectangle bound with link will be created.
destinationPageintThe destination page.
public void createCustomActionLink(Rectangle rect, int originalPage, Color color, int[] actionName)

Creates a link to custom actions in PDF document.

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
originalPageintThe number of original page where rectangle bound with link will be created.
colorjava.awt.ColorThe color of rectangle for active click.
actionNameint[]The array of actions (members of PredefinedAction enum) corresponding to executing menu items in Acrobat viewer.
public void createApplicationLink(Rectangle rect, String application, int page, Color clr, int[] actionName)

Creates a link to launch an application in PDF document.

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
applicationjava.lang.StringThe path of application to be launched.
pageintThe number of original page where rectangle bound with link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
actionNameint[]The array of actions (members of PredefinedAction enum) corresponding to executing menu items in Acrobat viewer.
public void createApplicationLink(Rectangle rect, String application, int page, Color clr)

Creates a link to launch an application in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createApplicationLink(new Rectangle(0, 0, 100, 100),
     "explorer", 1, Color.red });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
applicationjava.lang.StringThe path of application to be launched.
pageintThe number of original page where rectangle bound with link will be created.
clrjava.awt.ColorThe color of rectangle for active click.
public void createApplicationLink(Rectangle rect, String application, int page)

Creates a link to launch an application in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createApplicationLink(new Rectangle(0, 0, 100, 100), "explorer", 1 });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
applicationjava.lang.StringThe path of application to be launched.
pageintThe number of original page where rectangle bound with link will be created.
public void createJavaScriptLink(String code, Rectangle rect, int originalPage, Color color)

Creates a link to JavaScript in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createJavaScriptLink("app.alert('welcome to aspose!');",
     new Rectangle(0, 0, 100, 100), 1, Color.red });
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
codejava.lang.StringThe JavaScript code.
rectjava.awt.RectangleThe rectangle for active click.
originalPageintThe number of original page where rectangle bound with link will be created.
colorjava.awt.ColorThe color of rectangle for active click.

createText(Rectangle rect, String title, String contents, boolean open, String icon, int page)

public void createText(Rectangle rect, String title, String contents, boolean open, String icon, int page)

Creates text annotation in PDF document


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createText(new Rectangle(0, 0, 100, 100),
     "Welcome to Aspose", "You are welcome to Aspose!", true, "Key", 1);
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
titlejava.lang.StringThe title of the annotation.
contentsjava.lang.StringThe contents of the annotation.
openbooleanA flag specifying whether the annotation should initially be displayed open.
iconjava.lang.StringThe name of an icon will be used in displaying the annotation. This value can be: “Comment”, “Key”, “Note”, “Help”, “NewParagraph”, “Paragraph”, “Insert”
pageintThe number of original page where the text annotation will be created.

createFreeText(Rectangle rect, String contents, int page)

public void createFreeText(Rectangle rect, String contents, int page)

Creates free text annotation in PDF document


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createFreeText(new Rectangle(0, 0, 100, 100), "Welcome to Aspose", 1);
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
pageintThe number of original page where the text annotation will be created.

createMarkup(Rectangle rect, String contents, int type, int page, Color clr)

public void createMarkup(Rectangle rect, String contents, int type, int page, Color clr)

Creates markup annotation it PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createMarkup(new Rectangle(0, 0, 100, 100),
     "Welcome to Aspose", 0, 1, Color.red);
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
typeintThe type of markup annotation. Can be 0 (Highlight), 1 (Underline), 2 (StrikeOut), 3 (Squiggly).
pageintThe number of original page where the annotation will be created.
clrjava.awt.ColorThe color of markup.

createPopup(Rectangle rect, String contents, boolean open, int page)

public void createPopup(Rectangle rect, String contents, boolean open, int page)

Creates popup annotation in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createPopup(new Rectangle(0, 0, 100, 100), "Welcome to Aspose", true, 1);
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
openbooleanA flag specifying whether the pop-up annotation should initially be displayed open.
pageintThe number of original page where the annotation will be created.

createFileAttachment(Rectangle rect, String contents, String filePath, int page, String name)

public void createFileAttachment(Rectangle rect, String contents, String filePath, int page, String name)

Creates file attachment annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createFileAttachment(new Rectangle(0, 0, 100, 100),
     "Welcome to Aspose", "attachment_file.pdf", 1, "Graph");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
filePathjava.lang.StringThe path of the file will be attached.
pageintThe number of original page where the annotation will be created.
namejava.lang.StringThe name of an icon will be used in displaying the annotation. This value can be: “Graph”, “PushPin”, “Paperclip”, “Tag”.

createFileAttachment(Rectangle rect, String contents, InputStream attachmentStream, String attachmentName, int page, String name)

public void createFileAttachment(Rectangle rect, String contents, InputStream attachmentStream, String attachmentName, int page, String name)

Creates file attachment annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 java.io.InputStream attStream = new java.io.FileInputStream("attachment_file.pdf");

     editor.createFileAttachment(new Rectangle(0, 0, 100, 100),
         "Welcome to Aspose", attStream, "attachment_file.pdf", 1, "Graph");
     editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
attachmentStreamjava.io.InputStreamThe attachment file stream.
attachmentNamejava.lang.StringThe attachment name.
pageintThe number of original page where the annotation will be created.
namejava.lang.StringThe name of an icon will be used in displaying the annotation. This value can be: “Graph”, “PushPin”, “Paperclip”, “Tag”.

addDocumentAttachment(String fileAttachmentPath, String description)

public void addDocumentAttachment(String fileAttachmentPath, String description)

Adds document attachment with no annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.addDocumentAttachment("attachment_file.pdf", "description of attachment_file");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
fileAttachmentPathjava.lang.StringThe path of the file will be attached.
descriptionjava.lang.StringThe description information.

addDocumentAttachment(InputStream fileAttachmentStream, String fileAttachmentName, String description)

public void addDocumentAttachment(InputStream fileAttachmentStream, String fileAttachmentName, String description)

Adds document attachment with no annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 InputStream attStream = new FileInputStream("attachment_file.pdf")
     editor.addDocumentAttachment(attStream, "attachment_file.pdf", "description of attachment_file");
     editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
fileAttachmentStreamjava.io.InputStreamThe stream of the file will be attached.
fileAttachmentNamejava.lang.StringThe attachment name.
descriptionjava.lang.StringThe description information.

deleteAttachments()

public void deleteAttachments()

Deletes all attachments in PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.deleteAttachments();
 editor.save("example_out.pdf");

createLine(Rectangle rect, String contents, float x1, float y1, float x2, float y2, int page, int border, Color clr, String borderStyle, int[] dashArray, String[] LEArray)

public void createLine(Rectangle rect, String contents, float x1, float y1, float x2, float y2, int page, int border, Color clr, String borderStyle, int[] dashArray, String[] LEArray)

Creates line annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createLine(new Rectangle(0, 0, 100, 100), "Welcome to Aspose", 0, 0, 100, 100,
     1, 1, Color.red, "D", new int[] {2, 3}, new string[] {"OpenArrow", "ClosedArrow"});
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
x1floatThe starting horizontal coordinate of the line.
y1floatThe starting vertical coordinate of the line.
x2floatThe ending horizontal coordinate of the line.
y2floatThe ending vertical coordinate of the line.
pageintThe number of original page where the annotation will be created.
borderintThe border width in points. If this value is 0 no border is drawn. Default value is 1.
clrjava.awt.ColorThe color of line.
borderStylejava.lang.StringThe border style specifying the width and dash pattern to be used in drawing the line. This value can be: “S” (Solid), “D” (Dashed), “B” (Beveled), “I” (Inset), “U” (Underline).
dashArrayint[]A dash array defining a pattern of dashes and gaps to be used in drawing a dashed border. If it is used, borderSyle must be accordingly set to “D”.
LEArrayjava.lang.String[]An array of two values respectively specifying the beginning and ending style of the drawing line. The values can be: “Square”, “Circle”, “Diamond”, “OpenArrow”, “ClosedArrow”, “None”, “Butt”, “ROpenArrow”, “RClosedArrow”, “Slash”.

createSquareCircle(Rectangle rect, String contents, Color clr, boolean square, int page, int borderWidth)

public void createSquareCircle(Rectangle rect, String contents, Color clr, boolean square, int page, int borderWidth)

Creates square-circle annotation.


PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example.pdf");
 	editor.createSquareCircle(new Rectangle(0, 0, 100, 100),
 	    "Welcome to Aspose", Color.red, false, 1, 5);
  editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
contentsjava.lang.StringThe contents of the annotation.
clrjava.awt.ColorThe color of square or circle.
squarebooleanTrue (square), false (sircle).
pageintThe number of original page where the annotation will be created.
borderWidthintThe border width of square or circle.

drawCurve(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

public void drawCurve(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

Creates curve annotation.

PdfContentEditor editor = new PdfContentEditor();
 newApiEditor.bindPdf("example.pdf");
 LineInfo lineInfo = new LineInfo();
 lineInfo.setVerticeCoordinate ( new float[] { 0, 0, 100, 100 });  //x1, y1, x2, y2, .. xn, yn
 lineInfo.setVisibility ( true);
 editor.drawCurve(lineInfo, 1, new Rectangle(0, 0, 0, 0), "Welcome to Aspose");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
lineInfoLineInfoThe instance of LineInfo class.
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
annotContentsjava.lang.StringThe contents of the annotation.

createPolygon(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

public void createPolygon(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

Creates polygon annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 LineInfo lineInfo = new LineInfo();
 lineInfo.setVerticeCoordinate ( new float[] { 0, 0, 100, 100, 100, 50 });
 lineInfo.setVisibility ( true);
 editor.createPolygon(lineInfo, 1 , new Rectangle(0, 0, 0, 0), "Welcome to Aspose");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
lineInfoLineInfoThe instance of LineInfo class.
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
annotContentsjava.lang.StringThe contents of the annotation.

createPolyLine(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

public void createPolyLine(LineInfo lineInfo, int page, Rectangle annotRect, String annotContents)

Creates polyline annotation.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 LineInfo lineInfo = new LineInfo();
 lineInfo.setVerticeCoordinate ( new float[] { 0, 0, 100, 100, 100, 50 });
 lineInfo.setVisibility ( true);
 editor.createPolyLine(lineInfo, 1 , new Rectangle(0, 0, 0, 0), "Welcome to Aspose");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
lineInfoLineInfoThe instance of LineInfo class.
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
annotContentsjava.lang.StringThe contents of the annotation.

createCaret(int page, Rectangle annotRect, Rectangle caretRect, String symbol, String annotContents, Color color)

public void createCaret(int page, Rectangle annotRect, Rectangle caretRect, String symbol, String annotContents, Color color)

Creates caret annotation.


PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example.pdf");
 	editor.createCaret(1,
 	    new Rectangle(50, 50, 100, 100),
 	    new Rectangle(60, 60, 70, 70),
 	    "None", "Welcome to Aspose", Color.red);
  editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
caretRectjava.awt.RectangleThe actual boundaries of the underlying caret.
symboljava.lang.StringA symbol will be associated with the caret. Value can be: “P” (Paragraph), “None”.
annotContentsjava.lang.StringThe contents of the annotation.
colorjava.awt.ColorThe color of the annotation.

createRubberStamp(int page, Rectangle annotRect, String icon, String annotContents, Color color)

public void createRubberStamp(int page, Rectangle annotRect, String icon, String annotContents, Color color)

Creates a rubber stamp annotation.


PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example.pdf");
 	editor.createRubberStamp(1, Rectangle(0, 0, 100, 100),
 	    "Welcome to Aspose", Color.red);
  editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
iconjava.lang.Stringicon An icon is to be used in displaying the annotation. Default value: ‘Draft’.
annotContentsjava.lang.StringThe contents of the annotation.
colorjava.awt.ColorThe color of the annotation.

createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, String appearanceFile)

public void createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, String appearanceFile)

Creates a rubber stamp annotation.


PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example.pdf");
 	editor.createRubberStamp(1, Rectangle(0, 0, 100, 100),
 	    "Welcome to Aspose", Color.red, "appearance_file.pdf");
  editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
annotContentsjava.lang.StringThe contents of the annotation.
colorjava.awt.ColorThe color of the annotation.
appearanceFilejava.lang.StringThe path of appearance file.

createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, InputStream appearanceStream)

public void createRubberStamp(int page, Rectangle annotRect, String annotContents, Color color, InputStream appearanceStream)

Creates a rubber stamp annotation.


PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example.pdf");
  InputStream appStream = new FileInputStream("appearance_file.pdf");
 	    editor.createRubberStamp(1, Rectangle(0, 0, 100, 100),
 	        "Welcome to Aspose", Color.red, appStream);
      editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageintThe number of original page where the annotation will be created.
annotRectjava.awt.RectangleThe annotation rectangle defining the location of the annotation on the page.
annotContentsjava.lang.StringThe contents of the annotation.
colorjava.awt.ColorThe color of the annotation.
appearanceStreamjava.io.InputStreamThe stream of appearance file.

createBookmarksAction(String title, Color color, boolean boldFlag, boolean italicFlag, String file, String actionType, String destination)

public void createBookmarksAction(String title, Color color, boolean boldFlag, boolean italicFlag, String file, String actionType, String destination)

Creates a bookmark with the specified action.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.createBookmarksAction("bookmark title",
     Color.red, true, true, null, "GoTo", 1(page number));
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
titlejava.lang.StringThe title of the bookmark.
colorjava.awt.ColorThe color of the bookmark’s title.
boldFlagbooleanThe flag of bold attribution.
italicFlagbooleanThe flag of italic attribution.
filejava.lang.StringAnother file or application required when the action type is “GoToR” or “Launch”.
actionTypejava.lang.StringThe action type. The value can be: “GoToR”, “Launch”, “GoTo”, “URI”.
destinationjava.lang.StringThe local destination or remote destination or URL.

addDocumentAdditionalAction(String eventType, String code)

public void addDocumentAdditionalAction(String eventType, String code)

Adds additional action for document event.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.addDocumentAdditionalAction(PdfContentEditor.DocumentClose, "app.alert('Good-bye!');");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
eventTypejava.lang.StringThe document event types.
codejava.lang.StringThe code of JavaScript.

removeDocumentOpenAction()

public void removeDocumentOpenAction()

Removes open action from the document. This operation is useful when concatenating multiple documents that use explicit ‘GoTo’ action on startup.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.removeDocumentOpenAction();
 editor.save("example_out.pdf");

changeViewerPreference(int viewerAttribution)

public void changeViewerPreference(int viewerAttribution)

Changes the view preference.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.changeViewerPreference(ViewerPreference.HideMenubar);
 editor.changeViewerPreference(ViewerPreference.PageModeUseNone);
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
viewerAttributionintThe view attribution defined in the ViewerPreference class.

getViewerPreference()

public int getViewerPreference()

Returns the view preference.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 int prefValue = editor.GetViewerPreference();
 if ((prefValue & ViewerPreference.PageModeUseOutline) != 0)
 { // ... }

Returns: int - Returns set of ViewerPrefernece flags

replaceImage(int pageNumber, int index, String imageFile)

public void replaceImage(int pageNumber, int index, String imageFile)

Replaces the specified image on the specified page of PDF document with another image.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.replaceImage(1, 1, "image.jpg");
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageNumberintThe number of page on which the image is replaced.
indexintThe index of the image object must be replaced.
imageFilejava.lang.StringThe image file will be used for replacing.

deleteImage(int pageNumber, int[] index)

public void deleteImage(int pageNumber, int[] index)

Deletes the specified images on the specified page.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.deleteImage(1, new int[] {1, 2});
 editor.save("example_out.pdf");

Parameters:

ParameterTypeDescription
pageNumberintThe number of page on which images must be deleted.
indexint[]An array repsents images’ indexes.

deleteImage()

public void deleteImage()

Deletes all images from PDF document.


PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("example.pdf");
 editor.deleteImage();
 editor.save("example_out.pdf");

replaceText(String srcString, int thePage, String destString, TextState textState)

public boolean replaceText(String srcString, int thePage, String destString, TextState textState)

Replaces text in the PDF file on the specified page. TextState object (font family, color) can be specified to replaced text.


The example demonstrates how to replace text on the first page of the PDF document and set ```
TextState

text properties for the new text.

// open document Document doc = new Document(inFile); com.aspose.pdf.Font font = com.aspose.pdf.FontRepository.findFont(“Courier New”); font.isEmbedded ( true); // create PdfContentEditor object to edit text PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf(doc); // create textState object com.aspose.pdf.TextState textState = new com.aspose.pdf.TextState(); textState.setFont ( font); textState.setFontSize ( 17); textState.setFontStyle ( com.aspose.pdf.FontStyles.Bold | com.aspose.pdf.FontStyles.Italic); textState.setForegroundColor ( com.aspose.pdf.Color.getRed()); // change text with specified font editor.replaceText(“hello world”, 1, “hi world”, textState); // save document doc.save(outFile);


**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| srcString | java.lang.String | The string to be replaced. |
| thePage | int | Page number (0 means "all pages"). |
| destString | java.lang.String | The replaced string. |
| textState | [TextState](../../com.aspose.pdf/textstate) | Text state (Text Color, Font etc). |

**Returns:**
boolean - Returns true if replacement was made.
### replaceText(String srcString, String destString) {#replaceText-java.lang.String-java.lang.String-}

public boolean replaceText(String srcString, String destString)



Replaces text in the PDF file.

--------------------

The example demonstrates how to replace text in PDF document.

// open document Document doc = new Document(inFile); // create PdfContentEditor object to edit text PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf(doc); // change text editor.replaceText(“hello world”, “hi world”); // save document doc.save(outFile);


**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| srcString | java.lang.String | The string to be replaced. |
| destString | java.lang.String | Replacing string. |

**Returns:**
boolean - Returns true if replacement was made.
### replaceText(String srcString, int thePage, String destString) {#replaceText-java.lang.String-int-java.lang.String-}

public boolean replaceText(String srcString, int thePage, String destString)



Replaces text in the PDF file on the specified page.

--------------------

The example demonstrates how to replace text in PDF document on the specified page.

// open document Document doc = new Document(inFile); // create PdfContentEditor object to edit text PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf(doc); // change text editor.replaceText(“hello world”, 1, “hi world”); // save document doc.save(outFile);


**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| srcString | java.lang.String | The sting to be replaced. |
| thePage | int | Page number (0 for all pages) |
| destString | java.lang.String | Replacing string. |

**Returns:**
boolean - Returns true if replacement was made.
### replaceText(String srcString, String destString, TextState textState) {#replaceText-java.lang.String-java.lang.String-com.aspose.pdf.TextState-}

public boolean replaceText(String srcString, String destString, TextState textState)



Replaces text in the PDF file using specified  TextState  object.

--------------------

The example demonstrates how to replace text and set ``` TextState



 Document doc = new Document(inFile);
 // Create font and mark it to be embedded
 com.aspose.pdf.Font font = com.aspose.pdf.FontRepository.findFont("Courier New");
 font.isEmbedded ( true);
 // create PdfContentEditor object to edit text
 PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf(doc);
 // create textState object
 com.aspose.pdf.TextState textState = new com.aspose.pdf.TextState();
 textState.setFont ( font);
 textState.setFontStyle ( com.aspose.pdf.FontStyles.Bold | com.aspose.pdf.FontStyles.Italic);
 // change text with specified font
 editor.replaceText("hello world", "hi world", textState);
 // save document
 doc.save(outFile);

Parameters:

ParameterTypeDescription
srcStringjava.lang.StringString to be replaced
destStringjava.lang.StringReplacing string
textStateTextStateText state (Text Color, Font etc)

Returns: boolean - Returns true if replacement was made.

createMovie(Rectangle rect, String filePath, int page)

public void createMovie(Rectangle rect, String filePath, int page)

Parameters:

ParameterTypeDescription
rectjava.awt.Rectangle
filePathjava.lang.String
pageint

createSound(Rectangle rect, String filePath, String name, int page, String rate)

public void createSound(Rectangle rect, String filePath, String name, int page, String rate)

Parameters:

ParameterTypeDescription
rectjava.awt.Rectangle
filePathjava.lang.String
namejava.lang.String
pageint
ratejava.lang.String

deleteStamp(int pageNumber, int[] index)

public void deleteStamp(int pageNumber, int[] index)

Deletes multiple stamps on the specified page by stamp indexes.


PdfContentEditor contentEditor = new PdfContentEditor();
 contentEditor.bindPdf("file.pdf");
 contentEditor.deleteStamp(1, new int[] { 2, 3, 5} );
 contentEditor.save("outfile.pdf");

Parameters:

ParameterTypeDescription
pageNumberintPage number where stamp will be deleted.
indexint[]Stamp indexes.

deleteStampByIds(int[] stampIds)

public void deleteStampByIds(int[] stampIds)

Deletes stamps with specified IDs from all pages of the document.


PdfContentEditor contentEditor = new PdfContentEditor();
 contentEditor.bindPdf("file.pdf");
 contentEditor.deleteStampByIds(new int[] { 102, 103 } );
 contentEditor.save("outfile.pdf");

Parameters:

ParameterTypeDescription
stampIdsint[]Array of stamp IDs.

deleteStampByIds(int pageNumber, int[] stampIds)

public void deleteStampByIds(int pageNumber, int[] stampIds)

Deletes stamps on the specified page by multiple stamp IDs.


PdfContentEditor contentEditor = new PdfContentEditor();
 contentEditor.bindPdf("file.pdf");
 contentEditor.deleteStampByIds(1, new int[] { 100, 101 } );
 contentEditor.save("outfile.pdf");

Parameters:

ParameterTypeDescription
pageNumberintPage number where stamps will be deleted.
stampIdsint[]Array of stamp IDs.

deleteStampById(int pageNumber, int stampId)

public void deleteStampById(int pageNumber, int stampId)

Deletes stamp on the specified page by stamp ID.


PdfContentEditor contentEditor = new PdfContentEditor();
 contentEditor.bindPdf("file.pdf");
 contentEditor.deleteStampById(1, 100);
 contentEditor.save("outfile.pdf");

Parameters:

ParameterTypeDescription
pageNumberintPage number where stamp will be deleted.
stampIdintIdentifier of stamp which should be deleted.

hideStampById(int pageNumber, int stampId)

public void hideStampById(int pageNumber, int stampId)

Hides the stamp. After hiding, stamp visibility may be restored with ShowStampById method.

Parameters:

ParameterTypeDescription
pageNumberintNumber of the page.
stampIdintIdentifier of stamp which should be hidden.

showStampById(int pageNumber, int stampId)

public void showStampById(int pageNumber, int stampId)

Shows stamp which was hidden by HiddenStampById.

Parameters:

ParameterTypeDescription
pageNumberintNumber of the page.
stampIdintIdentifier of stamp which should be shown.

moveStampById(int pageNumber, int stampId, double x, double y)

public void moveStampById(int pageNumber, int stampId, double x, double y)

Changes position of the stamp on page.

Parameters:

ParameterTypeDescription
pageNumberintNumer of page.
stampIdintIdentifier of stamp which should be moved.
xdoubleNew stamp horizontal pozition on the page.
ydoubleNew stamp vertical position on the page.

moveStamp(int pageNumber, int stampIndex, double x, double y)

public void moveStamp(int pageNumber, int stampIndex, double x, double y)

Changes position of the stamp on page.

Parameters:

ParameterTypeDescription
pageNumberintNumber of page.
stampIndexintIndex of stamp on the page.
xdoubleNew stamp horizontal position.
ydoubleNew stamp vertical position.

deleteStampById(int stampId)

public void deleteStampById(int stampId)

Delete stamp by ID from all pages of the document.


PdfContentEditor contentEditor = new PdfContentEditor();
 contentEditor.bindPdf("file.pdf");
 contentEditor.deleteStampById(100);
 contentEditor.save("outfile.pdf");

Parameters:

ParameterTypeDescription
stampIdintIdentifier of stamp which should be deleted.
public void createLocalLink(Rectangle rect, int desPage, int originalPage)

Creates a local link in PDF document.

Parameters:

ParameterTypeDescription
rectjava.awt.RectangleThe rectangle for active click.
desPageintThe destination page.
originalPageintThe number of original page where rectangle bound with local link will be created.

replaceText(String srcString, String destString, int fontSize)

public boolean replaceText(String srcString, String destString, int fontSize)

Replaces text in the PDF file and sets font size.


The example demonstrates how to replace text and set font size for the new text.


 // open document
 Document doc = new Document(inFile);
 // Create font and mark it to be embedded
 com.aspose.pdf.Font font = FontRepository.FindFont("Courier New");
 font.isEmbedded ( true);
 // create PdfContentEditor object to edit text
 PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf(doc);
 // change text with specified font
 editor.replaceText("hello world", "hi world", 14);
 // save document
 doc.save(outFile);

Parameters:

ParameterTypeDescription
srcStringjava.lang.StringString to be replaced.
destStringjava.lang.StringReplacing string.
fontSizeintFont size.

Returns: boolean - Returns true if replacement was made.

getStamps(int pageNumber)

public StampInfo[] getStamps(int pageNumber)

Returns array of stamps on the page.

Parameters:

ParameterTypeDescription
pageNumberintPage number where stamps will be searched.

Returns: com.aspose.pdf.facades.StampInfo[] - Array of stamps.

close()

public void close()

Closes opened document.