com.aspose.pdf.facades

Class PdfConverter

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IFacade


    public final class PdfConverter
    extends Facade

    Represents a class to convert a pdf file's each page to images, supporting BMP, JPEG, PNG and TIFF now. Supported content in pdfs: pictures, form, comment.

    • Constructor Detail

      • PdfConverter

        public PdfConverter()

        Initializes new PdfConverter object.

      • PdfConverter

        public PdfConverter(IDocument document)

        Initializes new PdfConverter object on base of the document.

        Parameters:
        document - Pdf document.
    • Method Detail

      • getCoordinateType

        public int getCoordinateType()

        Gets the page coordinate type (Media/Crop boxes). CropBox value is used by default.

        Returns:
        PageCoordinateType element
        See Also:
        PageCoordinateType
      • setCoordinateType

        public void setCoordinateType(int value)

        Sets the page coordinate type (Media/Crop boxes). CropBox value is used by default.

        Parameters:
        value - PageCoordinateType element
        See Also:
        PageCoordinateType
      • isShowHiddenAreas

        @Deprecated
        public boolean isShowHiddenAreas()
        Deprecated. 

        Gets flag that controls visibility of hidden areas on the page. Method is Deprecated.

        Returns:
        boolean value
      • setShowHiddenAreas

        @Deprecated
        public void setShowHiddenAreas(boolean value)
        Deprecated. 
      • getRenderingOptions

        public RenderingOptions getRenderingOptions()

        Gets rendering options.

        Returns:
        rendering options.
      • setRenderingOptions

        public void setRenderingOptions(RenderingOptions value)

        Sets rendering options.

        Parameters:
        value - rendering options.
      • getFormPresentationMode

        public int getFormPresentationMode()

        Gets form presentation mode.

        Returns:
        form presentation mode.
        See Also:
        FormPresentationMode
      • setFormPresentationMode

        public void setFormPresentationMode(int value)

        Sets form presentation mode.

        Parameters:
        value - form presentation mode.
        See Also:
        FormPresentationMode
      • getResolution

        public Resolution getResolution()

        Gets resolution during converting. The higher resolution, the slower converting speed. The default value is 150.

        Returns:
        Resolution element
      • setResolution

        public void setResolution(Resolution value)

        Sets resolution during converting. The higher resolution, the slower converting speed. The default value is 150.

        Parameters:
        value - Resolution element
      • getStartPage

        public int getStartPage()

        Gets start position which you want to convert. The minimal value is 1.

        Returns:
        int value
      • setStartPage

        public void setStartPage(int value)

        Sets start position which you want to convert. The minimal value is 1.
        use setEndPage(int) before setStartPage(int)

        Parameters:
        value - int value
      • getEndPage

        public int getEndPage()

        Gets end position which you want to convert.

        Returns:
        int value
      • setEndPage

        public void setEndPage(int value)

        Sets end position which you want to convert.
        use setEndPage(int) before setStartPage(int)

        Parameters:
        value - int value
      • setRangeOfPages

        public void setRangeOfPages(int startPage,
                                    int EndPage)

        Sets range of pages between of which you want to convert.

        Parameters:
        startPage - int value
        EndPage - int value
      • getPassword

        public String getPassword()

        Gets document OwnerPassword.

        Returns:
        String value
      • setPassword

        public void setPassword(String value)

        Sets document OwnerPassword.

        Parameters:
        value - String value
      • getUserPassword

        public String getUserPassword()

        Gets document UserPassword.

        Returns:
        String value
      • setUserPassword

        public void setUserPassword(String value)

        Sets document UserPassword.

        Parameters:
        value - String value
      • getPageCount

        public int getPageCount()

        Gets the page count.

        Returns:
        int value
      • doConvert

        public void doConvert()

        Do some initial works for converting a pdf document to images.


         
         
          PdfConverter converter = new PdfConverter();
          converter.bindPdf("D:\\Test\\test.pdf");
          converter.doConvert();
          String prefix = "D:\\Test\\";
          String suffix = ".jpg";
          int imageCount = 1;
          while (converter.hasNextImage())
          {
                converter.getNextImage(prefix + imageCount + suffix);
                imageCount++;
          }
                
                
          
      • saveAsTIFF

        public void saveAsTIFF(String outputFile)

        Converts each pages of a pdf document to images and saves images to a single TIFF file.


          PdfConverter converter = new PdfConverter();
          converter.bindPdf(@"D:\Test\test.pdf");
          converter.doConvert();
          converter.saveAsTIFF(@"D:\Test\test.tiff");   
          
        Parameters:
        outputFile - The file to save the TIFF image.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               int compressionType)

        Converts each pages of a pdf document to images and saves images to a single TIFF file.


         PdfConverter converter = new PdfConverter();
         converter.bindPdf(@"D:\Test\test.pdf");
         converter.doConvert();
         converter.saveAsTIFF(@"D:\Test\test.tiff");
         
        Parameters:
        outputFile - The output file.
        compressionType - Type of the compression.
        See Also:
        CompressionType
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               int imageWidth,
                               int imageHeight)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               PageSize pageSize)

        Converts each pages of a pdf document to images with page size and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        pageSize - The page size of the image.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               PageSize pageSize,
                               TiffSettings settings)

        Converts each pages of a pdf document to images with page size and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        pageSize - The page size of the image.
        settings - Settings object that defines TIFF parameters.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               int imageWidth,
                               int imageHeight,
                               int compressionType)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        compressionType - Type of the compression.
        See Also:
        CompressionType
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               int imageWidth,
                               int imageHeight,
                               TiffSettings settings)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        settings - Settings object that defines TIFF parameters.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               int imageWidth,
                               int imageHeight,
                               TiffSettings settings,
                               IIndexBitmapConverter converter)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        settings - Settings object that defines TIFF parameters.
        converter - External converter
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(String outputFile,
                                     int imageWidth,
                                     int imageHeight)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF file.


          PdfConverter converter = new PdfConverter();
          converter.bindPdf(@"D:\Test\test.pdf");
          converter.doConvert();
          converter.saveAsTIFFClassF(@"D:\Test\test.tiff",204,196);     
          
        Parameters:
        outputFile - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(String outputFile,
                                     PageSize pageSize)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF file.

        Parameters:
        outputFile - The stream to save the TIFF image.
        pageSize - The page size of the image.
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(OutputStream outputStream,
                                     int imageWidth,
                                     int imageHeight)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(OutputStream outputStream,
                                     PageSize pageSize)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        pageSize - The page size of the image.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream)

        Converts each pages of a pdf document to images and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               int compressionType)

        Converts each pages of a pdf document to images and saves images to a single TIFF file.

        Parameters:
        outputStream - The output stream.
        compressionType - Type of the compression.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               PageSize pageSize)

        Converts each pages of a pdf document to images with page size and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        pageSize - The page size of the image.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               PageSize pageSize,
                               TiffSettings settings)

        Converts each pages of a pdf document to images with page size and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        pageSize - The page size of the image.
        settings - Settings object that defines TIFF parameters.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               int imageWidth,
                               int imageHeight)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               int imageWidth,
                               int imageHeight,
                               int compressionType)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        compressionType - Type of the compression.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               int imageWidth,
                               int imageHeight,
                               TiffSettings settings)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        settings - Settings object that defines TIFF parameters.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               int imageWidth,
                               int imageHeight,
                               TiffSettings settings,
                               IIndexBitmapConverter converter)

        Converts each pages of a pdf document to images with dimensions, and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        settings - Settings object that defines TIFF parameters.
        converter - External converter
      • hasNextImage

        public boolean hasNextImage()

        Indicates whether the pdf file has more images or not.

        Returns:
        Can get more images or not, true if can, or false.
      • getNextImage

        public void getNextImage(String outputFile)

        Saves image to file with default image format - jpeg.

        Parameters:
        outputFile - The file path and name to save the image.
      • getNextImage

        public void getNextImage(String outputFile,
                                 PageSize pageSize)

        Saves image to file with ith given page size and default image format - jpeg.

        Parameters:
        outputFile - The file path and name to save the image.
        pageSize - The page size of the image.
      • convertPageToPNGMemoryStream

        public com.aspose.ms.System.IO.MemoryStream convertPageToPNGMemoryStream(Page page)
        For internal usage only
        Parameters:
        page - Internal object
        Returns:
        Internal object
      • getNextImage

        public void getNextImage(String outputFile,
                                 ImageType format)

        Saves image to file with the givin image format.


         
          PdfConverter converter = new PdfConverter();
          converter.bindPdf(@"D:\Test\test.pdf");
          converter.DoConvert();
          String prefix = @"D:\Test\";
          String suffix = ".png";
          int imageCount = 1;
          while (converter.HasNextImage())
          {
                converter.getNextImage(prefix + imageCount + suffix, ImageFormat.Png);
                imageCount++;
          }
          
        Parameters:
        outputFile - The file path and name to save the image.
        format - The format of the image.
      • getNextImage

        public void getNextImage(String outputFile,
                                 PageSize pageSize,
                                 ImageType format)

        Saves image to file with given page size and image format.

        Parameters:
        outputFile - The file path and name to save the image.
        pageSize - The page size of the image.
        format - The format of the image.
      • getNextImage

        public void getNextImage(OutputStream outputStream)

        Saves image to stream with default image format - jpeg.

        Parameters:
        outputStream - The stream to save the image.
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 PageSize pageSize)

        Saves image to stream with given page size.

        Parameters:
        outputStream - The stream to save the image.
        pageSize - The page size of the image.
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 ImageType format)

        Saves image to stream with given image format.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 PageSize pageSize,
                                 ImageType format)

        Saves image to stream with given page size.

        Parameters:
        outputStream - The stream to save the image.
        pageSize - The page size of the image.
        format - The format of the image.
      • getNextImage

        public void getNextImage(String outputFile,
                                 ImageType format,
                                 int imageWidth,
                                 int imageHeight,
                                 int quality)

        Saves image to file with the given image format, dimensions and quality.


          PdfConverter converter = new PdfConverter();
          converter.bindPdf(@"D:\Test\test.pdf");
          converter.doConvert();
          String prefix = @"D:\Test\";
          String suffix = ".jpg";
          int imageCount = 1;
          while (converter.HasNextImage())
          {
                converter.getNextImage(prefix + imageCount + suffix, ImageFormat.Jpeg, 800, 1000, 50);
                imageCount++;
          }
          
        Parameters:
        outputFile - The file path and name to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 ImageType format,
                                 int imageWidth,
                                 int imageHeight,
                                 int quality)

        Saves image to stream with the givin image format, dimensions and quality.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • getNextImage

        public void getNextImage(String outputFile,
                                 ImageType format,
                                 double imageWidth,
                                 double imageHeight,
                                 int quality)

        Saves image to file with the givin image format, image size, and quality.


          PdfConverter converter = new PdfConverter();
          converter.bindPdf(@"D:\Test\test.pdf");
          converter.doConvert();
          String prefix = @"D:\Test\";
          String suffix = ".jpg";
          int imageCount = 1;
          float pixelX=800f;
          float pixelY=600f;
          while (converter.HasNextImage())
          {
                converter.getNextImage(prefix + imageCount + suffix, ImageFormat.Jpeg, pixelX, pixelY, 50);
                imageCount++;
          }
          
        Parameters:
        outputFile - The file path and name to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixels.
        imageHeight - The image height, the unit is pixels..
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 ImageType format,
                                 double imageWidth,
                                 double imageHeight,
                                 int quality)

        Saves image to stream with the givin image format, size and quality.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • bindPdf

        public void bindPdf(String inputFile)

        Binds a Pdf file for converting.

        Specified by:
        bindPdf in interface IFacade
        Overrides:
        bindPdf in class Facade
        Parameters:
        inputFile - The pdf file.
      • bindPdf

        public void bindPdf(InputStream inputStream)

        Binds a Pdf Stream for convert.

        Specified by:
        bindPdf in interface IFacade
        Overrides:
        bindPdf in class Facade
        Parameters:
        inputStream - The pdf Stream.
      • close

        public void close()

        Close the instance of PdfConverter and release the resources.

        Specified by:
        close in interface IFacade
        Overrides:
        close in class Facade
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(String outputFile)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF file.


         
         
          PdfConverter converter = new PdfConverter();
          converter.bindPdf("D:\\Test\\test.pdf");
          converter.doConvert();
          converter.saveAsTIFFClassF("D:\\Test\\test.tiff");    
          
        Parameters:
        outputFile - The stream to save the TIFF image.
      • saveAsTIFFClassF

        public void saveAsTIFFClassF(OutputStream outputStream)

        Converts each pages of a pdf document to images and save images to a single TIFF ClassF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               TiffSettings settings)

        Converts each pages of a pdf document to images with and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        settings - Settings.
      • saveAsTIFF

        public void saveAsTIFF(String outputFile,
                               TiffSettings settings,
                               IIndexBitmapConverter converter)

        Converts each pages of a pdf document to images with and saves images to a single TIFF file.

        Parameters:
        outputFile - The file name to save the TIFF image
        settings - Settings.
        converter - External converter
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               TiffSettings settings)

        Converts each pages of a pdf document to images and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        settings - Settings object that defines TIFF parameters.
      • saveAsTIFF

        public void saveAsTIFF(OutputStream outputStream,
                               TiffSettings settings,
                               IIndexBitmapConverter converter)

        Converts each pages of a pdf document to images and saves images to a single TIFF stream.

        Parameters:
        outputStream - The stream to save the TIFF image.
        settings - Settings object that defines TIFF parameters.
        converter - External converter
      • getNextImage

        public void getNextImage(String outputFile,
                                 ImageType format,
                                 int imageWidth,
                                 int imageHeight)

        Saves image to file with the given image format and dimensions.


         
         
          PdfConverter converter = new PdfConverter();
          converter.bindPdf("D:\\Test\\test.pdf");
          converter.DoConvert();
          String prefix = "D:\\Test\\";
          String suffix = ".jpg";
          int imageCount = 1;
          while (converter.hasNextImage())
          {
                converter.getNextImage(prefix + imageCount + suffix, ImageFormat.Jpeg, 800, 1000);
                imageCount++;
          }
          
        Parameters:
        outputFile - The file path and name to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 ImageType format,
                                 int imageWidth,
                                 int imageHeight)

        Saves image to stream with the givin image format, size and quality.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
        imageWidth - The image width, the unit is pixel.
        imageHeight - The image height, the unit is pixel.
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 ImageType format,
                                 int quality)

        Saves image to stream with given image format and quality.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
        See Also:
        ImageType
      • getNextImage

        public void getNextImage(OutputStream outputStream,
                                 PageSize pageSize,
                                 ImageType format,
                                 int quality)

        Saves image to stream with given page size, image format and quality.

        Parameters:
        outputStream - The stream to save the image.
        format - The format of the image.
        pageSize - The page size of the image.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • getNextImage

        public void getNextImage(String outputFile,
                                 ImageType format,
                                 int quality)

        Saves image to file with given image format and quality.

        Parameters:
        outputFile - The file path and name to save the image.
        format - The format of the image.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • getNextImage

        public void getNextImage(String outputFile,
                                 PageSize pageSize,
                                 ImageType format,
                                 int quality)

        Saves image to file with given page size, image format and quality.

        Parameters:
        outputFile - The file path and name to save the image.
        pageSize - The page size of the image.
        format - The format of the image.
        quality - The Jpeg file's quality (0~100), 0 is lowest and 100 is highest
      • dispose

        public void dispose()

        Close the instance of PdfConverter and release the resources.

        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable
        Overrides:
        dispose in class Facade