Overview
The DynamicPDF Rasterizer is DynamicPDF's product designed specifically for converting PDF documents into images. It support JPEG, BMP, PNG, GIF, and TIFF image formats.
The DynamicPDF Rasterizer creates rasterized images (JPEG, BMP, PNG, GIF, TIFF) from a PDF document.
If you need to convert these or other file formats to PDF then review DynamicPDF's DynamicPDF Converter product rather than DynamicPDF Rasterizer.
- DynamicPDF Rasterizer: PDF ---- to ----> Images
- DynamicPDF Core Suite: Images --- to ---> PDFs
- DynamicPDF Converter: Images --- to ---> PDFs
PdfRasterizer Class
The PdfRasterizer class is the class provided by the DynamicPdf Rasterizer for rasterizing PDF documents into images.
PdfRasterizer
has four constructors and three properties: BackgroundColor, CachePages, and Pages. The class has fifteen methods, including methods for appending PDFs to a PdfRasterizer
instance and drawing the rasterized PDF to an in image.
The PdfRasterizer
has five methods for outputting a rasterized PDF to an image. It has two overloads methods for outputting a rasterized PDF and three method overloads for drawing a rasterized PDF to a multi-page TIFF.
- Draw(ImageFormat, ImageSize)
- Draw(String, ImageFormat, ImageSize)
- DrawToMultiPageTiff(Stream, TiffImageFormat, ImageSize)
- DrawToMultiPageTiff(String, TiffImageFormat, ImageSize)
- DrawToMultiPageTiff(TiffImageFormat, ImageSize).
Examples
The following two examples illustrate using the PdfRasterizer
class to create a PNG from a single-page PDF document, followed by an example illustrating how to create a multi-page TIFF from a three page PDF document.
Using DynamicPDF Rasterizer
The following lists the most common flow for writing applications that use DynamicPDF Rasterizer.
- Specify the PDF Input File. Create a PdfRasterizer instance and specify the PDF's input file path in the constructor.
- Define the Output Image Format and Output Image Size. Note that defining an ImageFormat object specifies the image type (JPEG, BMP, PNG, GIF, TIFF) while defining an ImageSize object specifies the output image size.
- Specify the Output File Name and Location. Finally, specify the file name and location of the output file.
Multi-page PDF documents can output multiple image files. Refer to Output File Names for more information and examples.
PNG Example
The following example takes a single-page PDF and produces a single PNG.
PdfRasterizer rasterizer = new PdfRasterizer("single-page.pdf");
rasterizer.Draw("single-page-pdf-to-png-output.png", ImageFormat.Png, ImageSize.Dpi300);
Dim rasterizer As New PdfRasterizer("single-page.pdf")
rasterizer.Draw("single-page-pdf-to-png-output.png", ImageFormat.Png, ImageSize.Dpi300)
TIFF Example
The following example takes a two-page PDF and produces two TIFF images as separate images (pdf-to-tiff-one-output.tif
and pdf-to-tiff-one-output2.tif
).
See Output File Name for more information on file naming convention when creating multiple images from a PDF.
PdfRasterizer rasterizer = new PdfRasterizer("DocumentA.pdf");
rasterizer.Draw("pdf-to-tiff-one-output.tif", ImageFormat.TiffWithLzw, ImageSize.Dpi150);
Dim rasterizer As New PdfRasterizer("single-page.pdf")
rasterizer.Draw("single-page-pdf-to-png-output.png"), ImageFormat.Png, ImageSize.Dpi300)
Multi-Page TIFF Example
The following example uses the same PDF as the previous example, only rather than producing multiple TIFF images, it creates one multi-page TIFF.
PdfRasterizer rasterizer = new PdfRasterizer("DocumentA.pdf");
FixedImageSize fixedImageSize = new FixedImageSize(595, 841);
rasterizer.DrawToMultiPageTiff("output-multipage-tiff.tif", ImageFormat.TiffWithLzw, fixedImageSize);
Dim rasterizer As New PdfRasterizer("DocumentA.pdf")
Dim fixedImageSize As New FixedImageSize(595, 841) rasterizer.DrawToMultiPageTiff("output-multipage-tiff.tif"), ImageFormat.TiffWithLzw, fixedImageSize)
See Multi-Page TIFFs for more details.
Programming with DynamicPDF Rasterizer
Refer to the following topics for more information on programming using the DynamicPDF Rasterizer.