Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 9, 2022 05:25
Show Gist options
  • Save aspose-com-gists/6eedeb7fef83ededde7ec2c4de76d3a2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6eedeb7fef83ededde7ec2c4de76d3a2 to your computer and use it in GitHub Desktop.
Convert PDF Pages to JPG Images in C#
// 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();
}
// 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