I tried to insert a scaled image in a PdfPTable-Cell but the scaling was
not taken over.
I set up a demo file .
Thanks in advance for your help.
Regards,
Andreas
---- snip ---
public class PDFDemo {
public static void main(String[] args) throws Exception {
new PDFDemo();
}
public PDFDemo() throws Exception {
File f = new File("c://test.pdf");
Document document = new Document(PageSize.A4, 40, 40, 60, 50);
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(f));
writer.setStrictImageSequence(true);
document.open();
Image i = attachImage(document, new File("c://test.jpg"));
if (i != null) {
document.add(i);
}
PdfPTable table = new PdfPTable(new float[] { 10, 90 });
table.setWidthPercentage(100);
table.addCell("1st column");
if (i != null) {
table.addCell(i);
}
document.add(table);
document.close();
}
private Image attachImage(Document document, File f) throws Exception {
Image img = Image.getInstance(f.getAbsolutePath());
// half of the pagewidth and half of the height
float myWidth = (document.getPageSize().getWidth() -
document.leftMargin() - document.rightMargin()) / 2;
float myHeight = (document.getPageSize().getHeight() -
document.topMargin() - document.bottomMargin()) / 2;
img.scaleToFit(myWidth, myHeight);
return img;
}
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php