Convert PDF Page to Image

Convert PDF Pages to TIFF Image

The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named process(..) which allows you to convert one or all pages of a PDF file to TIFF images.

Convert One Page to TIFF

To convert one page in a PDF document to a TIFF image:

  1. Create an object of the Document class to load the source PDF file that you want to convert.
  2. Call the process(..) method to convert the page to TIFF.

The following code snippet shows how to convert a particular page to a TIFF image.

Convert All PDF Pages to TIFF Images

To convert all pages in a PDF file to TIFF format, use the following overload of the process(..) method.

Convert PDF Pages to Pixelated TIFF Images

To convert all pages in a PDF file to Pixelated TIFF format, use Pixelated option of IndexedConversionType.

Java

 //Open document

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Input.pdf");

//Create stream object to save the output image

java.io.OutputStream imageStream = new java.io.FileOutputStream("Image.tiff");

//Create Resolution object

com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);

//instantiate TiffSettings object

com.aspose.pdf.devices.TiffSettings tiffSettings  = new com.aspose.pdf.devices.TiffSettings();

//set the compression of resultant TIFF image

tiffSettings.setCompression(com.aspose.pdf.devices.CompressionType.CCITT4);

//set the color depth for resultant image

tiffSettings.setDepth(com.aspose.pdf.devices.ColorDepth.Format4bpp);

//skip blank pages while rendering PDF to TIFF

tiffSettings.setSkipBlankPages(true);

//set image brightness

//tiffSettings.setBrightness(.5f);

//set IndexedConversion Type, default value is simple

tiffSettings.setIndexedConversionType(IndexedConversionType.Pixelated);

//Create TiffDevice object with particular resolution

com.aspose.pdf.devices.TiffDevice   tiffDevice = new com.aspose.pdf.devices.TiffDevice(2480, 3508,resolution,tiffSettings);

//Convert a particular page (Page 1) and save the image to stream

tiffDevice.process(pdfDocument,1,1,imageStream);

//Close the stream

imageStream.close();

Convert PDF Pages to JPEG Image

The JpegDevice class allows you to convert PDF pages to JPEG images. This class provides a method named process(..) which allows you to convert a particular page of the PDF file to JPEG image.

Convert All Pages to JPEG Images

To convert all pages in a PDF file to JPEG format, iterate through the individual pages and convert each one.

The following code snippet shows you how to traverse through all the pages of PDF file and convert it to JPEG image.

Convert One PDF Page to JPEG Image

To convert just one page to a JPEG image:

  1. Create an object of the Document class to get the page you want to convert.
  2. Call the process(..) method to convert the page to a JPEG image.

The following code snippet shows you how to convert particular page to JPEG image.

Convert PDF Pages to PNG Images

The PngDevice class allows you to convert PDF pages to PNG images. This class provides a method named process(..) which allows you to convert a particular page to PNG image.

Convert All PDF Pages to PNG Images

To convert all pages in a PDF file to PNG files, iterate through the individual pages and convert each to PNG format. The following code snippet shows how to traverse through all the pages of a PDF file and convert each to a PNG image.

Convert One Page to PNG Image

To convert one page in a PDF document to a PNG image:

  1. Create an object of the Document class to get the particular page you want to convert.
  2. Call the process(..) method to convert the page to PNG image.

The following code snippet shows you how to convert particular page to PNG image.

Convert PDF Pages to BMP Image

The BmpDevice class allows you to convert PDF pages to BMP images. This class provides a method named process(..) which allows you to convert a particular page of the PDF file to BMP image.

Convert a PDF Page to BMP Image

To convert a PDF page to a BMP image:

  1. Create an object of the Document class, to get the particular page you want to convert.
  2. Call the process(..) method to convert the page to BMP.

The following code snippet shows you how to convert particular page to BMP image.

Convert All PDF Pages to BMP Images

To convert all page of PDF file to BMP format, you need to iterate through to get each individual page and convert it to BMP format. The following code snippet shows you how to traverse through all the pages of a PDF file and convert it to BMP.

Convert a particular page region to Image (DOM)

We can convert PDF documents to different Image formats using image devices objects of Aspose.PDF. However sometimes there is a requirement to convert particular page region into Image format. We can fulfill this requirement in two steps. Initially crop the PDF page to desired region and later convert it to image using desired Image device object.

The following code snippet shows you how to convert PDF pages to images.