Mathieu Mallet wrote:
Heya,I'm trying to display multiple images on a single line in iText in order to replicate the behavior of a web renderer. I tried to do this by wrapping the images in Chunk object, which are themselves placed in the same Paragraph object. However, when there are a lot of images to be displayed, the images get clipped at the bottom of the page. What am I doing wrong? How can I prevent this?
OK, I'm back and I'll start where I left off yesterday. I don't know if you followed the advice I gave you yesterday. If not, please try the example in attachment. If you remove the following line from the code sample:paragraph.setLeading(Math.max(img1.getScaledHeight(), img2.getScaledHeight()));
you get the undesired effect you were described. In other words: you can prevent this by setting the leading of the paragraph to the maximum height of the images. (That's what I meant with my remark yesterday.) br, Bruno
import java.io.FileOutputStream; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; public class ImageInChunk { public static void main(String[] args) { try { new ImageInChunk().run(); System.out.println("Generation done."); } catch (final Exception e) { e.printStackTrace(); } } public void run() throws Exception { // Setup document Document doc = new Document(PageSize.LETTER); PdfWriter.getInstance(doc, new FileOutputStream("image_in_chunk.pdf")); doc.open(); Image img1 = Image.getInstance("logo.gif"); img1.scalePercent(75); Image img2 = Image.getInstance("1t3xt.gif"); // Create pdf document Paragraph paragraph = new Paragraph(); paragraph.setLeading(Math.max(img1.getScaledHeight(), img2.getScaledHeight())); for (int i = 0; i < 20; i++) { paragraph.add(new Chunk(img1, 0, 0, true)); paragraph.add(new Chunk(img2, 0, 0, true)); paragraph.add(new Chunk(img2, 0, 0, true)); } doc.add(paragraph); doc.close(); } }
<<inline: 1t3xt.gif>>
<<inline: logo.gif>>
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ 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/