Convert multipage pdf invoice into multiple images

Hi Guys could you supply me with an Asp Net Core Razor page example where you convert  a multi page pdf invoice  into multiple images .


Thanks 


Edmund Herbert


3 Replies

KG Krithika Ganesan Syncfusion Team July 11, 2024 01:39 PM UTC

Using the PDF to image converter library, you can convert PDF documents into images. This allows you to convert multiple PDF pages into individual images. We have attached a code snippet and a sample below for your reference.


//Initialize PDF to Image converter.

PdfToImageConverter imageConverter = new PdfToImageConverter();

//Load the PDF document as a stream

FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);

imageConverter.Load(inputStream);

//Convert PDF to Image.

Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount - 1, false, false);


Attachment: PDF_to_Image_Core_6aabc73f.zip


EH Edmund Herbert July 12, 2024 04:10 AM UTC

Hi thanks could you show me how to save multiple images from stream extracted from pdf with multiple pages also how images could be saved to reflect each page.


Regards


Edmund Herbert



KG Krithika Ganesan Syncfusion Team July 12, 2024 01:30 PM UTC

Hi Edmund,

 

We can save the resulting `stream[]` as multiple images using the code snippet and sample we have attached below. By combining all the images into a ZIP file, we enable the downloading of that ZIP file.

 

using (MemoryStream ms = new MemoryStream())

{

    ms.Position = 0;

    //required: using System.IO.Compression; 

    using (var zip = new System.IO.Compression.ZipArchive(ms, ZipArchiveMode.Create, true))

    {

        for (int i = 0; i < imageStream.Length; i++)

        {

            var entry = zip.CreateEntry("Page" + i +".png");

 

            using (var entryStream = entry.Open())

            {

                imageStream[i].Position= 0;

                imageStream[i].CopyTo(entryStream);

            }

        }

    }

    return File(ms.ToArray(), "application/zip", zipName);

}

 

Regards,

Krithika


Attachment: PDF_to_Images_Core_598d3897.zip

Loader.
Up arrow icon