A scaled image inside PdfPTable is shown at wrong position in 5.1.1 version (it is not contained inside the cell). Same example works fine in 5.0.6 version.
import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import com.itextpdf.text.Document; import com.itextpdf.text.Font; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; public class PdfImageTest { public static void main(String arg[]) { try { Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, new FileOutputStream("tablePDF.pdf")); document.open(); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); byte[] imageBytes = getImage(); Image pdfImage = Image.getInstance(imageBytes); System.out.println(pdfImage + " : " + imageBytes.length ); float factor = 72f * 50 / (getDPI() * 100); pdfImage.scaleAbsolute(259 * factor, 28 * factor); PdfPCell cell = new PdfPCell(pdfImage); cell.setColspan(3); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setUseDescender(true); cell.setMinimumHeight(12); table.addCell(cell); Font font = FontFactory.getFont(FontFactory.TIMES, 10); cell = new PdfPCell(new Phrase("X", font)); cell.setMinimumHeight(12); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("T", font)); cell.setColspan(3); table.addCell(cell); document.add(table); document.close(); } catch (Exception ex) { ex.printStackTrace(); } } public static byte[] getImage() throws IOException { InputStream is = new FileInputStream("logo.png"); ByteArrayOutputStream img_bytes = new ByteArrayOutputStream(); int b; try { while ((b = is.read()) != -1) { img_bytes.write(b); } } finally { is.close(); } return img_bytes.toByteArray(); } public static int getDPI() { return GraphicsEnvironment.isHeadless() ? 96 : Toolkit.getDefaultToolkit().getScreenResolution(); } } -- View this message in context: http://itext-general.2136553.n4.nabble.com/Image-inside-PdfPTable-iText-5-1-1-versus-iText-5-0-6-tp3632511p3632511.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php