Class PngDevice
Contents
[
Hide
]PngDevice class
Represents image device that helps to save pdf document pages into png.
public sealed class PngDevice : ImageDevice
Constructors
Name | Description |
---|---|
PngDevice() | Initializes a new instance of the PngDevice class with default resolution. |
PngDevice(PageSize) | Initializes a new instance of the PngDevice class with provided page size, default resolution (=150). |
PngDevice(Resolution) | Initializes a new instance of the PngDevice class. Resolution for the result image file, see Resolution class. |
PngDevice(int, int) | Initializes a new instance of the PngDevice class with provided image dimensions, default resolution (=150). |
PngDevice(PageSize, Resolution) | Initializes a new instance of the PngDevice class with provided page size and resolution. |
PngDevice(int, int, Resolution) | Initializes a new instance of the PngDevice class with provided image dimensions and resolution. |
Properties
Name | Description |
---|---|
CoordinateType { get; set; } | Gets or sets the page coordinate type (Media/Crop boxes). CropBox value is used by default. |
FormPresentationMode { get; set; } | Gets or sets form presentation mode. |
Height { get; } | Gets image output height. |
RenderingOptions { get; set; } | Gets or sets rendering options. |
Resolution { get; } | Gets image resolution. |
TransparentBackground { get; set; } | Gets or sets if image has transparent background. |
Width { get; } | Gets image output width. |
Methods
Name | Description |
---|---|
override Process(Page, Stream) | Converts the page into png and saves it in the output stream. |
Process(Page, string) | Perfoms some operation on the given page and saves results into the file. |
Examples
The following example shows how to convert PDF file to PNG Images.
[C#]
// The path to your PDF Directory
string dataDir = @"YOUR_DATA_DIRECTORY";
// The file name of the PDF
string pdfFile = @"YOUR_PDF_FILE";
// Initialize instance of Document class
using (Document pdfDocument = new Document(Path.Combine(dataDir, pdfFile)))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Initialize PngDevice
PngDevice pngDevice = new PngDevice(resolution);
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream pngStream =
new FileStream($"{dataDir}image{pageCount}_out.png",
FileMode.Create))
{
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageCount], pngStream);
// Close stream
pngStream.Close();
}
}
}
[VB.NET]
' The path to your PDF Directory
Dim dataDir As String = "YOUR_DATA_DIRECTORY"
' The file name of the PDF
Dim pdfFile As String = "YOUR_PDF_FILE"
' Initialize instance of Document class
Using pdfDocument As Document = New Document(Path.Combine(dataDir, pdfFile))
' Create Resolution object
Dim resolution As Resolution = New Resolution(300)
' initialize PngDevice
Dim pngDevice As PngDevice = New PngDevice(resolution)
For pageCount As Integer = 1 To pdfDocument.Pages.Count
Using pngStream As FileStream = New FileStream($"{dataDir}image{pageCount}_out.png", FileMode.Create)
' Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages(pageCount), pngStream)
' Close stream
pngStream.Close()
End Using
Next
End Using
See Also
- class ImageDevice
- namespace Aspose.Pdf.Devices
- assembly Aspose.PDF