Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class PdfConverter

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

public class PdfConverter
extends java.lang.Object

Represents a class to transform each page to image file from pdf file, support BMP, JPEG, PNG and TIFF now.


Constructor Summary
PdfConverter()
          The constructor of the PdfConverter object.
 
Method Summary
 void bindPdf(java.io.InputStream inputStream)
          Binds a Pdf Stream for converting.
 void bindPdf(java.lang.String inputFile)
          Binds a Pdf file for converting.
 void doConvert()
          Begins to transform a Pdf document to image files.
 int getEndPage()
          Gets endPage value.
 void getNextImage(java.io.OutputStream outputStream)
          Saves next page's image to stream with default image type - Jpeg.
 void getNextImage(java.io.OutputStream outputStream, ImageType imageType)
          Saves next page's image to stream with the given image type.
 void getNextImage(java.lang.String outputFile)
          Saves next page's image to file with default image type - Jpeg.
 void getNextImage(java.lang.String outputFile, ImageType imageType)
          Saves next page's image to file with the given image type.
 java.lang.String getPassword()
          Gets password.
 int getStartPage()
          Gets startPage value.
 boolean hasNextImage()
          Judges if it can get more images or not.
 void savaAsTIFF(java.io.OutputStream outputStream)
          save each page's image to a single TIFF stream.
 void savaAsTIFF(java.lang.String outputFile)
          save each page's image to a single TIFF file.
 void setEndPage(int endPage)
          Sets endPage value.
 void setPassword(java.lang.String password)
          Sets password, use this password to decrypt the pdf file.
 void setStartPage(int startPage)
          Sets startPage value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfConverter

public PdfConverter()
The constructor of the PdfConverter object.

Method Detail

setStartPage

public void setStartPage(int startPage)
Sets startPage value.

Parameters:
startPage - start position which you want to convert of the pdf file.

getStartPage

public int getStartPage()
Gets startPage value.

Returns:
start position which you want to convert of the pdf file.

setEndPage

public void setEndPage(int endPage)
Sets endPage value.

Parameters:
endPage - end position which you want to convert of the pdf file.

getEndPage

public int getEndPage()
Gets endPage value.

Returns:
end position which you want to convert of the pdf file.

setPassword

public void setPassword(java.lang.String password)
Sets password, use this password to decrypt the pdf file.

Parameters:
password - the input pdf file's password

getPassword

public java.lang.String getPassword()
Gets password.

Returns:
the input pdf file's password has set.

bindPdf

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

Parameters:
inputFile - The pdf file to be convertted.
Throws:
java.io.FileNotFoundException

bindPdf

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

Parameters:
inputStream - The pdf Stream to be convertted.
Throws:
java.io.FileNotFoundException

doConvert

public void doConvert()
               throws java.lang.Exception
Begins to transform a Pdf document to image files.

 [SampleCode]
 //convert each page to images with the default image format(JPEG)
 String path = "./examples/resources/";
 PdfConverter converter = new PdfConverter();
 converter.bindPdf(path + "text.pdf");
 converter.doConvert();
 String suffix = ".jpg";
 int imageCount = 1;
 while (converter.hasNextImage()) {
     converter.getNextImage(path + imageCount + suffix);
     imageCount++;
 }
 

Throws:
java.lang.Exception

getNextImage

public void getNextImage(java.lang.String outputFile)
                  throws java.lang.Exception
Saves next page's image to file with default image type - Jpeg.

Parameters:
outputFile - The file path and name to save the image.
Throws:
java.lang.Exception

getNextImage

public void getNextImage(java.io.OutputStream outputStream)
                  throws java.lang.Exception
Saves next page's image to stream with default image type - Jpeg.

Parameters:
outputStream - The stream to save the image.
Throws:
java.lang.Exception

getNextImage

public void getNextImage(java.lang.String outputFile,
                         ImageType imageType)
                  throws java.lang.Exception
Saves next page's image to file with the given image type.

Parameters:
outputFile - The file path and name to save the image.
imageType - The given image type.
Throws:
java.lang.Exception

getNextImage

public void getNextImage(java.io.OutputStream outputStream,
                         ImageType imageType)
                  throws java.lang.Exception
Saves next page's image to stream with the given image type.

 [SampleCode]
 //convert each page to images with the givin image format(PNG)
 String path = "./examples/resources/";
 PdfConverter converter = new PdfConverter();
 converter.bindPdf(path + "text.pdf");
 converter.doConvert();
 String suffix = ".png";
 int imageCount = 1;
 while (converter.hasNextImage()) {
     converter.getNextImage(path + imageCount + suffix, ImageType.PNG);
     imageCount++;
 }
 

Parameters:
outputStream - The stream to save the image.
imageType - The given image type.
Throws:
java.lang.Exception

hasNextImage

public boolean hasNextImage()
Judges if it can get more images or not. True is can and false is can't.

Returns:
can get more images or not.

savaAsTIFF

public void savaAsTIFF(java.lang.String outputFile)
                throws java.lang.Exception
save each page's image to a single TIFF file.

 [SampleCode]
 //convert a pdf file to a single TIFF file
 String path = "./examples/resources/";
 try {
 	PdfConverter converter = new PdfConverter();
 	converter.bindPdf(path + "text.pdf");
 	converter.doConvert();
 	converter.savaAsTIFF(path + "text.tif");
 }
 catch (java.io.IOException ioe) {
 	System.out.println(ioe.getMessage() + ioe.getStackTrace());
 }
 

Parameters:
outputFile - The file path and name to save the image.
Throws:
java.lang.Exception

savaAsTIFF

public void savaAsTIFF(java.io.OutputStream outputStream)
                throws java.lang.Exception
save each page's image to a single TIFF stream.

Parameters:
outputStream - The stream to save the tiff image.
Throws:
java.lang.Exception