Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get original Size of PDF

Tags:

c#

pdf

pdfium

I want to get the same image quality as if I would use the export pdf to png from Adobe Acrobat.

But somehow this does not work for me. The dimensions that I get if I export the pdf to a png with help of the Adobe Acrobat tool are: Width:11264 pix Height:15940 pix

As you may see I provide you the method that I use to read the pdf an create per page a image. The possibilities that I have are to use the .Render Method which needs a int page(index) float dpiX, float dpiY, bool forPrinting

But some how it has no effect on the image saved ?

using (var document = PdfiumViewer.PdfDocument.Load(file)) 
{
    //This int is used to get the page count for each document 
    int pagecount = document.PageCount;

    //With the int pagecount we can create as may screenshots as there are pages in the document
    for (int index = 0; index < pagecount; index++)
    {
        //render the image created
        var image = document.Render(index,8448,11955, true);

        //savde the created screenshot temporerlay as a png + number (count)
        image.Save(@"C:\Users\chnikos\Desktop\Test\output" + index.ToString("000") + ".png",ImageFormat.Png);
        application.Selection.InlineShapes.AddPicture(@"C:\Users\chnikos\Desktop\Test\output" + index.ToString("000") + ".png");
    }
}
like image 581
Niko.K Avatar asked Oct 19 '25 13:10

Niko.K


1 Answers

try
{
    using (var document = PdfiumViewer.PdfDocument.Load(@"C:\Users\ohernandez\Pictures\img\descarga.pdf"))
    {
        for (int index = 0; index < document.PageCount; index++)
        {
            var image = document.Render(index, 300, 300, PdfRenderFlags.CorrectFromDpi);
            image.Save(@"C:\Users\ohernandez\Pictures\img\output.Jpeg" + index.ToString("000") + ".Jpeg", ImageFormat.Jpeg);
        }
    }
}
catch (Exception ex)
{
    // handle exception here;
}
like image 142
ohernandez Avatar answered Oct 22 '25 09:10

ohernandez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!