2

I'm using the following Java code to fill an pdf Template with itext

    PdfReader pdfTemplate = getPdfReader(templateFile);
    PdfStamper stamper = new PdfStamper(pdfTemplate, writer);
    stamper.getAcroFields().setField("#ID", "1");
    stamper.getAcroFields().setField("#value", "27");
    stamper.getAcroFields().setField("#valuexxx", "99");
    stamper.setFormFlattening(true);
// TODO Dynamic Table
    stamper.close();
    pdfTemplate.close();

an now my problem:

I would replace an textfield in the PDF with a Table dynamic length.

I've tryed

    float[] fieldPosition= pdfTemplate.getAcroFields().getFieldPositions("tableField");
    PdfPTable table = buildTable();
    PdfContentByte cb = stamper.getOverContent(1); 
    table.writeSelectedRows(0, -1, fieldPosition[1],fieldPosition[4],cb);

this works fine but when after the field is some content the table "overides it", the secound problem is when the table has more rows than the page can hold.

Has someone a good idea how to realy replace a field and rebuild the following document?

Christian A.
  • 157
  • 1
  • 12
  • I'm having the same problem over here: http://stackoverflow.com/questions/12364926/insert-pdfptable-into-exsting-pdf-template. Hav found some more resources in my question which may help... but since my pdf only has a handful of simple elements, we're thinking of generating the whole thing on the fly now. Spent two solid days looking for an elegant solution, no luck so far. – Joe Sep 12 '12 at 00:58

0 Answers0