Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class PdfFileEditor

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

public class PdfFileEditor
extends java.lang.Object

Represents a class for manipulating existing Pdf file, Concatenating Pdf files, inserting pages, extracting pages.


Constructor Summary
PdfFileEditor()
          Creates a PdfFileEditor object instance.
 
Method Summary
 boolean append(java.io.InputStream inputStream, java.io.InputStream portStream, int startPage, int endPage, java.io.OutputStream outputStream)
          Appends pages, which are chosen from portFile within the range from startPage to endPage, at the end of inputFile.
 boolean append(java.lang.String inputFile, java.lang.String portFile, int startPage, int endPage, java.lang.String outputFile)
          Appends pages, which are chosen from portFile within the range from startPage to endPage, at the end of inputFile.
 boolean concatenate(java.io.InputStream[] inputStreams, java.io.OutputStream outputStream)
          Merges multi-stream of Pdf into a new Pdf stream,supports for Acroform.
 boolean concatenate(java.io.InputStream firstInputStream, java.io.InputStream secInputStream, java.io.OutputStream outputStream)
          Merges two Pdf documents into a new Pdf document,supports for AcroForm.
 boolean concatenate(java.lang.String firstInputFile, java.lang.String secInputFile, java.lang.String outputFile)
          Merges two Pdf documents into a new Pdf document,supports for AcroForm.
 boolean extract(java.io.InputStream inputStream, int[] pageNumber, java.io.OutputStream outputStream)
          Extracts pages specified by number array, saves as a new Pdf file.
 boolean extract(java.io.InputStream inputStream, int startPage, int endPage, java.io.OutputStream outputStream)
          Extracts pages from input file,saves as a new Pdf file.
 boolean extract(java.lang.String inputFile, int[] pageNumber, java.lang.String outputFile)
          Extracts pages specified by number array, saves as a new Pdf file.
 boolean extract(java.lang.String inputFile, int startPage, int endPage, java.lang.String outputFile)
          Extracts pages from input file,saves as a new Pdf file.
 boolean insert(java.io.InputStream inputStream, int insertLocation, java.io.InputStream portStream, int[] pageNumber, java.io.OutputStream outputStream)
          Inserts pages from an other file into the input Pdf file.
 boolean insert(java.io.InputStream inputStream, int insertLocation, java.io.InputStream portStream, int startPage, int endPage, java.io.OutputStream outputStream)
          Inserts pages from an other file into the input Pdf file.
 boolean insert(java.lang.String inputFile, int insertLocation, java.lang.String portFile, int[] pageNumber, java.lang.String outputFile)
          Inserts pages from an other file into the input Pdf file.
 boolean insert(java.lang.String inputFile, int insertLocation, java.lang.String portFile, int startPage, int endPage, java.lang.String outputFile)
          Inserts pages from an other file into the Pdf file at a position.
 boolean makeBooklet(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Makes booklet from the inputStream to outputStream.
 boolean makeBooklet(java.io.InputStream inputStream, java.io.OutputStream outputStream, PageSize pageSize)
          Makes booklet from the inputStream to outputStream.
 boolean makeBooklet(java.lang.String inputFile, java.lang.String outputFile)
          Makes booklet from the inputFile to outputFile.
 boolean makeBooklet(java.lang.String inputFile, java.lang.String outputFile, PageSize pageSize)
          Makes booklet from the inputFile to outputFile.
 boolean makeNUp(java.io.InputStream inputStream, java.io.OutputStream outputStream, int x, int y)
          Makes N-Up document from the inputStream to outputStream.
 boolean makeNUp(java.io.InputStream inputStream, java.io.OutputStream outputStream, int x, int y, PageSize pageSize)
          Makes N-Up document from the inputStream to outputStream.
 boolean makeNUp(java.lang.String inputFile, java.lang.String outputFile, int x, int y)
          Makes N-Up document from the inputFile to outputFile.
 boolean makeNUp(java.lang.String inputFile, java.lang.String outputFile, int x, int y, PageSize pageSize)
          Makes N-Up document from the inputFile to outputFile.
 boolean splitFromFirst(java.io.InputStream inputStream, int location, java.io.OutputStream outputStream)
          Splits from location,and saves the front part in output Stream.
 boolean splitFromFirst(java.lang.String inputFile, int location, java.lang.String outputFile)
          Splits from location,and saves the front part as a new file.
 boolean splitToEnd(java.io.InputStream inputStream, int location, java.io.OutputStream outputStream)
          Splits from location, and saves the rare part as a new file Stream.
 boolean splitToEnd(java.lang.String inputFile, int location, java.lang.String outputFile)
          Splits from location, and saves the rare part as a new file.
 java.io.ByteArrayOutputStream[] splitToPages(java.io.InputStream inputStream)
          Splits the Pdf file into single-page documents.
 java.io.ByteArrayOutputStream[] splitToPages(java.lang.String inputFile)
          Splits the Pdf file into single-page documents.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfFileEditor

public PdfFileEditor()
Creates a PdfFileEditor object instance.

Method Detail

concatenate

public boolean concatenate(java.lang.String firstInputFile,
                           java.lang.String secInputFile,
                           java.lang.String outputFile)
                    throws java.io.IOException,
                           PdfKitException,
                           java.io.IOException
Merges two Pdf documents into a new Pdf document,supports for AcroForm.

 [SampleCode]
 String inFile1 = "example1.pdf";
 String inFile2 = "example2.pdf";
 String outFile = "kitOut.pdf";
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.concatenate(inFile1, inFile2, outFile);
 

Parameters:
firstInputFile - String The first Pdf document.
secInputFile - String The second Pdf document.
outputFile - String Output Pdf document name.
Returns:
boolean - True for success,or false.
Throws:
java.io.IOException
PdfKitException
java.io.IOException

concatenate

public boolean concatenate(java.io.InputStream firstInputStream,
                           java.io.InputStream secInputStream,
                           java.io.OutputStream outputStream)
                    throws java.io.IOException,
                           PdfKitException
Merges two Pdf documents into a new Pdf document,supports for AcroForm.

Parameters:
firstInputStream - InputStream The first Pdf Stream.
secInputStream - InputStream The second Pdf Stream.
outputStream - OutputStream Output Pdf Stream.
Returns:
boolean True for success,or false.
Throws:
java.io.IOException
AsposeExceptionon
PdfKitException

concatenate

public boolean concatenate(java.io.InputStream[] inputStreams,
                           java.io.OutputStream outputStream)
                    throws java.io.IOException,
                           PdfKitException,
                           java.io.IOException
Merges multi-stream of Pdf into a new Pdf stream,supports for Acroform.

 [SampleCode]
 FileInputStream inStream1 = new FileInputStream("example1.pdf");
 FileInputStream inStream2 = new FileInputStream("example2.pdf");
 FileInputStream inStream3 = new FileInputStream("example3.pdf");
 FileInputStream inStream4 = new FileInputStream("example4.pdf");
 FileOutputStream outStream = new FileOutputStream("kitOut.pdf");
 //buffer the input streams
 InputStream[] inStreams = new InputStream[] {
 inStream1, inStream2, inStream3, inStream4};
 //concatenate the input files
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.concatenate(inStreams, outStream);
 //close the output stream
 outStream.close();
 

Parameters:
inputStreams - InputStream[] Input Pdf streams.
outputStream - OutputStream Output Pdf stream.
Returns:
boolean True for success,or false.
Throws:
java.io.IOException
PdfKitException
java.io.IOException

append

public boolean append(java.io.InputStream inputStream,
                      java.io.InputStream portStream,
                      int startPage,
                      int endPage,
                      java.io.OutputStream outputStream)
               throws java.io.IOException,
                      PdfKitException
Appends pages, which are chosen from portFile within the range from startPage to endPage, at the end of inputFile.

Parameters:
inputStream - InputStream Input Pdf Stream.
portStream - InputStream Exporting Pages from Pdf Stream.
startPage - int Page starts in portFile.
endPage - int Page ends in portFile.
outputStream - OutputStream Output Pdf document Stream.
Returns:
boolean True for success, or false.
Throws:
java.io.IOException
PdfKitException

append

public boolean append(java.lang.String inputFile,
                      java.lang.String portFile,
                      int startPage,
                      int endPage,
                      java.lang.String outputFile)
               throws java.io.FileNotFoundException,
                      java.io.IOException,
                      PdfKitException
Appends pages, which are chosen from portFile within the range from startPage to endPage, at the end of inputFile.

 [SampleCode]
 String inFile = "example1.pdf";
 String portFile = "example2.pdf";
 String outFile = "kitOut.pdf";
 int start = 1;
 int end = 3;
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.append(inFile, portFile, start, end, outFile);
 

Parameters:
inputFile - String Input Pdf file.
portFile - String Pages from Pdf file.
startPage - int Page starts in portFile.
endPage - int Page ends in portFile.
outputFile - String Output Pdf document.
Returns:
boolean - True for success, or false.
Throws:
java.io.FileNotFoundException
java.io.IOException
PdfKitException

extract

public boolean extract(java.io.InputStream inputStream,
                       int startPage,
                       int endPage,
                       java.io.OutputStream outputStream)
                throws java.io.IOException,
                       PdfKitException
Extracts pages from input file,saves as a new Pdf file.

Parameters:
inputStream - InputStream Input file Stream.
startPage - int Start page number.
endPage - int End page number.
outputStream - OutputStream Output Pdf file Stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

extract

public boolean extract(java.lang.String inputFile,
                       int startPage,
                       int endPage,
                       java.lang.String outputFile)
                throws java.io.IOException,
                       PdfKitException
Extracts pages from input file,saves as a new Pdf file.

Parameters:
inputFile - String Input Pdf file path.
startPage - int Start page number.
endPage - int End page number.
outputFile - String Output Pdf file path.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

extract

public boolean extract(java.lang.String inputFile,
                       int[] pageNumber,
                       java.lang.String outputFile)
                throws java.io.IOException,
                       PdfKitException
Extracts pages specified by number array, saves as a new Pdf file.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 int[] pages = new int[] {1, 2, 4, 10, 100};
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.extract(inFile, pages, outFile);
 

Parameters:
inputFile - String Input file path.
pageNumber - int[] Pages from the input file.
outputFile - String Output file path.
Returns:
boolean - True for successs, or false.
Throws:
java.io.IOException
PdfKitException

extract

public boolean extract(java.io.InputStream inputStream,
                       int[] pageNumber,
                       java.io.OutputStream outputStream)
                throws java.io.IOException,
                       PdfKitException
Extracts pages specified by number array, saves as a new Pdf file.

Parameters:
inputStream - InputStream Input file Stream.
pageNumber - int[] Pages from the input file.
outputStream - OutputStream Output file stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

splitFromFirst

public boolean splitFromFirst(java.lang.String inputFile,
                              int location,
                              java.lang.String outputFile)
                       throws java.io.IOException,
                              PdfKitException,
                              java.io.IOException
Splits from location,and saves the front part as a new file.

Parameters:
inputFile - String Source Pdf file.
location - int The splitting point.
outputFile - String Output Pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException
java.io.IOException

splitFromFirst

public boolean splitFromFirst(java.io.InputStream inputStream,
                              int location,
                              java.io.OutputStream outputStream)
                       throws java.io.IOException,
                              PdfKitException,
                              java.io.IOException
Splits from location,and saves the front part in output Stream.

 [SampleCode]
 String inFile = "example1.pdf";
 String outFile = "kitOut.pdf";
 int location = 3;
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.splitFromFirst(inFile, location, outFile);
 

Parameters:
inputStream - InputStream Source Pdf file Stream.
location - int The splitting point.
outputStream - OutputStream Output file Stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException
java.io.IOException

splitToEnd

public boolean splitToEnd(java.lang.String inputFile,
                          int location,
                          java.lang.String outputFile)
                   throws java.io.IOException,
                          PdfKitException,
                          java.io.IOException
Splits from location, and saves the rare part as a new file.

Parameters:
inputFile - String Source Pdf file.
location - int The splitting position.
outputFile - String Output Pdf file path.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException
java.io.IOException

splitToEnd

public boolean splitToEnd(java.io.InputStream inputStream,
                          int location,
                          java.io.OutputStream outputStream)
                   throws java.io.IOException,
                          PdfKitException
Splits from location, and saves the rare part as a new file Stream.

Parameters:
inputStream - InputStream Source Pdf file Stream.
location - int The splitting position.
outputStream - OutputStream Output Pdf file Stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

splitToPages

public java.io.ByteArrayOutputStream[] splitToPages(java.lang.String inputFile)
                                             throws PdfKitException,
                                                    java.io.IOException
Splits the Pdf file into single-page documents.

 [SampleCode]
 String inFile1 = "example1.pdf";
 PdfFileEditor pdfEditor = new PdfFileEditor();
 int fileNum = 0;
 ByteArrayOutputStream[] outBuffer = pdfEditor.splitToPages(inFile1);
 while(fileNum < outBuffer.length)
 {
 FileOutputStream outStream = new FileOutputStream(path + fileNum + ".pdf");
 outStream.write(outBuffer[fileNum].toByteArray());
 outStream.close();
 fileNum++;
 }
 

Parameters:
inputFile - String Input Pdf file name.
Returns:
ByteArrayOutputStream[] - Output Pdf streams,each stream buffers a single-page Pdf document.
Throws:
PdfKitException
java.io.IOException

splitToPages

public java.io.ByteArrayOutputStream[] splitToPages(java.io.InputStream inputStream)
                                             throws java.io.IOException,
                                                    PdfKitException
Splits the Pdf file into single-page documents.

Parameters:
inputStream - InputStream Input Pdf stream.
Returns:
ByteArrayOutputStream[] - Output Pdf streams,each stream buffers a single-page Pdf document.
Throws:
java.io.IOException
PdfKitException

insert

public boolean insert(java.lang.String inputFile,
                      int insertLocation,
                      java.lang.String portFile,
                      int startPage,
                      int endPage,
                      java.lang.String outputFile)
               throws PdfKitException,
                      java.io.IOException
Inserts pages from an other file into the Pdf file at a position.

Parameters:
inputFile - String Input Pdf file.
insertLocation - int Position in input file.
portFile - String The porting Pdf file.
startPage - int Start position in portFile.
endPage - int End position in portFile.
outputFile - String Output Pdf file.
Returns:
boolean - True for success, or false.
Throws:
PdfKitException
java.io.IOException

insert

public boolean insert(java.io.InputStream inputStream,
                      int insertLocation,
                      java.io.InputStream portStream,
                      int startPage,
                      int endPage,
                      java.io.OutputStream outputStream)
               throws PdfKitException,
                      java.io.IOException
Inserts pages from an other file into the input Pdf file.

Parameters:
inputStream - InputStream Input Stream of Pdf file.
insertLocation - int Insert position in input file.
portStream - InputStream Stream of Pdf file for pages.
startPage - int From which page to start.
endPage - int To which page to end.
outputStream - OutputStream Output Stream.
Returns:
boolean - True for success, or false.
Throws:
PdfKitException
java.io.IOException

insert

public boolean insert(java.lang.String inputFile,
                      int insertLocation,
                      java.lang.String portFile,
                      int[] pageNumber,
                      java.lang.String outputFile)
               throws java.io.IOException,
                      PdfKitException
Inserts pages from an other file into the input Pdf file.

 [SampleCode]
 String inFile = "example1.pdf";
 String portFile = "example2.pdf";
 String outFile = "kitOut.pdf";
 int location = 1;
 int[] pages = new int[] {1, 2, 3, 8};
 PdfFileEditor pdfEditor = new PdfFileEditor();
 pdfEditor.insert(inFile, location, portFile, pages, outFile);
 

Parameters:
inputFile - String Input Pdf file.
insertLocation - int Insert position in input file.
portFile - String Pages from the Pdf file.
pageNumber - int[] The page number of the ported in portFile.
outputFile - String Output Pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

insert

public boolean insert(java.io.InputStream inputStream,
                      int insertLocation,
                      java.io.InputStream portStream,
                      int[] pageNumber,
                      java.io.OutputStream outputStream)
               throws java.io.IOException,
                      PdfKitException
Inserts pages from an other file into the input Pdf file.

Parameters:
inputStream - InputStream Input Stream of Pdf file.
insertLocation - int Insert position in input file.
portStream - InputStream Stream of Pdf file for pages.
pageNumber - int[] The page number of the ported in portFile.
outputStream - OutputStream Output Stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeNUp

public boolean makeNUp(java.lang.String inputFile,
                       java.lang.String outputFile,
                       int x,
                       int y)
                throws java.io.IOException,
                       PdfKitException
Makes N-Up document from the inputFile to outputFile.

Parameters:
inputFile - Input pdf file path and name.
outputFile - Output pdf file path and name.
x - The page number in landscape orientation.
y - The page number in portrait orientation.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeNUp

public boolean makeNUp(java.io.InputStream inputStream,
                       java.io.OutputStream outputStream,
                       int x,
                       int y)
                throws java.io.IOException,
                       PdfKitException
Makes N-Up document from the inputStream to outputStream.

Parameters:
inputStream - Input pdf stream.
outputStream - Output pdf stream.
x - The page number int landscape orientation.
y - The page number int portrait orientation.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeNUp

public boolean makeNUp(java.lang.String inputFile,
                       java.lang.String outputFile,
                       int x,
                       int y,
                       PageSize pageSize)
                throws java.io.IOException,
                       PdfKitException
Makes N-Up document from the inputFile to outputFile.

Parameters:
inputFile - Input pdf file path and name.
outputFile - Output pdf file path and name.
x - The page number in landscape orientation.
y - The page number in portrait orientation.
pageSize - The page size of the output pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeNUp

public boolean makeNUp(java.io.InputStream inputStream,
                       java.io.OutputStream outputStream,
                       int x,
                       int y,
                       PageSize pageSize)
                throws java.io.IOException,
                       PdfKitException
Makes N-Up document from the inputStream to outputStream.

Parameters:
inputStream - Input pdf stream.
outputStream - Output pdf stream.
x - The page number in landscape orientation.
y - The page number in portrait orientation.
pageSize - The page size of the output pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeBooklet

public boolean makeBooklet(java.lang.String inputFile,
                           java.lang.String outputFile)
                    throws java.io.IOException,
                           PdfKitException
Makes booklet from the inputFile to outputFile.

Parameters:
inputFile - Input pdf file path and name.
outputFile - Output pdf file path and name.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeBooklet

public boolean makeBooklet(java.io.InputStream inputStream,
                           java.io.OutputStream outputStream)
                    throws java.io.IOException,
                           PdfKitException
Makes booklet from the inputStream to outputStream.

Parameters:
inputStream - Input pdf stream.
outputStream - output pdf stream.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeBooklet

public boolean makeBooklet(java.lang.String inputFile,
                           java.lang.String outputFile,
                           PageSize pageSize)
                    throws java.io.IOException,
                           PdfKitException
Makes booklet from the inputFile to outputFile.

Parameters:
inputFile - Input pdf file path and name.
outputFile - Output pdf file path and name.
pageSize - The page size of the output pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException

makeBooklet

public boolean makeBooklet(java.io.InputStream inputStream,
                           java.io.OutputStream outputStream,
                           PageSize pageSize)
                    throws java.io.IOException,
                           PdfKitException
Makes booklet from the inputStream to outputStream.

Parameters:
inputStream - Input pdf stream.
outputStream - output pdf stream.
pageSize - The page size of the output pdf file.
Returns:
boolean - True for success, or false.
Throws:
java.io.IOException
PdfKitException