The best practice depends on what you want to do. The first case places the 
image with the dimensions you choosed, it may overflow or not, you must know 
what you are doing. The second case scales the image automatically to the cell 
size, it's convenient but you have no flexibility.

Paulo 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of GAMBELLI Raffaele
> Sent: Thursday, October 18, 2007 8:03 AM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Image size inside PdfPCell
> 
> I'm sorry but your short answer doesn't help us to explain 
> that strangeness documented in the first post.
> If in your plans it is normal that one time the image is 
> scaled to fit a rectangle and one time the image isn't 
> scaled, at least give us a best practice to add images to pdfPcells.
> 
> Thanks, best regards.
> Raffaele
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] 
> Behalf Of Paulo
> Soares
> Sent: mercoledì 17 ottobre 2007 17.54
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Image size inside PdfPCell
> 
> 
> The first case is a shorthand to new Chunk(image, 0, 0) and 
> behaves as expected.
> 
> Paulo
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED] On 
> > Behalf Of GAMBELLI Raffaele
> > Sent: Wednesday, October 17, 2007 4:34 PM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Image size inside PdfPCell
> > 
> > This is very strange:
> > 
> > Consider an image of 800x600, use for test that in attachment
> > 
> > If I do
> > ...
> > PdfPCell itextCell = new PdfPCell(image);
> > table.addCell(itextCell);
> > 
> > The image goes out of the cell BUT IF I DO:
> > ...
> > PdfPCell itextCell = new PdfPCell();
> > itextCell.setImage(image)
> > table.addCell(itextCell);
> > 
> > Then it works and the image fits correctly the cell.
> > 
> > Perhaps setImage is intended for cell's background?
> > 
> > But why with the first snippet of code doesn't it work?
> > Thanks, best regards.
> > Raffaele
> > 
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] 
> > Behalf Of Paulo
> > Soares
> > Sent: mercoledì 17 ottobre 2007 17.00
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Image size inside PdfPCell
> > 
> > 
> > addCell(Image) will always scale the image to fit the cell. 
> > You can have
> > scaling with the PdfPCell constructors or with 
> PdfPCell.addElement().
> > 
> > Paulo
> > 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] 
> > > [mailto:[EMAIL PROTECTED] On 
> > > Behalf Of GAMBELLI Raffaele
> > > Sent: Wednesday, October 17, 2007 2:16 PM
> > > To: iText-questions@lists.sourceforge.net
> > > Subject: [iText-questions] Image size inside PdfPCell
> > > 
> > > Hi all,
> > > 
> > > In the following code I simply put an image in the document, 
> > > and then in the next page I put the same image inside a 
> > > PdfPCell, although I'm using jpg1.setWidthPercentage(0); why 
> > > does the image inside PdfPCell result bigger than the other one?
> > > 
> > > Thanks, regards.
> > > Raffaele
> > > 
> > > 
> > > public static void main(String[] args) {
> > >         
> > >         System.out.println("Scaling an Image");
> > >         
> > >         // step 1: creation of a document-object
> > >         Document document = new Document();
> > >         
> > >         try {
> > >             
> > >             // step 2:
> > >             // we create a writer that listens to the document
> > >             // and directs a PDF-stream to a file
> > >             
> > >             Format formatter = new 
> > > SimpleDateFormat("yyyyMMddmmss");            
> > >                   String outputFileName = "scaling_" + 
> > > formatter.format(new Date(System.currentTimeMillis())) + ".pdf";
> > >             PdfWriter.getInstance(document, new 
> > > FileOutputStream("pdf/scaling/" + outputFileName));
> > >             
> > >             // step 3: we open the document
> > >             document.open();
> > >             
> > >             // step 4: we add content
> > >             String image = "images/otsoe.jpg";
> > >             
> > >                   Image jpg1 = Image.getInstance(image);
> > >                   
> > >                   document.add(new Paragraph("Original 
> > > size --> (" + jpg1.getWidth() + ", " + jpg1.getHeight() + ")" ));
> > >                   document.add(jpg1);
> > >                   
> > >                   document.newPage();
> > >                   
> > >                   PdfPTable pdfPTable = new PdfPTable(1);
> > >                   pdfPTable.addCell("Original size --> (" 
> > > + jpg1.getWidth() + ", " + jpg1.getHeight() + ")");
> > >                   jpg1.setWidthPercentage(0);
> > >                   pdfPTable.addCell(jpg1);
> > >                   document.add(pdfPTable);                        
> > > 
> > >         }
> > >         catch(DocumentException de) {
> > >             System.err.println(de.getMessage());
> > >         }
> > >         catch(IOException ioe) {
> > >             System.err.println(ioe.getMessage());
> > >         }
> > >         
> > >         // step 5: we close the document
> > >         document.close();
> > >     }


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to