Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:24:50+00:00 2026-06-10T12:24:50+00:00

I’m creating the 3 columns layout with iText java lib. The biggest problem is

  • 0

I’m creating the 3 columns layout with iText java lib.

The biggest problem is that, that the text in the first column could be less than in the second column or third or less in the second column than third column. So I need to move the insertion point to the next column.

I tried to use nextColumn method which should move insertion point to the
next column but it moves all columns to the right side.

Maybe anyone had the same issue and know how to do it right?

Thanks for answers!

The image below shows what I want it.
columns layout

UPDATE:

Ok I’ll try to rephrase the question.

Here is the code how I declare 3 columns:

MultiColumnText columnsFooter = new MultiColumnText(210f);
columnsFooter.addRegularColumns(document.left() - 10f,
    document.right(), 0, 3);
columnsFooter.setAlignment(Element.ALIGN_CENTER);

I have 3 columns with headers and some text in each column. The text depends on how much text the user entered today. If the user filled the text limit is OK because the first column is filled and second text goes to second column (second text starts from second column).

But if the user don’t fill the text limit on the first column or second column the next starts writing from the column which are not fully filled up.

I.e.

This is okay because the first and the second columns are fully filled up.

enter image description here

This is bad because the first column are not fully filled up and second column text starts from the first column. So I need to add column break before HEADER 2 and 3 to get a good layout structure if the text are not fully filled up.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:24:52+00:00Added an answer on June 10, 2026 at 12:24 pm

    Can you rephrase the question? Because I don’t understand it. What is an insertion point?
    I wrote the book about iText, and I can do pretty much anything I want to do with ColumnText, so it may be in your interest to clarify what you want.

    The question is still unclear, but the picture says a thousand words. I’ve made you an example with 4 columns and 5 articles:

        import java.io.FileOutputStream;
    import java.io.IOException;
    
    import com.itextpdf.text.Document;
    import com.itextpdf.text.DocumentException;
    import com.itextpdf.text.PageSize;
    import com.itextpdf.text.Paragraph;
    import com.itextpdf.text.pdf.ColumnText;
    import com.itextpdf.text.pdf.PdfWriter;
    
    
    public class ColumnTextExample {
    
    
        /** Definition of four columns */
        public static final float[][] COLUMNS = {
            { 36, 36, 224, 579 } , { 230, 36, 418, 579 },
            { 424, 36, 612, 579 } , { 618, 36, 806, 579 }
        };
    
        public static final String ARTICLE1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
        public static final String ARTICLE2 = ARTICLE1 + " " + ARTICLE1 + " " + ARTICLE1;
        public static final String ARTICLE3 = ARTICLE1 + " " + ARTICLE1;
    public static final String[] ARTICLES = { "HEADER 1\n" + ARTICLE1, "HEADER 2\n" + ARTICLE2, "HEADER 3\n" + ARTICLE3, "HEADER 4\n" + ARTICLE1, "HEADER 5\n" + ARTICLE3 };
    
        public static void main(String[] args) throws IOException, DocumentException {
            // step 1
            Document document = new Document(PageSize.A4.rotate());
            // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("columns.pdf"));
            // step 3
            document.open();
            // step 4
            ColumnText ct = new ColumnText(writer.getDirectContent());
            int column = 0;
            ct.setSimpleColumn(
                COLUMNS[column][0], COLUMNS[column][1],
                COLUMNS[column][2], COLUMNS[column][3]);
            int status = ColumnText.START_COLUMN;
            for (String article : ARTICLES) {
                ct.addElement(new Paragraph(article));
                status = ct.go();
                while (ColumnText.hasMoreText(status)) {
                    column = nextColumn(document, column, ct);
                    status = ct.go();
                }
                column = nextColumn(document, column, ct);
            }
            // step 5
            document.close();
        }
    
        public static int nextColumn(Document document, int column, ColumnText ct) {
            column = (column + 1) % 4;
            if (column == 0)
                document.newPage();
            ct.setSimpleColumn(
                    COLUMNS[column][0], COLUMNS[column][1],
                    COLUMNS[column][2], COLUMNS[column][3]);
            return column;
        }
    }
    

    The first article fits the first column, leaving half a column open. We skip to the next column for the second article. That doesn’t fit the second column: it takes one column and a half. The third article fits the fourth column, but we need to skip to the next page for the fourth article, and so on…
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.