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

about the image

about the image

g.DrawImage(image, X, Y,Width,Height);

1.what is the unit for the X,Y,Width,Height. is the pixel, or Millimeter?
2.about the X,Y, is the image's center point, or the left-top point?

3.Because I have set g.DrawImage(image, 0, 0,Width,Height); but the image is not at the paper's top left , it has some margins.(you can see the attached picture) Because our database has record the items position(X,Y). So we need to set item's position based on the left-top point of paper. how can we set this margin to zero.

thanks
yang



Sample_93536c41.zip

4 Replies

AD Administrator Syncfusion Team August 6, 2008 05:59 AM UTC

Hi Yang,

Thank you for your interest in Syncfusion PDF.

Here is the answers for your questions,

1)DrawString method measurement

DrawString used to draw the specified text string at the specified location with the specified Brush and Font objects. The configuration for the location parameter is SizeF. Those values are representing float values which representing height and width in pixel.

2)Is X,Y the image''s center point or the left-top point?

The X,Y is the System.Drawing.Point that represents the upper-left corner of the specified boundary region.

3)Setting Margin

PDF generates the document with default margin value. We can set the margin value to zero by using the PageSettings class. Kindly use the below code to set the marging value as zero.

// Setting Margin
doc.PageSettings.Margins.All = 0;

Please look into the sample from the below specified location and let me know if this helps.

http://www.syncfusion.com/support/user/uploads/Sample_23a4b6c3.zip


Regards,
Suba




WY Wulong Yang August 6, 2008 06:43 AM UTC

hi, there is one thing, because you said the unit is Pixel, mm=Pixel*25.4/DPI, if the PDF page is A4(210mm*297). you can see if we want image at the middle of of the PDF page,
Position X(mm)=105mm, y=0, it change to Pixel
X(Pixel)=105mm*96/25.4=396, Y=0, ( my computer's DPI=96)

when you do that,you will find actually it will not show at the middle, is it a bug?

g.DrawImage(image, 396, 0, image.Width, image.Height);



SS Sri Subhashini M Syncfusion Team August 6, 2008 12:57 PM UTC

Hi,

Essential PDF generates the document with the size values as 596 and 842. Kindly use the below code to draw the image in the middle of the PDF document,

// Drawing the image
g.DrawImage(image, (page.Size.Width / 4) , (page.Size.Height / 2) - image.Height, image.Width, image.Height);

Please let me know if this helps.

Regards,
Suba



ER Eric Rosenblum September 4, 2014 08:47 PM UTC

 PdfImage image = new PdfBitmap(PathToImage);
                //PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Tahoma", 10f, FontStyle.Bold), false);
                // PdfSolidBrush brush = new PdfSolidBrush(Color.DarkBlue);


                float ftImageWidth;
                float ftImageHeight;
                float ftPageWidth;
                float ftPageHeight;

                float.TryParse(image.Width.ToString(), out ftImageWidth);
                float.TryParse(image.Height.ToString(), out ftImageHeight);
                ftPageWidth = page.Graphics.ClientSize.Width;
                ftPageHeight = page.Graphics.ClientSize.Height;


                float myWidth = image.Width;
                float myHeight = image.Height;
                float shrinkFactor;

                float temp;
                if (myWidth > ftPageWidth)
                {

                    shrinkFactor = myWidth / ftPageWidth;
                    myWidth = ftPageWidth;
                    myHeight = myHeight / shrinkFactor;
                }

                if (myHeight > ftPageHeight)
                {
                    shrinkFactor = myHeight / ftPageHeight;
                    myHeight = ftPageHeight;
                    myWidth = myWidth / shrinkFactor;
                }


                g.DrawImage(image, (ftPageWidth - myWidth)/2, (ftPageHeight - myHeight)/2, myWidth, myHeight);

Loader.
Live Chat Icon For mobile
Up arrow icon