Convert PDF Pages

Convert PDF Pages to JPEG Images

The JpegDevice class allows you to convert PDF pages to JPEG images. This class provides a method named Process which allows you to convert pages of PDF file to JPEG image.

Converting All Pages to JPEG Images

To convert all pages in a PDF document to images:

  1. Loop through all pages of the PDF and convert each page individually:
    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 JPEG image.

The following code snippet shows you how to convert all pages in a file to JPEG images.

Converting One Page

To convert a particular page, there is no need to iterate through all the pages. Simply provide the index of the page you want to convert:

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 of the PDF file to PNG image.

Convert All Pages to PNG Images

Try online

You can check the quality of Aspose.PDF conversion and view the results online at this link:

products.aspose.app/pdf/conversion/pdf-to-png

To convert all pages in a PDF document to images:

  1. Loop through all pages in the PDF and then convert each page individually:
    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 PNG.

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

Convert One Page

To convert a particular page, there is no need to iterate through all PDF pages. Simply provide the index of the page you want to convert.

Set UseFontHinting while converting PDF to PNG

Aspose.Pdf.RenderingOptions class has a property UseFontHinting of type boolean, which can be used to turn on the font hinting mechanism. Font hinting is basically the use of mathematical instructions to adjust the display of an outline font. In some cases, turning this flag on may solve problems with text legibility. For now, usage of this flag could give effect only for TTF fonts, if these fonts are using in source document. Following code snippet shows the usage of UseFontHinting property:

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 all the pages in a PDF file to a single TIFF image.

Convert All Pages to One TIFF Image

To convert all pages in a PDF file to a single TIFF image:

  1. Create an object of the Document class.
  2. Call the Process method to convert the document.
  3. To set the output file’s properties, use the TiffSettings class.

The following code snippet shows how to convert all the PDF pages to a single TIFF image.

To save the output TIFF to specific page size, use the overloaded TiffDevice constructor with the Aspose.PDF.Facades.PageSize class. Predefined page sizes are available, for example, A4, A3, and Letter.

Convert One Page to TIFF Image

To convert a particular page in a PDF file to a TIFF image, use an overloaded version of the Process(..) method which takes a page number as an argument for conversion. The following code snippet shows how to convert the first page of a PDF to TIFF format.

Use Bradley algorithm during conversion

Aspose.PDF for .NET has been supporting the feature to convert PDF to TIF using LZW compression and then with the use of AForge, Binarization can be applied. However one of the customers requested that for some images, they need to get the Threshold using Otsu, so they also would like to use Bradley.

Convert PDF Pages to EMF Image

The EmfDevice class allows you to convert PDF pages to EMF images. This class provides a method named Process which allows you to convert a particular page of the PDF file to EMF image format.

Convert All Pages to EMF Images

To convert all pages in a PDF file to images:

  1. Loop through all pages in the file.
  2. Convert each page individually:
    1. Create an object of the Document class to load the PDF document.
    2. Get the page you want to convert.
    3. Call the Process method to convert the page to EMF.

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

Convert One PDF Page to EMF

To convert a particular page to EMF format:

  1. Pass the page index as an argument to the Process(..) method.

The following code snippet shows the steps to convert the first page of PDF to EMF format.

Convert an Image to PDF

Images are often used to clarify or illustrate data and are often shared between colleagues. Sharing images in PDF format is a convenient way to ensure that everyone can view them. To this end, Aspose.PDF for .NET supports converting images to PDF. The following table shows the image formats that Aspose.PDF can convert to PDF.

Image File TypesDescription
CCITTCCITT is a lossless image compression method used in Group 4 fax machines. It is used for black and white images only.
GIFGraphics Interchange Format, a bitmap image format frequently used on the web, uses lossless compression.
JPEGJoint Photographic Experts Group is a lossy compression method for digital images, developed for use with digital photography.
PNGPortable Network Graphics is an improved, non-patented replacement for GIF and is a popular lossless image compression format used on the web.
TIFFTagged Image File Format is a file format for storing raster graphics. It is widely used in word processing and digital image manipulation applications.
BMPThe bitmap file format is a raster graphics image format used to store digital images. It is created to be device-independent.
EMFEnhanced Meta File is a 32-bit version of Microsoft’s Windows Meta File format.
ExifExchangeable Image File format specifies formats for images, sound and other tags used by digital cameras, smartphones and other devices.
IconICO files are files that hold icons – pictograms representing actions, for example – for computer interfaces.
WMFWindows Meta File is a device-independent image format aimed to take both vector and raster graphics.
MemoryBmpMemoryBmp type
UnknownUnknown file type.

Aspose.PDF Image Approach

A PDF document comprises pages and each page contains one or more paragraph objects. A paragraph can be a text, image, table, floating box, graph, heading, form field or an attachment. To convert an image file into PDF format, enclose it in a paragraph.

It is possible to convert images at a physical location on the local hard drive, found at a web URL or in a MemoryStream. To add an image:

  1. Create an object of the Image class.
  2. Add the image to a page’s Paragraphs collection.
  3. Specify the file’s path or source.
    1. If an image is at a location on the hard drive, specify the path location using the Image.File property.
  4. If an image is placed in a MemoryStream, pass the object holding the image to the Image.ImageStream property.

The following code snippet shows how to load an image object, get its dimensions, set the page dimensions according to image dimensions, place the image on a page in a PDF file and save the output as PDF.

Convert PDF Pages to BMP Images

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.

To convert a page to an image:

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

To convert all pages in a document to images, loop through the pages of the PDF and convert each page individually. The following code snippet shows how to convert all PDF pages to BMP images.

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 a particular page region into Image format. We can fulfill this requirement in two steps. Initially crop the PDF page to the desired region and later convert it to image using the desired Image device object.

Following code demonstrates how to convert a particular page region to PNG using PNGDevice.

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