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.

Draw Image in PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

92539 Jan 20,2010 07:23 AM Apr 23,2014 04:51 AM Windows Forms 9
loading
Tags: PDF
Barbara Tacchino
Asked On January 20, 2010 07:23 AM

Hello,

my development team and I are evaluating to buy PDF Essentials, so we are doing some tests about writing in PDF using Syncfusion.Pdf.Graphics.PdfGraphics object.
In particular we are trying to draw an image using the following code:

PdfDocument wPDFDOC = new PdfDocument();
PdfPage wPDFPage = wPDFDOC.Pages.Add();
PdfGraphics wPDFGraphics = wPDFPage.Graphics;
PdfImage wPdfImage = PdfImage.FromFile (@"c:\testBitmap.bmp");

//the image size has heigth:51 and width :429 the physical dimensions are Height:38.25 and Width: 312.75

wPdfImage.Draw(wPDFGraphics, 0, 0);
wPDFDOC.Save(@"c:\testBitmap.pdf");


As result, the image printed on a pdf file is larger and stretched. It seems that the drawn image is using the image pixels size as points without any unit conversion.

Thanks



ImageError_9fd86d2e.zip

Meiyappan R [Syncfusion]
Replied On January 21, 2010 10:22 AM

Hi Barbara,

Thank you for your interest in syncfusion products.

In the image the units are measured in pixels.In pdf the units are measured in points.While drawing we make unit conversions from pixels to points.Even if the units are converted we need to set the page scale explicitly.We have modified your sample to produce the image of expected size.Could you please look into the modified sample attached to the below link.

http://help.syncfusion.com/samples/pdf/ModifiedSample.zip

Kindly let us know if it works.

Regards
Meiyappan

Barbara Tacchino
Replied On January 21, 2010 12:31 PM

Hello,

thank you very much for your reply. The solution you provided seems to be ok in my tests.
The only thing I would like to ask you is the following: since after the image, in the same page, I may have to write also text, is it correct to restore the graphics transformation with this line (in my tests it seems to work):

wPDFPage.Graphics.ScaleTransform(1.136f, 1.136f);

Thanks in advance for your reply.

Best regards,

Barbara

Karthik M [Syncfusion]
Replied On January 22, 2010 11:26 AM

Hi Barbara,

Thank you for your update.

Yes, you are correct. We need to restore the current graphics state before performing subsequent drawing.

Please find the sample illustrating the same from the below location and let us know if this helps.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=WorkingwithImage_Restore-2000333351.zip

Best Regards,
Karthik

Marius Marin
Replied On May 10, 2013 06:42 AM

Hello,

I have a similar issue. Adjusting the scale as in your example:
    //the image size has heigth:51 and width :429 the physical dimensions are Height:38.25 and Width: 312.75
    wPDFPage.Graphics.ScaleTransform(.88f, .88f); 
fixed the image stretching.

However, I can't figure out how you did compute the 0.88 scalling factor...
I appreciate if you could help me with that.

Regards,
Marius

KarthikeyanC [Syncfusion]
Replied On May 16, 2013 11:45 PM

Hi Marius,

Thank you for your information.

 

The scaling factor is the conversion of pixel to points.

The scaling factor should be 0.75f, and the code snippet is:

wPDFPage.Graphics.ScaleTransform(.75f, .75f);

 

I have attached a sample with these code changes for your reference.

WorkingwithImage.zip

 

Please let us know if you have any concern.

 

Thanks,

Karthikeyan.C


caimage
Replied On June 3, 2013 06:17 AM

so much need to pay attention to when we are draw in pdf c#. pixels and points required to be changed.  we also should to scale the image height and width.

caimage
Replied On June 3, 2013 06:17 AM

so much need to pay attention to when we are draw in pdf c#. pixels and points required to be changed.  we also should to scale the image height and width.

KarthikeyanC [Syncfusion]
Replied On June 6, 2013 07:55 AM

Hi Caimage,
Thank you for sharing the information.

Thanks,
Karthikeyan.C

jonathan crawford
Replied On April 23, 2014 04:51 AM

Hi
 
I do not understand where you get the .75f and .88f from in the examples above.
This is not clear from your code. I thopught a scaling constant would be constant.
 
I cannot get my images to display correctly
 
Thanks
 
jc

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.

;