How to calculate the correct image size in out pdf using itextsharp ?
Posted
by MK
on Stack Overflow
See other posts from Stack Overflow
or by MK
Published on 2010-05-02T07:43:38Z
Indexed on
2010/05/02
7:47 UTC
Read the original article
Hit count: 270
itextsharp
I' am trying to add an image to a pdf using itextsharp, regardless of the image size it always appears to be mapped to a different greater size inside the pdf ?
The image I add is 624x500 pixel (DPI:72):
And here is a screen of the output pdf:
And here is how I created the document:
Document document = new Document();
System.IO.MemoryStream stream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, stream);
document.Open();
System.Drawing.Image pngImage = System.Drawing.Image.FromFile("test.png");
Image pdfImage = Image.GetInstance(pngImage, System.Drawing.Imaging.ImageFormat.Png);
document.Add(pdfImage);
document.Close();
byte[] buffer = stream.GetBuffer();
FileStream fs = new FileStream("test.pdf", FileMode.Create);
fs.Write(buffer, 0, buffer.Length);
fs.Close();
Any idea why on how to calculate the correct size ?
© Stack Overflow or respective owner