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

Filed under:

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):

alt text

And here is a screen of the output pdf:

alt text

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

Related posts about itextsharp