user3388946
user3388946

Reputation: 49

iText filling multi pages with same textfields

I know there is already some information online but I don't get it.

My case: I'm having a PDF of 10 pages, all page contains the same form. When I'm using my code, only the first page is filled out and the others are still blank. If I checked the field names in Adobe Livecycle, they are all the same of the different pages.

What should I do in my case to fill all the pages and not only the fist one?

My code:

//Pagecount == 10
//I was trying to loop through the pages, no success
for(int i=1; i<=pageCount; i++){    
    form.setField("RecallID", wdContext.currentGetRecallDetailsResponseOutputElement().getRecallid());
    form.setField("Afdeling", afdeling);

    String type = wdContext.currentGetRecallDetailsResponseOutputElement().getType();
    if(type.equals("D"))form.setField("Type", "DESTRUCTION");
    else if(type.equals("B"))form.setField("Type", "BLOCK");


    form.setField("Description", wdContext.currentGetRecallDetailsResponseOutputElement().getDescription());
    form.setField("CreationDate",sdf.format(wdContext.currentGetRecallDetailsResponseOutputElement().getCreationdate()));
    form.setField("Enddate", sdf.format(wdContext.currentGetRecallDetailsResponseOutputElement().getEnddate()));

    form.setField("Acties", wdContext.currentGetRecallDetailsResponseOutputElement().getAction_Nl());
    form.setField("Actions", wdContext.currentGetRecallDetailsResponseOutputElement().getAction_Fr());

    form.setField("Probleem", wdContext.currentGetRecallDetailsResponseOutputElement().getProblem_Nl());
    form.setField("Probleme", wdContext.currentGetRecallDetailsResponseOutputElement().getProblem_Fr());

}

stamper.setFormFlattening(true);
stamper.close();

Upvotes: 0

Views: 1618

Answers (2)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Please take a look at the FillFlattenMerge2 example. This example is explained in this video tutorial: https://www.youtube.com/watch?v=6YwDME0Fl1c (if you follow the tutorial, you'll understand why FillFlattenMerge1 is an example on how NOT to do it.)

Document document = new Document();
PdfCopy copy = new PdfSmartCopy(document, new FileOutputStream(dest));
document.open();
ByteArrayOutputStream baos;
PdfReader reader;
PdfStamper stamper;
AcroFields fields;
for (int i = 0; i < data.length; i++) {
    // create a PDF in memory
    baos = new ByteArrayOutputStream();
    reader = new PdfReader(SRC);
    stamper = new PdfStamper(reader, baos);
    fields = stamper.getAcroFields();
    tokenizer = new StringTokenizer(line, ";");
    fields.setField("name", data[i].getName());
    ...
    stamper.setFormFlattening(true);
    stamper.close();
    reader.close();
    // add the PDF to PdfCopy
    reader = new PdfReader(baos.toByteArray());
    copy.addDocument(reader);
    reader.close();
}
br.close();
document.close();

You can see the example in action here: http://demo.itextsupport.com/itextsamples/ (Click on the link "How to do it correctly" next to "Fill, flatten and merge").

Upvotes: 1

Ninad Pingale
Ninad Pingale

Reputation: 7069

Create an object of form inside loop.

Also check pageCount if it is 1.

Upvotes: 0

Related Questions