Output File Names
DynamicPDF Rasterizer allows outputting image files using either a default naming strategy or using user-defined names. The default naming strategy makes generating a file easier while manually controlling an output file name provides developers greater flexibility.
Default Output File Names
When using the PdfRasterizer class's Draw method to convert the PDF document to an image file, one image file is created for each PDF page specified. These output files use the value specified in the Draw method's fileName parameter.
The naming strategy for multi-page rasterization is as follows. When rasterizing more than one page, each page names the output image as the specified file name (minus the extension), the page number, and then appends the image file's extension.
<file name> + <page-number>.<file-type-extension>
The DocumentA.pdf
file contains four pages and therefore creates four images:
- myoutput1.png,
- myoutput2.png,
- myoutput3.png, and
- myoutput4.png.
For example, if you had a 3-page PDF document and named the output file myimage.png
, then the resultant images are named:
- myimage1.png,
- myimage2.png,
- and myimage3.png.
The following code illustrates the default output file naming
PdfRasterizer rasterizer = new PdfRasterizer(pdfFilePath);
rasterizer.Draw(pngFilePath, ImageFormat.Png, ImageSize.Dpi72);
Dim MyRasterizer As PdfRasterizer = New PdfRasterizer(pdfFilePath)
MyRasterizer.Draw(pngFilePath, ImageFormat.Png, ImageSize.Dpi72)
Manual Control of Output File Names
Developers also have control of file names by iterating over a collection of Pages in a PdfRasterizer object and then calling the Draw method individually for each page. Each page within the loop outputs the current image from the PDF document and allows naming each page uniquely.
PdfRasterizer rasterizer = new PdfRasterizer(pdfFilePath);
for(int i = 0; i < rasterizer.Pages.Count; i++)
{
rasterizer.Pages[i].Draw("DocumentA" + i +".png", ImageFormat.Png, ImageSize.Dpi72);
}
Dim MyRasterizer As PdfRasterizer = New PdfRasterizer(pdfFilePath)
Dim i As Integer
For i = 0 To MyRasterizer.Pages.Count - 1
MyRasterizer.Pages(i).Draw("Page" & i & "_DocumentA.png", ImageFormat.Png, ImageSize.Dpi72)
Next