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.

Center image

Thread ID:

Created:

Updated:

Platform:

Replies:

125991 Sep 16,2016 12:31 AM Sep 19,2016 03:11 AM ASP.NET MVC 1
loading
Tags: PDF
mvxyc
Asked On September 16, 2016 12:31 AM

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 03:11 AM

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. 


CONFIRMATION

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.

;