iText - Hinzufügen von externen Bild mit Chunk

Ich bin neu in iText und konfrontiert mit einem wirklich interessanten Fall über das hinzufügen von externen Bildern auf einen Absatz. Hier ist die Sache:

Document document = new Document();  
PdfWriter.getInstance(document, new FileOutputStream("out2.pdf"));  
document.open();  
Paragraph p = new Paragraph();  
Image img = Image.getInstance("blablabla.jpg");  
img.setAlignment(Image.LEFT| Image.TEXTWRAP);  
//Notice the image added to the Paragraph through a Chunk
p.add(new Chunk(img2, 0, 0, true));  
document.add(p);  
Paragraph p2 = new Paragraph("Hello Worlddd!");  
document.add(p2);

gibt mir das Bild und "Hallo Worlddd!" - saite. Allerdings

Document document = new Document();  
PdfWriter.getInstance(document, new FileOutputStream("out2.pdf"));  
document.open();  
Paragraph p = new Paragraph();  
Image img = Image.getInstance("blablabla.jpg");  
img.setAlignment(Image.LEFT| Image.TEXTWRAP);  
//Notice the image added directly to the Paragraph
p.add(img);
document.add(p);  
Paragraph p2 = new Paragraph("Hello Worlddd!");  
document.add(p2);

gibt mir das Bild und den string "Hallo worlddd!" befindet sich auf der rechten Seite der Bild und eine Zeile oben.

Was ist die Logik hinter diesen Unterschied?

Es könnte nur ein Schreibfehler sein, aber in deinem ersten snippet, fügen Sie img2 statt img.

InformationsquelleAutor caca | 2012-06-20

Schreibe einen Kommentar