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. Image for the cookie policy date
close icon

Center image

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);

1 Reply

SK Sasi Kumar Sekar Syncfusion Team 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. 
doc.Save("Output.pdf”); 
 
 
 
 
Sample link: 
 
Kindly let us know if you have any further assistance on this. 
 
Regards, 
Sasi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon