¿Cómo calcular el tamaño de imagen correcto en nuestro PDF usando itextsharp?
Estoy tratando de agregar una imagen a un pdf usando itextsharp, independientemente del tamaño de la imagen, siempre parece estar asignada a un tamaño mayor diferente dentro del pdf.
La imagen que agrego es de 624x500 píxeles (DPI: 72):
texto alternativo http://www.freeimagehosting.net/uploads/727711dc70.png
Y aquí hay una pantalla del pdf de salida:
texto alternativo http://www.freeimagehosting.net/uploads/313d49044d.png
Y así es como creé el documento:
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();
¿Alguna idea sobre cómo calcular el tamaño correcto?
Ya probé ScaleAbsolute y la imagen todavía se muestra con dimensiones incorrectas.