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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:48:39+00:00 2026-05-20T17:48:39+00:00

I’m using iText to generate a PDF document that consists of several copies of

  • 0

I’m using iText to generate a PDF document that consists of several copies of almost the same information.

E.g.: An invoice. One copy is given to the customer, another is filed and a third one is given to an accountant for book-keeping.

All the copies must be exactly the same except for a little piece of text that indicates who is the copy to (Customer, Accounting, File, …).

There are two possible scenarios (I don’t know if the solution is the same for both of them):

a) Each copy goes in a different page.

b) All the copies goes in the same page (the paper will have cutting holes to separete copies).

There will be a wrapper or helper class which uses iText to generate the PDF in order to be able to do something like var pdf = HelperClass.CreateDocument(DocuemntInfo info);. The multiple-copies problem will be solved inside this wrapper/helper.

What does iText provides to accomplish this? Do I need to write each element in the document several times in different positions/pages? Or does iText provide some way to write one copy to the document and then copy it to other position/page?


Note: It’s a .Net project, but I tagged the question with both java and c# because this qustion is about how to use iText properly the answer will help both laguage developers.

  • 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-20T17:48:40+00:00Added an answer on May 20, 2026 at 5:48 pm

    Here’s how I see this working.

    PdfReader reader = new PdfReader( templatePDFPath );
    Document doc = new Document();
    PdfWriter writer = PdfWriter.createInstance( doc, new FileOutputStream("blah.pdf" ) );
    
    PdfImportedPage inputPage = writer.getImportedPage( reader, 1 );
    
    PdfDirectContent curPageContent = writer.getDirectContent();
    
    String extraStuff[] = getExtraStuff();
    
    for (String stuff : extraStuff) {
      curPageContent.saveState();
      curPageContent.addTemplate( inputPage /*, x, y*/ );
      curPageContent.restoreState();
    
      curPageContent.beginText();
      curPageContent.setTextMatrix(x, y);
      curPageContent.setFontAndSize( someFont, someSize );
    
      // the actual work:
      curPageContent.showText( stuff );
    
      curPageContent.EndText();       
    
      // save the contents of curPageContent out to the file and reset it for the next page.
      doc.newPage();
    }
    

    That’s the bare minimum of work on the computer’s part. Quite Efficient, and it’ll result in a smaller PDF. Rather than having N copies of that page, with tweaks, you have one copy of that page that’s reused on N pages, with little tweaks on top.

    You could do the same thing, and use the “x,y” parameters in addTemplate to draw them all on the same page. Up to you.

    PS: you’ll need to figure out the coordinates for setTextMatrix in advance.

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

Sidebar

Related Questions

No related questions found

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.