|
//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); |
|
'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") |
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.
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.
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