Image in between a paragraph Using iText

2019-04-11 00:40发布

问题:

I am using iText to generate my custom .pdf document. I tried a lot but i am not able to do get a desired design of my text which includes an image. I need an output just like shown below:

I have tried Chunk class and Paragraph class but i am not able to get the desired. Any ideas?

回答1:

You have (at least) two options:

  1. Use image.setAlignment(Image.LEFT | Image.TEXTWRAP); and add the image to the document (not to a Chunk or Paragraph). This will add the image to the left and wrap the other text around it.
  2. Add the image at an absolute position, and add the text using ColumnText for irregular columns: http://1t3xt.be/?0b3

1 is the easiest way, but the result may not always be what you desire (you can tweak some things, such as adding a borden); 2 demands more work, but allows you to create the output exactly the way you want to.