Draw Image in PDF
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
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
SIGN IN To post a reply.
9 Replies
MR
Meiyappan R
Syncfusion Team
January 21, 2010 03:22 PM UTC
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
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
BT
Barbara Tacchino
January 21, 2010 05:31 PM UTC
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
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
KM
Karthik M
Syncfusion Team
January 22, 2010 04:26 PM UTC
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
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
MM
Marius Marin
May 10, 2013 10:42 AM UTC
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
KC
Karthikeyan Chandrasekar
Syncfusion Team
May 17, 2013 03:45 AM UTC
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.
Please let us know if you have any concern.
Thanks,
Karthikeyan.C
CA
caimage
June 3, 2013 10:17 AM UTC
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.
CA
caimage
June 3, 2013 10:17 AM UTC
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.
KC
Karthikeyan Chandrasekar
Syncfusion Team
June 6, 2013 11:55 AM UTC
Hi Caimage,
Thank you for sharing the information.
Thanks,
Karthikeyan.C
Thank you for sharing the information.
Thanks,
Karthikeyan.C
JC
jonathan crawford
April 23, 2014 08:51 AM UTC
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
SIGN IN To post a reply.
- 9 Replies
- 8 Participants
-
BT Barbara Tacchino
- Jan 20, 2010 12:23 PM UTC
- Apr 23, 2014 08:51 AM UTC