How to split iText Paragraph into multiple columns

2019-06-02 10:22发布

问题:

Is there any way I can split Paragraph data into multiple columns?

Current Paragraph

 Something in the paragraph which need to read by the end user.

Required Paragraph

Something in     ---------      to read by
the paragraph    ---------      the end user.
which need       ---------

Basically user wants to read shorter lines rather than a long line.

I am using itextpdf-5.4.4.jar Paragraph to display data.

Thanks for you help

回答1:

Please read my answer to the question How to draw a rectangle around multiline text for which I've written DrawRectangleAroundText.

In this example, we have a Paragraph with plenty of text:

Paragraph p = new Paragraph("This is a long paragraph that doesn't"
    + "fit the width we defined for the simple column of the"
    + "ColumnText object, so it will be distributed over several"
    + "lines (and we don't know in advance how many).");

And we distribute this paragraph over different lines like this:

For this purpose, we use the ColumnText class:

ct = new ColumnText(cb);
ct.setSimpleColumn(300f, 500f, 430f, 780f);
ct.addElement(p);
ct.go();

This is only a simple proof of concept. For more info about ColumnText, read the section Absolute positioning of text in the free ebook The Best iText Questions on StackOverflow. This way, you'll be able to avoid posting a question that can be answered by recycling an answer that was posted less than a day ago.



标签: itext