From c3b622f8c105e5b78d3100924e618231e8465b0a Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Mon, 27 Oct 2025 16:33:59 +0530 Subject: [PATCH 1/3] 260329-ug: Added the code sample for create PDF page based on the image size using PdfUnitConverter class --- .../NET/Working-with-Annotations.md | 4 +- .../PDF-Library/NET/Working-with-Images.md | 154 ++++++++++++++++++ 2 files changed, 156 insertions(+), 2 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Annotations.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Annotations.md index ca56ac094..d2fb53343 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Annotations.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Annotations.md @@ -5074,7 +5074,7 @@ The [PdfAnnotationIntent.FreeTextTypeWriter](https://help.syncfusion.com/cr/docu {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Annotation/Setting-Annotation-Intent/.NET/Setting-Annotation-Intent/Program.cs" %} using Syncfusion.Drawing; using Syncfusion.Pdf; @@ -5192,7 +5192,7 @@ End Using {% endtabs %} -You can download a complete working sample from GitHub. +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/260329/Annotation/Setting-Annotation-Intent/.NET). ## Adding comments and review status to the PDF annotation diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md index 38ca465a8..cf94820e3 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md @@ -723,6 +723,160 @@ doc.Close(True) You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Add-transparancy-and-rotation-to-the-image/). +## Unit conversion in image position + +The [PdfUnitConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfUnitConvertor.html) class provides precise measurement conversion capabilities for PDF layouts. When positioning images in a PDF document, the converter translates pixel dimensions to PDF points, enabling millimeter-perfect placement and sizing. This ensures images maintain their aspect ratio while rendering at exact locations and filling designated spaces like rectangles. + +The code snippet to illustrate the same is given below. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} + +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +//Create a new PDF document +using (PdfDocument document = new PdfDocument()) +{ + using (FileStream stream = new FileStream("Image.png", FileMode.Open, FileAccess.Read)) + { + //Load the image from the disk + PdfBitmap image = new PdfBitmap(stream); + + //Add the first section to the PDF document + PdfSection section = document.Sections.Add(); + + //Initialize unit converter + PdfUnitConvertor converter = new PdfUnitConvertor(); + + //Convert the image size from pixel to points + SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); + + //Set section size based on the image size + section.PageSettings.Size = size; + + // Set section orientation based on the image size (by default Portrait) + if (image.Width > image.Height) + section.PageSettings.Orientation = PdfPageOrientation.Landscape; + + //Set a margin for the section + section.PageSettings.Margins.All = 0; + + //Add a page to the section + PdfPage page = section.Pages.Add(); + + //Draw image + page.Graphics.DrawImage(image, 0, 0); + + //Save the document + document.Save("Output.pdf"); + } +} + +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +//Create a new PDF document +using (PdfDocument document = new PdfDocument()) +{ + using (FileStream stream = new FileStream("Image.png", FileMode.Open, FileAccess.Read)) + { + //Load the image from the disk + PdfBitmap image = new PdfBitmap(stream); + + //Add the first section to the PDF document + PdfSection section = document.Sections.Add(); + + //Initialize unit converter + PdfUnitConvertor converter = new PdfUnitConvertor(); + + //Convert the image size from pixel to points + SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); + + //Set section size based on the image size + section.PageSettings.Size = size; + + // Set section orientation based on the image size (by default Portrait) + if (image.Width > image.Height) + section.PageSettings.Orientation = PdfPageOrientation.Landscape; + + //Set a margin for the section + section.PageSettings.Margins.All = 0; + + //Add a page to the section + PdfPage page = section.Pages.Add(); + + //Draw image + page.Graphics.DrawImage(image, 0, 0); + + //Save the document + document.Save("Output.pdf"); + } +} + +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + +Module Program + Sub Main() + ' Create a new PDF document + Using document As New PdfDocument() + + ' Load the image from disk + Using stream As New FileStream("Image.png", FileMode.Open, FileAccess.Read) + Dim image As New PdfBitmap(stream) + + ' Add a section to the PDF document + Dim section As PdfSection = document.Sections.Add() + + ' Initialize unit converter + Dim converter As New PdfUnitConvertor() + + ' Convert image size from pixels to points + Dim size As SizeF = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel) + + ' Set section size based on image size + section.PageSettings.Size = size + + ' Set orientation to landscape if image is wider than tall + If image.Width > image.Height Then + section.PageSettings.Orientation = PdfPageOrientation.Landscape + End If + + ' Remove margins + section.PageSettings.Margins.All = 0 + + ' Add a page to the section + Dim page As PdfPage = section.Pages.Add() + + ' Draw the image at position (0, 0) + page.Graphics.DrawImage(image, 0, 0) + + ' Save the document + document.Save("Output.pdf") + End Using + End Using + End Sub +End Module + +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from GitHub. + ## Converting multi page TIFF to PDF Multi frame TIFF image can be converted to PDF document. This can be done by accessing each frame of the multi frame TIFF image and rendering it in each page of the PDF document using [PdfBitmap](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfBitmap.html) class. From 36d10e668c3c19e84d1c37b90a07abb6ef1b550c Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Tue, 28 Oct 2025 09:53:23 +0530 Subject: [PATCH 2/3] 260329-ug: Updated the API name. --- .../PDF/PDF-Library/NET/Working-with-Images.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md index cf94820e3..d97dc2158 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md @@ -749,7 +749,7 @@ using (PdfDocument document = new PdfDocument()) PdfSection section = document.Sections.Add(); //Initialize unit converter - PdfUnitConvertor converter = new PdfUnitConvertor(); + PdfUnitConverter converter = new PdfUnitConverter(); //Convert the image size from pixel to points SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); @@ -795,7 +795,7 @@ using (PdfDocument document = new PdfDocument()) PdfSection section = document.Sections.Add(); //Initialize unit converter - PdfUnitConvertor converter = new PdfUnitConvertor(); + PdfUnitConverter converter = new PdfUnitConverter(); //Convert the image size from pixel to points SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); @@ -842,7 +842,7 @@ Module Program Dim section As PdfSection = document.Sections.Add() ' Initialize unit converter - Dim converter As New PdfUnitConvertor() + Dim converter As New PdfUnitConverter() ' Convert image size from pixels to points Dim size As SizeF = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel) From a674fc7b216f4d13e01bd032c4e8161292282e79 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Tue, 28 Oct 2025 11:30:42 +0530 Subject: [PATCH 3/3] 260329-ug: Resolved the given feedback. --- .../PDF/PDF-Library/NET/Working-with-Images.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md index d97dc2158..c95dee8ba 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md @@ -752,7 +752,7 @@ using (PdfDocument document = new PdfDocument()) PdfUnitConverter converter = new PdfUnitConverter(); //Convert the image size from pixel to points - SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); + SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point); //Set section size based on the image size section.PageSettings.Size = size; @@ -798,7 +798,7 @@ using (PdfDocument document = new PdfDocument()) PdfUnitConverter converter = new PdfUnitConverter(); //Convert the image size from pixel to points - SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel); + SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point); //Set section size based on the image size section.PageSettings.Size = size; @@ -845,7 +845,7 @@ Module Program Dim converter As New PdfUnitConverter() ' Convert image size from pixels to points - Dim size As SizeF = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Pixel) + Dim size As SizeF = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point) ' Set section size based on image size section.PageSettings.Size = size