Convert each pdf page to image and download all images in a single zip file

Hi,

Convert each pdf from memorystream
ie) each page from memory stream to image and download all images in a single zip file

Hi There,


Thanks for contacting support.

Yes, you can covert each page of the PDF document to image. The following code snippet shows you how to convert all pages in a file to JPEG images.

C#

// Open document
Document pdfDocument = new Document(dataDir + “PagesToImages.pdf”);
string outputDir = dataDir + “images_folder/”;

for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(outputDir + “image” + pageCount + “_out” + “.jpg”, FileMode.Create))
{
// Create JPEG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
// JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
JpegDevice jpegDevice = new JpegDevice(resolution, 100);
// Convert a particular page and save the image to stream
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}

This way you will have all PDF pages as separate images, then you can zip them. You can check “Convert PDF pages” section in our documentation for more details.

If you still face any issue, please feel free to contact us.

Best Regards,