« Return to Thread: Read and Manipulate existing PDF cont.

Re: Read and Manipulate existing PDF cont.

by Iliadis Yannis :: Rate this Message:

Reply to Author | View in Thread

Thanx for your quick reply.

I will try the XFA form and PdfPTable part to see how they work.

BTW: It seems that Acrobat Designer does't align objects correctly, even if you tell them to (Layout->Align->Left from the Designer's Menu).

2006/11/30, Bruno Lowagie (iText) <bruno@...>:
Iliad Yan wrote:

> I am sending you 2 sample attachments (both created with Acrobat
> Designer 7) of what I want to do.

Note that there is only limited support for
forms created with Designer. You also need
a very recent version of iText.

However, that's not a problem.

Let's get some source code from the book ;-)

// create a reader object
PdfReader reader = new PdfReader("temp.pdf");
// create a stamper object
PdfStamper stamper =
   new PdfStamper(reader, new FileOutputStream( "result.pdf"));
// get the form from stamper (because we are going to fill out fields)
AcroFields form = stamper.getAcroFields();
// first let's see what fields are inside:
HashMap fields = form.getFields();
for (Iterator i = fields.keySet().iterator(); i.hasNext();) {
   System.out.print(i.next());
}
// iText has found two fields:
// form1[0].Page1[0].name[0]
// form1[0].Page1[0].lastname[0]
// now let's fill those fields:
form.setField("form1[0].Page1[0].name[0]", "Doe");
form.setField("form1[0].Page1[0].lastname[0]", "John");
// the next line removes the form
stamper.setFormFlattening(true);
stamper.close();
// and we're done!

FYI: you are talking about AcroFields, but you do have
an XFA form in your PDF. This can be checked like this:

XfaForm xfa = form.getXfa();
System.err.println(xfa.isXfaPresent());

> Can you please send me a small code example on how I could create the
> entire finalOut.pdf using the iText API.

OK, the above example solves half of the problem: we have
added a first and last name (you may want to use setExtraMargin()
because I see that your fields aren't positioned very well; or
you could redesign your form).

Now you want to add subjects and grades to the document.
I suggest that you use PdfPTable (maybe wrapped in a
ColumnText object if you expect that the table will not
fit on one page).

Unfortunately iText doesn't know where it should add the table.
Either you have to take a ruler, measure the paper and calculate the
coordinates where iText can write the table (with writeSelectedRows)
or column (setSimpleColumn).
Or you redesign your form and add an extra field (for instance a
button) that marks the area where iText should draw the table.
You can then get the coordinates with getFieldPositions and
use these coordinates to draw the table or column.

br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

 « Return to Thread: Read and Manipulate existing PDF cont.