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

  • SEARCH
  • Home
  • 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 8902843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:42:59+00:00 2026-06-15T01:42:59+00:00

I’m trying to add some strings, images and tables into my pdf file (there

  • 0

I’m trying to add some strings, images and tables into my pdf file (there have to be several pages) but when i try to use ColumnText (I use this because I want to place strings at absolute positions), I encounter a problem.
When the column height is not sufficient to add the content of the strings, the content is incomplete. How can I avoid that content gets lost?

Here’s the related code :

try {
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    String imageUrl = "/Users/nofear/workspace/deneme23/pics/a4-ust.png";
    String imageUrlAlt = "pics/a4-alt.png";
    Image imageust = null;
    Image imageAlt = null;
    try {
        imageust = Image.getInstance(imageUrl);
        imageAlt = Image.getInstance(imageUrlAlt);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("HEIGHT"
        + (document.getPageSize().getHeight() - imageust.getHeight()));
    imageust.setAbsolutePosition(0f,
        document.getPageSize().getHeight() - imageust.getHeight()-10);
    imageAlt.setAbsolutePosition( 0f, 10f);
    document.add(imageust);
    document.add(imageAlt);
    // now draw a line below the headline
    cb.setLineWidth(1f); 
    cb.moveTo(0, 200);
    cb.lineTo(200, 200);
    cb.stroke();
    // first define a standard font for our text
    Font helvetica8BoldBlue = FontFactory.getFont(FontFactory.HELVETICA,16);
    // create a column object
    ColumnText ct = new ColumnText(cb);
    // define the text to print in the column
    Phrase myText = new Phrase("Very Very Long String!!!" , helvetica8BoldBlue);
    ct.setSimpleColumn(myText, 60, 750,
        /* width*/document.getPageSize().getWidth() - 40, 100,
        20, Element.ALIGN_LEFT);
    ct.go();
} catch (Exception e) {
} finally {
    document.close();
}
  • 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-15T01:43:00+00:00Added an answer on June 15, 2026 at 1:43 am

    There are three options:

    1. Either you provide a bigger rectangle, so that the content fits inside,
    2. or you reduce the content (e.g. smaller font, less text),…
    3. Keep the size of the rectangle, keep the font size, etc… but add the content that doesn’t fit on the next page.

    How do you know if the content doesn’t fit?

    You can add the content in simulation mode first, and test if all the content was ‘consumed’:

    int status = ct.go(true);
    boolean fits = !ColumnText.hasMoreText(status);
    

    Based on the value of fits, you can decide to change the size of the rectangle or the content. There’s an example that shows how to do this: http://itextpdf.com/examples/iia.php?id=163

    If you can distribute the content over different pages, you don’t need simulation mode, you just need to insert a document.newPage();

    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(rect);
    int status = ct.go();
    while (ColumnText.hasMoreText(status)) {
        document.newPage();
        ct.setSimpleColumn(rect);
        status = ct.go();
    }
    

    In this example rect contains the coordinates of the rectangle.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a reasonable size flat file database of text documents mostly saved in

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.