Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class PdfContentEditor

java.lang.Object
  extended bycom.aspose.pdf.kit.PdfContentEditor

public class PdfContentEditor
extends java.lang.Object

Represents a class to edit the pdf file's content.


Constructor Summary
PdfContentEditor()
          The constructor of the PdfContentEditor object.
 
Method Summary
 void bindPdf(java.io.InputStream inputStream)
          Binds a Pdf Stream for editing.
 void bindPdf(java.lang.String inputFile)
          Binds a Pdf file for editing
 void createApplicationLink(java.awt.Rectangle rect, java.lang.String application, int originalPage)
          Creates a application link in the same pdf.
 void createBookmarkOfPage(java.lang.String[] bookmarkName, int[] pageNumber)
          Creates bookmarks for multipages using the corresponding bookmark names.
 void createBookmarkOfPage(java.lang.String bkname, int pagenumber)
          Creates bookmark for the page you want.
 void createBookmarks()
          Creates bookmark for all of pages.
 void createFileAttachment(java.awt.Rectangle rect, java.lang.String contents, java.lang.String filePath, int page, java.lang.String name)
          Creates a file attachment annotation.
 void createFreeText(java.awt.Rectangle rect, java.lang.String contents, int page)
          Creates FreeText Annotations.
 void createLine(java.awt.Rectangle rect, java.lang.String contents, float x1, float y1, float x2, float y2, int page, int border, java.lang.String borderStyle, int[] dashArray, java.lang.String[] LEArray, java.awt.Color clr)
          Creates Line Annotations.
 void createLocalLink(java.lang.String outputFile, java.awt.Rectangle rect, int desPage, int page)
          Creates a local link in the pdf by add annotation.
 void createMarkup(java.awt.Rectangle rect, java.lang.String contents, int type, float[] quadPoints, int page, java.awt.Color clr)
          Creates Markup Annotations.
 void createPdfDocumentLink(java.awt.Rectangle rect, java.lang.String document, int originalPage, int pageOfOpenDocument)
          Creates a pdf document link in the same pdf file.
 void createPopup(java.awt.Rectangle rect, java.lang.String contents, boolean open, int page)
          Creates Popup Annotations.
 void createText(java.awt.Rectangle rect, java.lang.String title, java.lang.String contents, boolean open, java.lang.String icon, int page)
          Creates Text Annotations.
 void createWebLink(java.awt.Rectangle rect, java.lang.String url, int page)
          Creates a web link in the pdf by add annotation.
 void replaceText(java.lang.String srcString, java.lang.String descString)
          Replaces srcString in the PDF file with descString.
 void save(java.io.OutputStream outputStream)
          Saves the result PDF to stream.
 void save(java.lang.String outputFile)
          Saves the result PDF to file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfContentEditor

public PdfContentEditor()
The constructor of the PdfContentEditor object.

Method Detail

bindPdf

public void bindPdf(java.lang.String inputFile)
             throws java.io.FileNotFoundException
Binds a Pdf file for editing

Parameters:
inputFile - The pdf file to be edited.
Throws:
java.io.FileNotFoundException
See Also:
bindPdf(InputStream)

bindPdf

public void bindPdf(java.io.InputStream inputStream)
Binds a Pdf Stream for editing.

Parameters:
inputStream - The pdf Stream to be edited.
Throws:
java.io.FileNotFoundException
See Also:
replaceText(String, String)

save

public void save(java.lang.String outputFile)
          throws java.lang.Exception
Saves the result PDF to file.

Parameters:
outputFile - output pdf file
Throws:
java.lang.Exception
See Also:
save(OutputStream)

save

public void save(java.io.OutputStream outputStream)
          throws java.io.IOException,
                 PdfKitException
Saves the result PDF to stream.

Parameters:
outputStream - output pdf stream
Throws:
java.io.IOException
PdfKitException
See Also:
replaceText(String, String)

replaceText

public void replaceText(java.lang.String srcString,
                        java.lang.String descString)
                 throws java.io.IOException,
                        com.aspose.pdf.kit.COSVisitorException
Replaces srcString in the PDF file with descString.

 [SampleCode]
 //Replace the string "Pdf" with "WordPpt" in the give pdf file
 PdfContentEditor editor = new PdfContentEditor();
 editor.bindPdf("text.pdf");
 editor.replaceText("Pdf", "WordPpt");
 editor.save("replace.pdf");
 

Parameters:
srcString - the string to be replaced
descString - the replaced string
Throws:
java.io.IOException
COSVisitorException

createBookmarks

public void createBookmarks()
                     throws java.lang.Exception
Creates bookmark for all of pages.

 [SampleCode]
 PdfContentEditor editor = new PdfContentEditor();
 editor.CreateBookmarks();
 

Throws:
java.lang.Exception - if input file not exist,throw exception

createBookmarkOfPage

public void createBookmarkOfPage(java.lang.String bkname,
                                 int pagenumber)
                          throws java.lang.Exception
Creates bookmark for the page you want.

 [SampleCode]
 PdfContentEditor editor = new PdfContentEditor();
 editor.createBookmarkOfPage("bkname",pagenumber);
 

Parameters:
bkname - bookmark's name you want to define
pagenumber - the desination page
Throws:
java.lang.Exception - if input file not exist,throw exception

createWebLink

public void createWebLink(java.awt.Rectangle rect,
                          java.lang.String url,
                          int page)
                   throws java.lang.Exception
Creates a web link in the pdf by add annotation.

 [SampleCode]
 PdfContentEditor editor = new PdfContentEditor();
 Rectangle rect=new Rectangle(130,130,150,150);
 try{
   editor.createWebLink(rect,"http://www.aspose.com",2);
  }
  catch(Exception e){
   e.printStackTrace();
 }
 

Parameters:
rect - Rectangle the Rectangle for active click
url - String the web destination
page - int create rectangle in the page
Returns:
void
Throws:
java.io.IOException
java.lang.Exception

createLocalLink

public void createLocalLink(java.lang.String outputFile,
                            java.awt.Rectangle rect,
                            int desPage,
                            int page)
                     throws java.lang.Exception
Creates a local link in the pdf by add annotation.

 [SampleCode]
 PdfContentEditor editor = new PdfContentEditor();
 Rectangle rect=new Rectangle(130,130,150,150);
 String outputFile="test.pdf"
 try{
   editor.createLocalLink(outputFile,rect,1,2);
  }
 catch(Exception e){
	 e.printStackTrace();
 }
 

Parameters:
outputFile - String the edited file
rect - Rectangle the Rectangle for active click
desPage - the destination page
page - int create rectangle in the page
Throws:
java.io.IOException
java.lang.Exception

createBookmarkOfPage

public void createBookmarkOfPage(java.lang.String[] bookmarkName,
                                 int[] pageNumber)
                          throws java.lang.Exception
Creates bookmarks for multipages using the corresponding bookmark names.

 [SampleCode]
  PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("test.pdf");
  String []bookmarkName={"test1","test2","test3"};
  int []pageNumber={3,2,1};
  editor.createBookmarkOfPage(bookmarkName,pageNumber);
  editor.save("test_output.pdf");
 

Parameters:
bookmarkName - The specified bookmark name array
pageNumber - The specified desination page array
Throws:
java.lang.Exception

createPdfDocumentLink

public void createPdfDocumentLink(java.awt.Rectangle rect,
                                  java.lang.String document,
                                  int originalPage,
                                  int pageOfOpenDocument)
                           throws java.lang.Exception
Creates a pdf document link in the same pdf file.

 [SampleCode]
  PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example1.pdf");
	Rectangle rect=new Rectangle(130,130,150,150);
  String document="example1_document.pdf";
  editor.createPdfDocumentLink(rect,document,1,2);
  editor.save("example1_pageofdocument.pdf");
 

Parameters:
rect - Rectangle The Rectangle for active click
document - String The Document for open
originalPage - int The page in which the url link is created
pageOfOpenDocument - int The page of document to be opened
Throws:
java.lang.Exception

createApplicationLink

public void createApplicationLink(java.awt.Rectangle rect,
                                  java.lang.String application,
                                  int originalPage)
                           throws java.lang.Exception
Creates a application link in the same pdf.

 [SampleCode]
  PdfContentEditor editor = new PdfContentEditor();
  editor.bindPdf("example1.pdf");
	Rectangle rect=new Rectangle(130,130,150,150);
  String document="example1_document.pdf";
  editor.createApplicationLink(rect,document,1,2);
  editor.save("example1_pageofdocument.pdf");
 

Parameters:
rect - Rectangle The Rectangle for active click
application - String The application to be launched
originalPage - int The page in which the url link is created
Throws:
java.lang.Exception

createText

public void createText(java.awt.Rectangle rect,
                       java.lang.String title,
                       java.lang.String contents,
                       boolean open,
                       java.lang.String icon,
                       int page)
                throws java.io.IOException,
                       PdfKitException
Creates Text Annotations.

 [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(50,50,200,200);
    String document="example1_document.pdf";
    editor.createText(rect,"welcome to aspose!","you are welcome!",true,"Key",1);
    editor.save("example1_application.pdf");
 

Parameters:
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 to be used in displaying the annotation,it's value include:Comment,Key,Note,Help,NewParagraph,Paragraph,Insert
page - The page in which the text annotation is created
Throws:
java.io.IOException
PdfKitException

createFreeText

public void createFreeText(java.awt.Rectangle rect,
                           java.lang.String contents,
                           int page)
                    throws java.io.IOException,
                           PdfKitException
Creates FreeText Annotations.

 [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(50,50,200,200);
    String document="example1_document.pdf";
    editor.createFreeText(rect,"you are welcome!",1);
    editor.save("example1_application.pdf");
 

Parameters:
rect - The annotation rectangle defining the location of the annotation on the page
contents - The contents of the annotation
page - The page in which the text annotation is created
Throws:
java.io.IOException
PdfKitException

createLine

public void createLine(java.awt.Rectangle rect,
                       java.lang.String contents,
                       float x1,
                       float y1,
                       float x2,
                       float y2,
                       int page,
                       int border,
                       java.lang.String borderStyle,
                       int[] dashArray,
                       java.lang.String[] LEArray,
                       java.awt.Color clr)
                throws java.io.IOException,
                       PdfKitException
Creates Line Annotations.

 [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(50,50,200,200);
    Color c=new Color(255,125,125);
    int []dashArray={};
    String []LEArray={};
    editor.createLine(rect,"",100,100,400,100,1,5,"s",dashArray,LEArray,c);
    editor.save("example1_Line.pdf");
 

Parameters:
rect - The annotation rectangle defining the location of the annotation on the page
contents - The contents of the annotation
x1 - The starting horizontal coordinates of the line
y1 - The starting vertical coordinates of the line
x2 - The ending horizontal coordinates of the line
y2 - The ending verticalcoordinates of the line
page - The page in which the text annotation is created
border - The border width in points. If this value is 0, no border is drawn. Default value: 1
borderStyle - The border style specifying the width and dash pattern to be used in drawing the line, it's value includes:S,D,B,I,U
dashArray - A dash array defining a pattern of dashes and gaps to be used in drawing a dashed border
LEArray - An array of two names specifying the line ending styles to be used in drawing the line,it's value includes:Square,Circle,Diamond,OpenArrow,ClosedArrow,etc
clr - The color of line
Throws:
java.io.IOException
PdfKitException

createMarkup

public void createMarkup(java.awt.Rectangle rect,
                         java.lang.String contents,
                         int type,
                         float[] quadPoints,
                         int page,
                         java.awt.Color clr)
                  throws java.io.IOException,
                         PdfKitException
Creates Markup Annotations.

   [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(50,50,200,200);
    String document="example1_document.pdf";
    float [] quadPoints={100,115,150,115,150,105,100,105};
    Color clr=new Color(255,0,255);
    editor.createMarkup(rect,"welcome to aspose",3,quadPoints,1,clr);
    editor.save("example1_application.pdf");
 

Parameters:
rect - The annotation rectangle defining the location of the annotation on the page
contents - The contents of the annotation
type - The type of annotation that this dictionary describes; must be Highlight(0), Underline(1), Squiggly(2), or StrikeOut(3)
quadPoints - An array of 8 กม n numbers specifying the coordinates of n quadrilaterals in default user space
page - The page in which the text annotation is created
clr - The color of markup
Throws:
java.io.IOException
PdfKitException

createPopup

public void createPopup(java.awt.Rectangle rect,
                        java.lang.String contents,
                        boolean open,
                        int page)
                 throws java.io.IOException,
                        PdfKitException
Creates Popup Annotations.

 [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(50,50,200,200);
    String document="example1_document.pdf";
    editor.createPopup(rect,"welcome to aspose!",true,1);
    editor.save("example1_application.pdf");
 

Parameters:
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 page in which the text annotation is created
Throws:
java.io.IOException
PdfKitException

createFileAttachment

public void createFileAttachment(java.awt.Rectangle rect,
                                 java.lang.String contents,
                                 java.lang.String filePath,
                                 int page,
                                 java.lang.String name)
                          throws java.io.IOException,
                                 PdfKitException
Creates a file attachment annotation.

 [SampleCode]
    PdfContentEditor editor = new PdfContentEditor();
    editor.bindPdf("example1.pdf");
	  Rectangle rect=new Rectangle(130,130,150,150);
    String document="example1_document.pdf";
    editor.createFileAttachment(rect,"file attachment",document,1,"Tag");
    editor.save("example1_attachment.pdf");
 

Parameters:
rect - Rectangle The Rectangle for active click
contents - String Text to be displayed for the annotation
filePath - String The path to the file
page - int The page in which annotation is created
name - String The name of an icon to be used in displaying the annotation
Throws:
java.io.IOException
PdfKitException