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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Fitting jpg image to page in pdf without loosing quality

Thread ID:





143094 Mar 4,2019 09:00 PM UTC Mar 7,2019 06:43 AM UTC WinForms 3
Tags: PDF
Bruce Groen
Asked On March 4, 2019 09:00 PM UTC


I am new to your tools and hoping for some direction.  I have read many posts on there regarding images in pdf's and resolution, etc.  I am trying to convert a jpg file into a pdf file.  The jpg files are 3,165 pixels wide by 1,856 pixels tall.  I want them to fill a landscape pdf page while retaining as much quality as possible.  

I read on this page (https://blog.idrsolutions.com/2012/03/there-are-several-versions-of-each-image-inside-your-pdf-file/) that images can be stored in pdf's in multiple formats so that you can display it in a resolution that fits the page but you can export it at its native resolution.  

I have tried this but I end up only seeing the top left corner of the image showing up on the page in the pdf and I loose the rest of the image.

Could you by chance share some code that accomplishes my goal?


Surya Kumar [Syncfusion]
Replied On March 5, 2019 10:13 AM UTC

Hi Bruce, 

Greetings from Syncfsuion. 

In order to draw the image without loss of quality you need to draw the image to fit the page bounds. Please refer the below code snippet to do the same: 
//Create a new PDF document. 
PdfDocument doc = new PdfDocument(); 
doc.PageSettings.Orientation = PdfPageOrientation.Landscape; 
//Add a page to the document. 
PdfPage page = doc.Pages.Add(); 
//Create PDF graphics for the page 
PdfGraphics graphics = page.Graphics; 
//Load the image from the disk. 
PdfBitmap image = new PdfBitmap(imagePath); 
SizeF pageSize = page.GetClientSize(); 
//Setting image bounds 
RectangleF imageBounds = new RectangleF(0, 0, pageSize.Width, pageSize.Height); 
//Draw the image 
graphics.DrawImage(image, imageBounds); 
//Save the document. 
//Close the document. 

Using the above code snippet will scale the image to fit in the provided bounds. We have created a simple sample for the same and it can be found in below link: 

You can refer our UG documentation to know more about the same. 

Please try the same let us know if you need any further information in this. 

Surya Kumar 

Bruce Groen
Replied On March 6, 2019 10:00 AM UTC

Thanks for getting back to me so quickly.  I apologize, I should have specified that I am developing in vb.net.  I am having some problems converting a couple of the lines you provided into vb.net.  Would you mind please posting sample code in vb.net form?

Karthikeyan Chandrasekar [Syncfusion]
Replied On March 7, 2019 06:43 AM UTC

Hi Bruce, 
As per your request we have created the sample which we have provided in VB.NET. Please find the code snippet and sample for the same from below, 
'Create PDF document 
Dim doc As PdfDocument = New PdfDocument() 
'Set orientation  
doc.PageSettings.Orientation = PdfPageOrientation.Landscape 
'Add page 
Dim page As PdfPage = doc.Pages.Add() 
'Create graphics 
Dim graphics As PdfGraphics = page.Graphics 
'Load the image from disk 
Dim image As PdfBitmap = New PdfBitmap(imagePath); 
'Get page size 
Dim pageSize As SizeF = page.GetClientSize() 
'Setting image bounds 
Dim imageBounds As RectangleF = New RectangleF(0, 0, pageSize.Width, pageSize.Height) 
'Draw the image 
graphics.DrawImage(image, imageBounds) 
'Save the document 
'Close the document 
Please let us know if you need any further assistance on this. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon