See http://itextdocs.lowagie.com/tutorial/objects/tables/index.php or page 178
of the book.
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of [EMAIL PROTECTED]
> Sent: Monday, August 11, 2008 5:07 PM
> To: [email protected]
> Subject: [iText-questions] Image in PdfPTable - scaleToFit not working
>
> 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;
> }
>
> }
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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