Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created November 26, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b45852c1bdf93266ac2680913962f54d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b45852c1bdf93266ac2680913962f54d to your computer and use it in GitHub Desktop.
PDF to PNG C# Conversion
// Open PDF document
Document pdfDocument = new Document("Document.pdf");
// Set page index
int page = 1;
// Create FileStream for the output image
using (FileStream imageStream = new FileStream(string.Format("page_{0}.png", page), FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create Png device with specified attributes
// Width, Height, Resolution
PngDevice PngDevice = new PngDevice(500, 700, resolution);
// Convert a particular page and save the image to stream
PngDevice.Process(pdfDocument.Pages[page], imageStream);
// Close stream
imageStream.Close();
}
// Open PDF document
Document pdfDocument = new Document("Document.pdf");
// Loop through each page
foreach (var page in pdfDocument.Pages)
{
// Create file stream for output image
using (FileStream imageStream = new FileStream(string.Format("page_{0}.png", page.Number), FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create Png device with specified attributes
// Width, Height, Resolution
PngDevice PngDevice = new PngDevice(500, 700, resolution);
// Convert a particular page and save the image to stream
PngDevice.Process(page, imageStream);
// Close stream
imageStream.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment