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>
Example
The following code illustrates the default output file naming and creating multiple files from a PDF.
PdfRasterizer rasterizer = new PdfRasterizer("DocumentA.pdf");
rasterizer.Draw(@"png-output-example.png"), ImageFormat.Png, ImageSize.Dpi72);
Dim rasterizer As New PdfRasterizer("DocumentA.pdf")
rasterizer.Draw("png-output-example.png"), ImageFormat.Png, ImageSize.Dpi72)
The DocumentA.pdf
file contains four pages which when rasterized produces the following four images:
- png-output-example.png,
- png-output-example2.png,
- png-output-example3.png, and
- png-output-example4.png.
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.
The naming strategy differs between default naming and manual naming. When using default naming the first image has no numeric suffix and the remaining suffixes are numbered 1..n
. When using manual naming, the numeric suffix is 0..n
.
Example
The following code illustrates manual output file naming when creating a PNG from a PDF.
PdfRasterizer rasterizer = new PdfRasterizer(@"DocumentA.pdf");
for (int i = 0; i < rasterizer.Pages.Count; i++) {
rasterizer.Pages[i].Draw("manual-output" + i + ".png", ImageFormat.Png, ImageSize.Dpi72);
}
Dim rasterizer As New PdfRasterizer(Program.GetResourcePath("DocumentA.pdf"))
For i As Integer = 0 To rasterizer.Pages.Count - 1
rasterizer.Pages(i).Draw("manual-output" & i & ".png"), ImageFormat.Png, ImageSize.Dpi72)
Next
The DocumentA.pdf
file contains four pages which when rasterized produces the following four images:
- manualOutput0.png,
- manualOutput1.png,
- manualOutput2.png, and
- manualOutput3.png.