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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Center image

Thread ID:





125991 Sep 16,2016 04:31 AM UTC Sep 19,2016 07:11 AM UTC ASP.NET MVC 1
Tags: PDF
Asked On September 16, 2016 04:31 AM UTC

I tried this, but does not center:
                       PdfPage page = document.Pages.Add();

                        PdfGraphics graphics = page.Graphics;
                        PdfBitmap image = new PdfBitmap(ImageFilenames[i]);

                        graphics.DrawImage(image, image.Width / 2, image.Height / 2);

Sasi Kumar Sekar [Syncfusion]
Replied On September 19, 2016 07:11 AM UTC

Hi mvxyc, 
Thank you for contacting Syncfusion support. 
We can able to achieve your requirements by subtracting the half image width and height from the center position of the page, Please find the below code snippet and sample link for your reference. 
Code snippet: 
//Create PDf document 
PdfDocument doc = new PdfDocument(); 
//Add pages to PDF document. 
PdfPage page = doc.Pages.Add(); 
string imagePath = Server.MapPath("~/App_Data/business.jpg"); 
PdfImage image=PdfImage.FromFile(imagePath);     
float x = (page.GetClientSize().Width / 2) - (image.Width / 2); 
float y = (page.GetClientSize().Height / 2) - (image.Height / 2); 
//Draw the image to center of PDf page.         
page.Graphics.DrawImage(image, new RectangleF(x,y,image.Width,image.Height)); 
//Save the PDF document. 
Sample link: 
Kindly let us know if you have any further assistance on this. 
Sasi Kumar S. 


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