Read the complete article on how to convert PDF pages to JPG images in C#: https://blog.aspose.com/2022/06/08/convert-pdf-to-jpg-in-csharp-net/
Last active
June 9, 2022 05:25
-
-
Save aspose-com-gists/6eedeb7fef83ededde7ec2c4de76d3a2 to your computer and use it in GitHub Desktop.
Convert PDF Pages to JPG Images in C#
This file contains hidden or 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 number | |
int pageNumber = 1; | |
// Create FileStream for the output image | |
using (FileStream imageStream = new FileStream(string.Format("page_{0}.jpg", pageNumber), FileMode.Create)) | |
{ | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create Jpeg device with specified attributes | |
// Width, Height, Resolution | |
JpegDevice JpgDevice = new JpegDevice(500, 700, resolution); | |
// Convert a particular page and save the image to stream | |
JpgDevice.Process(pdfDocument.Pages[pageNumber], imageStream); | |
// Close stream | |
imageStream.Close(); | |
} |
This file contains hidden or 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 pages | |
foreach (var page in pdfDocument.Pages) | |
{ | |
// Create file stream | |
using (FileStream imageStream = new FileStream(string.Format("page_{0}.jpg", page.Number), FileMode.Create)) | |
{ | |
// Create resolution object | |
Resolution resolution = new Resolution(300); | |
// Create Jpeg device with specified attributes | |
// Width, Height, Resolution | |
JpegDevice JpgDevice = new JpegDevice(500, 700, resolution); | |
// Convert a particular page and save the image to stream | |
JpgDevice.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