public final class PdfContentEditor extends SaveableFacade
Represents a class to edit PDF file's content.
Modifier and Type | Field and Description |
---|---|
static String |
DOCUMENT_CLOSE
A document event type.
|
static String |
DOCUMENT_OPEN
A document event type.
|
static String |
DOCUMENT_PRINTED
A document event type.
|
static String |
DOCUMENT_SAVED
A document event type.
|
static String |
DOCUMENT_WILL_PRINT
A document event type.
|
static String |
DOCUMENT_WILL_SAVE
A document event type.
|
Constructor and Description |
---|
PdfContentEditor()
The constructor of the PdfContentEditor object.
|
PdfContentEditor(IDocument document)
Initializes new
PdfContentEditor object on base of the document . |
Modifier and Type | Method and Description |
---|---|
void |
addDocumentAdditionalAction(String eventType,
String code)
Adds additional action for document event.
|
void |
addDocumentAttachment(InputStream fileAttachmentStream,
String fileAttachmentName,
String description)
Adds document attachment with no annotation.
|
void |
addDocumentAttachment(String fileAttachmentPath,
String description)
Adds document attachment with no annotation.
|
void |
bindPdf(InputStream inputStream)
Binds a PDF stream for editing.
|
void |
bindPdf(String inputFile)
Binds a PDF file for editing.
|
void |
changeViewerPreference(int viewerAttribution)
Changes the view preference.
|
void |
close()
Closes opened document.
|
void |
createApplicationLink(Rectangle rect,
String application,
int page)
Creates a link to launch an application in PDF document.
|
void |
createApplicationLink(Rectangle rect,
String application,
int page,
Color clr)
Creates a link to launch an application in PDF document.
|
void |
createApplicationLink(Rectangle rect,
String application,
int page,
Color clr,
int[] actionName)
Creates a link to launch an application in PDF document.
|
void |
createBookmarksAction(String title,
Color color,
boolean boldFlag,
boolean italicFlag,
String file,
String actionType,
String destination)
Creates a bookmark with the specified action.
|
void |
createCaret(int page,
Rectangle annotRect,
Rectangle caretRect,
String symbol,
String annotContents,
Color color)
Creates caret annotation.
|
void |
createCustomActionLink(Rectangle rect,
int originalPage,
Color color,
int[] actionName)
Creates a link to custom actions in PDF document.
|
void |
createFileAttachment(Rectangle rect,
String contents,
InputStream attachmentStream,
String attachmentName,
int page,
String name)
Creates file attachment annotation.
|
void |
createFileAttachment(Rectangle rect,
String contents,
String filePath,
int page,
String name)
Creates file attachment annotation.
|
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");
|
void |
createJavaScriptLink(String code,
Rectangle rect,
int originalPage,
Color color)
Creates a link to JavaScript in PDF document.
|
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.
|
void |
createLocalLink(Rectangle rect,
int desPage,
int originalPage)
Creates a local link in PDF document.
|
void |
createLocalLink(Rectangle rect,
int desPage,
int originalPage,
Color clr)
Creates a local link in PDF document.
|
void |
createLocalLink(Rectangle rect,
int desPage,
int originalPage,
Color clr,
int[] actionName)
Creates a local link in PDF document.
|
void |
createMarkup(Rectangle rect,
String contents,
int type,
int page,
Color clr)
Creates markup annotation it PDF document.
|
void |
createMovie(Rectangle rect,
String filePath,
int page) |
void |
createPdfDocumentLink(Rectangle rect,
String remotePdf,
int originalPage,
int destinationPage)
Creates a link to another PDF document page.
|
void |
createPdfDocumentLink(Rectangle rect,
String remotePdf,
int originalPage,
int destinationPage,
Color clr)
Creates a link to another PDF document page.
|
void |
createPdfDocumentLink(Rectangle rect,
String remotePdf,
int originalPage,
int destinationPage,
Color clr,
int[] actionName)
Creates a link to another PDF document page.
|
void |
createPolygon(LineInfo lineInfo,
int page,
Rectangle annotRect,
String annotContents)
Creates polygon annotation.
|
void |
createPolyLine(LineInfo lineInfo,
int page,
Rectangle annotRect,
String annotContents)
Creates polyline annotation.
|
void |
createPopup(Rectangle rect,
String contents,
boolean open,
int page)
Creates popup annotation in PDF document.
|
void |
createRubberStamp(int page,
Rectangle annotRect,
String annotContents,
Color color,
InputStream appearanceStream)
Creates a rubber stamp annotation.
|
void |
createRubberStamp(int page,
Rectangle annotRect,
String annotContents,
Color color,
String appearanceFile)
Creates a rubber stamp annotation.
|
void |
createRubberStamp(int page,
Rectangle annotRect,
String icon,
String annotContents,
Color color)
Creates a rubber stamp annotation.
|
void |
createSound(Rectangle rect,
String filePath,
String name,
int page,
String rate) |
void |
createSquareCircle(Rectangle rect,
String contents,
Color clr,
boolean square,
int page,
int borderWidth)
Creates square-circle annotation.
|
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!"
|
void |
createWebLink(Rectangle rect,
String url,
int originalPage)
Creates a web link in PDF document.
|
void |
createWebLink(Rectangle rect,
String url,
int originalPage,
Color clr)
Creates a web link in PDF document.
|
void |
createWebLink(Rectangle rect,
String url,
int originalPage,
Color clr,
int[] actionName)
Creates a web link in PDF document.
|
void |
deleteAttachments()
Deletes all attachments in PDF document.
|
void |
deleteImage()
Deletes all images from PDF document.
|
void |
deleteImage(int pageNumber,
int[] index)
Deletes the specified images on the specified page.
|
void |
deleteStamp(int pageNumber,
int[] index)
Deletes multiple stamps on the specified page by stamp indexes.
|
void |
deleteStampById(int stampId)
Delete stamp by ID from all pages of the document.
|
void |
deleteStampById(int pageNumber,
int stampId)
Deletes stamp on the specified page by stamp ID.
|
void |
deleteStampByIds(int[] stampIds)
Deletes stamps with specified IDs from all pages of the document.
|
void |
deleteStampByIds(int pageNumber,
int[] stampIds)
Deletes stamps on the specified page by multiple stamp IDs.
|
void |
drawCurve(LineInfo lineInfo,
int page,
Rectangle annotRect,
String annotContents)
Creates curve annotation.
|
List<Annotation> |
extractLink()
Extracts the collection of Link instances contained in PDF document.
|
ReplaceTextStrategy |
getReplaceTextStrategy()
Get a set of parameters for replace text operation
|
StampInfo[] |
getStamps(int pageNumber)
Returns array of stamps on the page.
|
TextEditOptions |
getTextEditOptions()
Gets text edit options.
|
TextReplaceOptions |
getTextReplaceOptions()
Gets text replace options.
|
TextSearchOptions |
getTextSearchOptions()
Gets text search options.
|
int |
getViewerPreference()
Returns the view preference.
|
void |
hideStampById(int pageNumber,
int stampId)
Hides the stamp.
|
void |
moveStamp(int pageNumber,
int stampIndex,
double x,
double y)
Changes position of the stamp on page.
|
void |
moveStampById(int pageNumber,
int stampId,
double x,
double y)
Changes position of the stamp on page.
|
void |
removeDocumentOpenAction()
Removes open action from the document.
|
void |
replaceImage(int pageNumber,
int index,
String imageFile)
Replaces the specified image on the specified page of PDF document with another image.
|
boolean |
replaceText(String srcString,
int thePage,
String destString)
Replaces text in the PDF file on the specified page.
|
boolean |
replaceText(String srcString,
int thePage,
String destString,
TextState textState)
Replaces text in the PDF file on the specified page.
|
boolean |
replaceText(String srcString,
String destString)
Replaces text in the PDF file.
|
boolean |
replaceText(String srcString,
String destString,
int fontSize)
Replaces text in the PDF file and sets font size.
|
boolean |
replaceText(String srcString,
String destString,
TextState textState)
Replaces text in the PDF file using specified
TextState object. |
void |
setReplaceTextStrategy(ReplaceTextStrategy value)
Set a set of parameters for replace text operation
|
void |
setTextEditOptions(TextEditOptions value)
Sets text edit options.
|
void |
setTextReplaceOptions(TextReplaceOptions value)
Sets text replace options.
|
void |
setTextSearchOptions(TextSearchOptions value)
Sets text search options.
|
void |
showStampById(int pageNumber,
int stampId)
Shows stamp which was hidden by HiddenStampById.
|
save, save
bindPdf, bindPdf, bindPdf, dispose, getDocument
public static final String DOCUMENT_OPEN
A document event type. Opens a document.
public static final String DOCUMENT_CLOSE
A document event type. Closes a document.
public static final String DOCUMENT_WILL_SAVE
A document event type. Excute a action before saving.
public static final String DOCUMENT_SAVED
A document event type. Excute a action after saving.
public static final String DOCUMENT_WILL_PRINT
A document event type. Excute a action before printing.
public static final String DOCUMENT_PRINTED
A document event type. Excute a action after printing.
public PdfContentEditor()
The constructor of the PdfContentEditor object.
public PdfContentEditor(IDocument document)
Initializes new PdfContentEditor
object on base of the document
.
document
- Pdf document.public TextSearchOptions getTextSearchOptions()
Gets text search options.
public void setTextSearchOptions(TextSearchOptions value)
Sets text search options.
value
- TextSearchOptions elementpublic TextEditOptions getTextEditOptions()
Gets text edit options.
public void setTextEditOptions(TextEditOptions value)
Sets text edit options.
value
- setTextEditOptions elementpublic TextReplaceOptions getTextReplaceOptions()
Gets text replace options.
public void setTextReplaceOptions(TextReplaceOptions value)
Sets text replace options.
value
- TextReplaceOptions elementpublic ReplaceTextStrategy getReplaceTextStrategy()
Get a set of parameters for replace text operation
public void setReplaceTextStrategy(ReplaceTextStrategy value)
Set a set of parameters for replace text operation
value
- ReplaceTextStrategy elementpublic void bindPdf(String inputFile)
Binds a PDF file for editing.
public void bindPdf(InputStream inputStream)
Binds a PDF stream for editing.
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 }
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");
rect
- The rectangle for active click.url
- The web link destination.originalPage
- The number of original page on which rectangle bound with web link will be created.clr
- The color of rectangle for active click.actionName
- 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");
rect
- The rectangle for active click.url
- The web link destination.originalPage
- The number of original page where rectangle bound with web link will be created.clr
- The 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");
rect
- The rectangle for active click.url
- The web link destination.originalPage
- The 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");
rect
- The rectangle for active click.desPage
- The destination page.originalPage
- The number of original page where rectangle bound with local link will be created.clr
- The color of rectangle for active click.actionName
- The array of actions (members of PredefinedAction enum) corresponding to executing menu items
in Acrobat viewer.PredefinedAction
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");
rect
- The rectangle for active click.desPage
- The destination page.originalPage
- The number of original page where rectangle bound with local link will be created.clr
- The 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");
rect
- The rectangle for active click.remotePdf
- The PDF document which page will be opened.originalPage
- The number of original page where rectangle bound with link will be created.destinationPage
- The destination page.clr
- The color of rectangle for active click.actionName
- 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");
rect
- The rectangle for active click.remotePdf
- The PDF document which page will be opened.originalPage
- The number of original page where rectangle bound with link will be created.destinationPage
- The destination page.clr
- The 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");
rect
- The rectangle for active click.remotePdf
- The PDF document which page will be opened.originalPage
- The number of original page where rectangle bound with link will be created.destinationPage
- The destination page.public void createCustomActionLink(Rectangle rect, int originalPage, Color color, int[] actionName)
Creates a link to custom actions in PDF document.
rect
- The rectangle for active click.originalPage
- The number of original page where rectangle bound with link will be created.color
- The color of rectangle for active click.actionName
- 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.
rect
- The rectangle for active click.application
- The path of application to be launched.page
- The number of original page where rectangle bound with link will be created.clr
- The color of rectangle for active click.actionName
- 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");
rect
- The rectangle for active click.application
- The path of application to be launched.page
- The number of original page where rectangle bound with link will be created.clr
- The 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");
rect
- The rectangle for active click.application
- The path of application to be launched.page
- The 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");
code
- The JavaScript code.rect
- The rectangle for active click.originalPage
- The number of original page where rectangle bound with link will be created.color
- The color of rectangle for active click.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");
rect
- The annotation rectangle defining the location of the annotation on the page.title
- The title of the annotation.contents
- The contents of the annotation.open
- A flag specifying whether the annotation should initially be displayed open.icon
- The name of an icon will be used in displaying the annotation. This value can be: "Comment",
"Key", "Note", "Help", "NewParagraph", "Paragraph", "Insert"page
- The number of original page where the text annotation will be created.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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.page
- The number of original page where the text annotation will be created.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");
rect
- The rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.type
- The type of markup annotation. Can be 0 (Highlight), 1 (Underline), 2 (StrikeOut), 3
(Squiggly).page
- The number of original page where the annotation will be created.clr
- The color of markup.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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.open
- A flag specifying whether the pop-up annotation should initially be displayed open.page
- The number of original page where the annotation will be created.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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.filePath
- The path of the file will be attached.page
- The number of original page where the annotation will be created.name
- The name of an icon will be used in displaying the annotation. This value can be: "Graph",
"PushPin", "Paperclip", "Tag".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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.attachmentStream
- The attachment file stream.attachmentName
- The attachment name.page
- The number of original page where the annotation will be created.name
- The name of an icon will be used in displaying the annotation. This value can be:
"Graph",
"PushPin", "Paperclip", "Tag".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");
fileAttachmentPath
- The path of the file will be attached.description
- The description information.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");
fileAttachmentStream
- The stream of the file will be attached.fileAttachmentName
- The attachment name.description
- The description information.public void deleteAttachments()
Deletes all attachments in PDF document.
PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf("example.pdf"); editor.deleteAttachments(); editor.save("example_out.pdf");
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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.x1
- The starting horizontal coordinate of the line.y1
- The starting vertical coordinate of the line.x2
- The ending horizontal coordinate of the line.y2
- The ending vertical coordinate of the line.page
- The number of original page where the annotation will be created.border
- The border width in points. If this value is 0 no border is drawn. Default value is 1.clr
- The color of line.borderStyle
- The 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).dashArray
- 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".LEArray
- 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".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");
rect
- The annotation rectangle defining the location of the annotation on the page.contents
- The contents of the annotation.clr
- The color of square or circle.square
- True (square), false (sircle).page
- The number of original page where the annotation will be created.borderWidth
- The border width of square or circle.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");
lineInfo
- The instance of LineInfo class.page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.annotContents
- The contents of the annotation.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");
lineInfo
- The instance of LineInfo class.page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.annotContents
- The contents of the annotation.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");
lineInfo
- The instance of LineInfo class.page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.annotContents
- The contents of the annotation.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");
page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.caretRect
- The actual boundaries of the underlying caret.symbol
- A symbol will be associated with the caret. Value can be: "P" (Paragraph), "None".annotContents
- The contents of the annotation.color
- The color of the annotation.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");
page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.icon
- String valueannotContents
- The contents of the annotation.color
- The color of the annotation.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");
page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.annotContents
- The contents of the annotation.color
- The color of the annotation.appearanceFile
- The path of appearance file.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");
page
- The number of original page where the annotation will be created.annotRect
- The annotation rectangle defining the location of the annotation on the page.annotContents
- The contents of the annotation.color
- The color of the annotation.appearanceStream
- The stream of appearance file.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");
title
- The title of the bookmark.color
- The color of the bookmark's title.boldFlag
- The flag of bold attribution.italicFlag
- The flag of italic attribution.file
- Another file or application required when the action type is "GoToR" or "Launch".actionType
- The action type. The value can be: "GoToR", "Launch", "GoTo", "URI".destination
- The local destination or remote destination or URL.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");
eventType
- The document event types.code
- The code of JavaScript.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");
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");
viewerAttribution
- The view attribution defined in the ViewerPreference class.public int getViewerPreference()
Returns the view preference.
PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf("example.pdf"); int prefValue = editor.GetViewerPreference(); if ((prefValue & ViewerPreference.PageModeUseOutline) != 0) { // ... }
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");
pageNumber
- The number of page on which the image is replaced.index
- The index of the image object must be replaced.imageFile
- The image file will be used for replacing.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");
pageNumber
- The number of page on which images must be deleted.index
- An array repsents images' indexes.public void deleteImage()
Deletes all images from PDF document.
PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf("example.pdf"); editor.deleteImage(); editor.save("example_out.pdf");
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);
srcString
- The string to be replaced.thePage
- Page number (0 means "all pages").destString
- The replaced string.textState
- Text state (Text Color, Font etc).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);
srcString
- The string to be replaced.destString
- Replacing 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);
srcString
- The sting to be replaced.thePage
- Page number (0 for all pages)destString
- Replacing string.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
text properties for the new text.
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);
srcString
- String to be replaceddestString
- Replacing stringtextState
- Text state (Text Color, Font etc)public void createSound(Rectangle rect, String filePath, String name, int page, String rate)
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");
pageNumber
- Page number where stamp will be deleted.index
- Stamp indexes.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");
stampIds
- Array of stamp IDs.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");
pageNumber
- Page number where stamps will be deleted.stampIds
- Array of stamp IDs.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");
pageNumber
- Page number where stamp will be deleted.stampId
- Identifier of stamp which should be deleted.public void hideStampById(int pageNumber, int stampId)
Hides the stamp. After hiding, stamp visibility may be restored with ShowStampById method.
pageNumber
- Number of the page.stampId
- Identifier of stamp which should be hidden.public void showStampById(int pageNumber, int stampId)
Shows stamp which was hidden by HiddenStampById.
pageNumber
- Number of the page.stampId
- Identifier of stamp which should be shown.public void moveStampById(int pageNumber, int stampId, double x, double y)
Changes position of the stamp on page.
pageNumber
- Numer of page.stampId
- Identifier of stamp which should be moved.x
- New stamp horizontal pozition on the page.y
- New stamp vertical position on the page.public void moveStamp(int pageNumber, int stampIndex, double x, double y)
Changes position of the stamp on page.
pageNumber
- Number of page.stampIndex
- Index of stamp on the page.x
- New stamp horizontal position.y
- New stamp vertical position.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");
stampId
- Identifier of stamp which should be deleted.public void createLocalLink(Rectangle rect, int desPage, int originalPage)
Creates a local link in PDF document.
rect
- The rectangle for active click.desPage
- The destination page.originalPage
- The number of original page where rectangle bound with local link will be created.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);
srcString
- String to be replaced.destString
- Replacing string.fontSize
- Font size.public StampInfo[] getStamps(int pageNumber)
Returns array of stamps on the page.
pageNumber
- Page number where stamps will be searched.