Created
November 26, 2020 02:08
-
-
Save aspose-com-gists/b45852c1bdf93266ac2680913962f54d to your computer and use it in GitHub Desktop.
PDF to PNG C# Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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