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 6556673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:58:30+00:00 2026-05-25T12:58:30+00:00

I am working with the iText library to do some PDF manipulation in Java,

  • 0

I am working with the iText library to do some PDF manipulation in Java, but I am trying to do something in which the iText API is starting to overwhelm me. I really just need a quick tutorial, or some pseudo-code, but here is what I am trying to accomplish:

  1. User selects a series of check boxes, indicating which PDFs he or she wishes to print.
  2. Based on user input, grab 1 – x PDF template files. Each page has a series of AcroFields which need to be filled out.
  3. One such page requires drawing some custom graphics on the PDF, i.e. accessing the PdfContentByte object and manipulating that to insert images and rectangles.
  4. If it possible, I would like to avoid writing temporary PDFs to disk. The previous programmer did this, and it has been messy to deal with that. I’d much prefer to grab the template file, manipulate it in memory and serve it directly to the browser.

I seem to have all the pieces, but I can’t quite put it all together. Point #4 is what’s been really tripping me up.

TIA.

  • 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-05-25T12:58:30+00:00Added an answer on May 25, 2026 at 12:58 pm

    So, here is the answer I was finally able to come up with:

    //Open an input stream to the PDF template
    InputStream is = getInputStreamToEachFile();
    
    
    //Declare a document object, as well as a PdfCopy for
    //copying in each PdfFile we open in memory and edit.
    Document doc = new Document();
    PdfCopy copy = new PdfCopy(doc, outputStreamToBrowser);
    
    
    //Be sure to open the document or it will throw an exception!
    doc.open();
    
    
    //Since the PdfStamper class wants to output everything to an
    //output stream you can declare a ByteArrayOutputStream object
    //and direct it there, since we need to tack on more PDFs and
    //can't just output to the response's output stream directly.
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    PdfStamper stamper = new PdfStamper(new PdfReader(is), byteStream);
    
    
    //Pseduocode - set form fields - just check out
    //the documentation for AcroFields in the API
    //this part is easy.
    ...
    
    
    //if form has custom graphics declare a PdfContentByte array
    //the 1 argument in the getUnderContent refers to the page number
    
    PdfContentByte cb = stamper.getUnderContent(1);
    
    //pseduocode - do custom graphics. This can be a lot of different things,
    //so check the documentation
    ...
    
    
    //Wrap things up - set the dyanamic form fields to read only
    //and call the stamper's close function to close the streams
    stamper.setFormFlatterning(true);
    stamper.close()
    
    
    //Finally, declare a new PdfReader, reading the stamper's byte array stream
    //which was declared in memory.
    PdfReader outReader = new PdfReader(byteStream.toByteArray());
    
    //Use this function call to add each page that you need. Repeat this process
    //for as many PDFs as are being stitched together.
    copy.addPage(copy.getImportedPage(outReader,1));
    
    //Finally, tell the browser you are done generating the file, and output it.
    //If there are a lot of pages being generated this way, I guess you could use the flush
    //function instead, and then call close when they are all done.
    copy.close();
    

    Thanks go out to this tutorial which I eventually found on my own:

    http://itextpdf.com/examples/iia.php?id=127

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

Sidebar

Related Questions

Working with python interactively, it's sometimes necessary to display a result which is some
I'm trying to make PDF forms (aka AcroForms) editable in Java. So far i
I am trying to silent print PDF files from within a java application (more
I am using iText API to generate RTF using Java. The RTF file is
I'm currently working on building a PDF based report in Java. I have looked
Working with some basic java apps on CentOS 5 linux and I have my
I am working on a java application, which asks for a url as input,
I'm working on an upgrade to iText to version 2.17. It's a java application,
Working with TCL and I'd like to implement something like the Strategy Pattern .
Working on some matrix code, I'm concerned of performance issues. here's how it works

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.