Center image on the page

Hi,
i would like center a lot of images in the page. I've try this code:

foreach (...
{

x = ((doc.Pages[doc.Pages.Count - 1].Graphics.ClientSize.Width) - Img.Width) / 2;

PointF location = new PointF(_x, _lastLineY + 20);
SizeF size = new SizeF(Img.Width, Img.Height);
RectangleF rect = new RectangleF(location, size);
Img.Draw(doc.Pages[doc.Pages.Count - 1], rect);

}

but only first image is centered, the others images shifts on the left... why?

Thank you.

1 Reply

SS Sri Subhashini M Syncfusion Team August 26, 2009 08:26 AM UTC

Hi Pegaso,

Thank you for your interest in Essential PDF.

Drawing image in center of the PDF document

I was able to reproduce the issue which you mentioned here. Kindly refer the modified code snippet,


PdfImage Img = PdfBitmap.FromFile(images[i]);
x = (doc.Pages[i].Graphics.ClientSize.Width) / 2;
float imgw = Img.Width / 2 ;
PointF location = new PointF(x - imgw, _lastLineY + 20);
SizeF size = new SizeF(Img.Width, Img.Height);
RectangleF rect = new RectangleF(location, size);
doc.Pages[i].Graphics.DrawImage(Img, rect);


Please do find the sample from the below specified location and let me know if this helps,

http://files.syncfusion.com/samples/PDF.Windows/PDF_Window_F89455.zip

Regards,
Suba

Loader.
Up arrow icon