We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ExportAsImage doesn't work with DPI Settings

I Have a problem with exporting a PDF to an Image when i set the DPI:

      public static Bitmap ConvertPdfToBitmap(string filepath, int dpi)
        {

            Bitmap bmp = null;

            PdfViewerControl loadedDocument = new PdfViewerControl();
            loadedDocument.Load(filepath);
            bmp = loadedDocument.ExportAsImage(0);
            bmp = loadedDocument.ExportAsImage(0, bmp.HorizontalResolution *2, bmp.VerticalResolution*2) ;

            return bmp;
        }

When i use the DPI settings, the image DPI gets higher but the image itself is nto stretched. White space is added around it, even when I put in an integer like 300,300 it is the same thing.
Is this a bug or am i doing something wrong?

Attachment: 20190117_19_40_31_665a0895.rar

1 Reply

KK Karthik Krishnaraj Syncfusion Team January 18, 2019 11:17 AM UTC

Hi Haikal, 
 
Greetings from Syncfusion, 
 
When i use the DPI settings, the image DPI gets higher but the image itself is nto stretched. White space is added around it 
We were unable to reproduce the issue with “White space added around the exported image”. I have attached a simple sample for your reference below. Can you please modify the sample to replicate the issue? It will be helpful for us to analyze further and provide better solution. 
the image itself is nto stretched 
DPI value is meant to increase the quality of the image. If you want to increase width and height of the image, you can specify the custom size to the image while exporting the PDF document using PDF viewer. Please find the below code snippet. 
 
BitmapSource[] bitmapSource = pdfViewer.ExportAsImage(startIndex, endIndex, new SizeF(900, 900), 300, 300, true); 
 
 
 
API reference link: 
 
We can also export the specific pages of the PDF document as Bitmap sources with respect to DPI. Please find the API reference link below. 
 
We have prepared sample illustrating both the scenario. Kindly try running the sample and let us know whether it helps you. 
 
 
 
Sample link: 
 
Regards, 
Karthik. 


Loader.
Live Chat Icon For mobile
Up arrow icon