Fitting jpg image to page in pdf without loosing quality

Hi, 

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?

Thanks.

6 Replies

SK Surya Kumar Syncfusion Team 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. 
doc.Save(DataPathOutput+"Output.pdf"); 
 
//Close the document. 
doc.Close(true); 



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. 

Regards, 
Surya Kumar 



BG Bruce Groen 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?




KC Karthikeyan Chandrasekar Syncfusion Team 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 
doc.Save("Output.pdf") 
'Close the document 
doc.Close(True) 
Process.Start("Output.pdf") 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Karthikeyan  



NA Naveed Ansari January 11, 2026 10:17 AM UTC

When dealing with issues like fitting a JPG image into a PDF without losing quality, having a quick way to share and review images is really helpful. Chat pic makes this easy by letting users upload high-resolution images without complex sign-ups, so others can check clarity, scaling, and compression before conversion. Sharing the image on Chatpic allows quick feedback on whether the resolution is sufficient for PDF export. This can help avoid quality loss by adjusting image size and DPI beforehand.



NA Naveed Ansari January 29, 2026 01:59 PM UTC

When fitting a JPG image into a PDF, the key challenge is preserving the original resolution while adapting it to the document layout. Similarly, when reviewing software or digital files, users often depend on visual previews and file information to understand content before use. In both situations, proper file handling and clarity play an important role in overall usability.



JT Jeyalakshmi Thangamarippandian Syncfusion Team January 30, 2026 07:50 AM UTC

Hi Naveed,


When using the Syncfusion .NET PDF Library, the image quality itself is not reduced during the drawing process. However, quality loss may occur if the image is scaled while being drawn onto the PDF page.

To maintain clarity, we recommend setting the PDF page size to match the original dimensions of the image. This ensures the image appears crisp and clear in the generated PDF.

Please refer to the sample code below.

 

//Create a new PDF document
PdfDocument doc = new PdfDocument();
//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
FileStream imageStream = new FileStream("../../../Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);

PdfBitmap image = new PdfBitmap(imageStream);

 

// Add a new section to the document
PdfSection section = doc.Sections.Add();

 

// Set the size of the page in the section to match the image's physical dimensions
section.PageSettings.Size = new SizeF(image.PhysicalDimension.Width, image.PhysicalDimension.Height);
//Draw the image
graphics.DrawImage(image, 0, 0);

 

//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);

 

If this does not meet your requirement, could you please provide further complete requirement details and image file.



Regards,

Jeyalakshmi T


Loader.
Up arrow icon