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

Insert Image centered in pdf page

Thread ID:





108724 May 8,2013 05:02 PM May 11,2013 04:59 AM ASP.NET Web Forms (Classic) 2
Tags: PDF
Bob Baldwin
Asked On May 8, 2013 05:02 PM

We have the need to convert JPEG, PNG, GIF, and BMP files into a PDF file.
I'm using the PDFImage class but not sure how to center the image within the PDFDocument page.
I can load the image and see its Height and Width in pixels as well as the PhysicalDimensions in Points.
Can you help me determine how to calc the point to place the image so that it is centered on the portrait page?
I guess we need to convert the Image pixel size into points using the PDFUnitConvertor.  This value should allow me to calc the X,Y Point that will center the graphic.
Any help would be appreciated, below is my current code. 
Thx...Bob Baldwin
Trabon Solutions

var tmpPdf = new PdfDocument();
case ".jpg":
case ".png":
case ".gif":
case ".bmp":
var image = new PdfBitmap(companyProjFileDir + @"\" + fn + fileExt);
var pg = tmpPdf.Pages.Add();
ar g = pg.Graphics;
g.DrawImage(image, 0, 0, image.Width, image.Height);
Debug.WriteLine(string.Format("image.Width={0}", image.Width));
Debug.WriteLine(string.Format("image.Height={0}", image.Height));
Debug.WriteLine(string.Format("image.HorizontalResolution={0}", image.HorizontalResolution));
Debug.WriteLine(string.Format("image.VerticalResolution={0}", image.VerticalResolution));
Debug.WriteLine(string.Format("image.PhysicalDimensions={0}", image.PhysicalDimension.ToString()));
Debug.WriteLine(string.Format("pg.Size={0}", pg.Size.ToString()));
Debug.WriteLine(string.Format("pg.ClientSize={0}", pg.GetClientSize().ToString()));
Debug.WriteLine(string.Format("PageSettings.Size={0}", tmpPdf.PageSettings.Size.ToString()));
Debug.WriteLine(string.Format("PageSettings.Margins={0}", tmpPdf.PageSettings.Margins.ToString()));
Debug.WriteLine(string.Format("PageSettings.Height={0}", tmpPdf.PageSettings.Height));
Debug.WriteLine(string.Format("PageSettings.Width={0}", tmpPdf.PageSettings.Width));
PdfUnitConvertor con = new PdfUnitConvertor();
SizeF size = con.ConvertToPixels(image.PhysicalDimension, PdfGraphicsUnit.Point);
Debug.WriteLine(string.Format("image.PhysicalDim2Pixel={0}", size.ToString()));

Bob Baldwin
Replied On May 9, 2013 03:03 PM

Nevermind, I found it after more searching on your forums:

Praveenkumar H [Syncfusion]
Replied On May 11, 2013 04:59 AM

Hi Bob,

Thank you for using Syncfusion products,

We are happy to hear that you got the solution.

Please let us know if you have any concern

With Regards,


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.

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.