Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v5.x)  /  Image Align

Forum Thread - Image Align

 Oct 21 2009 12:17 PM

I need some help with displaying image in the center of the page. My page width is 500 float points and height is 700 float points.

I tried both Align.Center and Valign.Center but the picture doesn't align in center.

Here's my code:
PageElements.Image bitmapImage = new PageElements.Image(newImage, 0, 20);
                    bitmapImage.VAlign = ceTe.DynamicPDF.VAlign.Center;

 Oct 21 2009 12:37 PM
Posted by a ceTe Software moderator
Hello John,

Yes, you can place the image in the middle of the page and below is a sample code for this.

    Document document = new Document();
    Page page = new Page();
    float centerX = (page.Dimensions.Width - page.Dimensions.LeftMargin - page.Dimensions.RightMargin) / 2;
    float centerY = (page.Dimensions.Height - page.Dimensions.TopMargin - page.Dimensions.BottomMargin) / 2;
    Image MyImage = new Image(@"D:\Attachments\Images\logo.tif", centerX, centerY);
    MyImage.VAlign = VAlign.Center;
    MyImage.Align = Align.Center;

ceTe Software Support Team.
 Oct 21 2009 2:17 PM

Thanks for your reply. It worked out. I have one more question. I want to display image caption after the image. How do I find what is the end of the image (end Y) on the page?
I tried image.Height + 15 as Y coordinate for formattedImageText but it doesn't work.

float centerX = ContentWidth / 2;
                    float centerY = ContentHeight / 2 ;
                    PageElements.Image scaledImage = new PageElements.Image(newImage, centerX, centerY);
                    scaledImage.VAlign = ceTe.DynamicPDF.VAlign.Center;
                    scaledImage.Align = ceTe.DynamicPDF.Align.Center;
                    float imgHeight = newImage.Height;
                                       PageElements.FormattedTextArea formattedimageText = new PageElements.FormattedTextArea(imageText, 0, imgHeight + 15, ContentWidth, 0, imageStyle);
                    formattedimageText.Style.Paragraph.Align = ceTe.DynamicPDF.TextAlign.Center;
                    float imageTextHeight = formattedimageText.GetRequiredHeight();
                    formattedimageText.Height = imageTextHeight;
 Oct 21 2009 3:19 PM
Posted by a ceTe Software moderator

You can calculate the Y coordinate of where the image ended using the starting Y coordinate where you place the image and the height of the image.

ceTe Software Support Team
 Feb 15 2017 7:21 AM

Does the API changed since ?
Because this code doesn't work anymore...

Thanks for your help !
 Feb 15 2017 11:14 AM
Posted by a ceTe Software moderator

The code posted above is for v5 and we tested using the v5.1.2.15141 DLL and we are able to place the image correctly in the middle of the page using code sample posted above.

Please send over the following details to so we can look into it further.

1.Code sample which uses static data to recreate the behaviour.
2.Output PDF.
3.Image file.
4.Exact version and build number of the DynamicPDF DLL file. You can get this information in DLL references properties (Version and Description fields) in Visual Studio.

ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 9:12 AM.