1T3XT info wrote:
> bthorington wrote:
>
>> Hello,
>>
>> I've been trying to figure out how to put HTML (converted to PDF) into
>> form fields in an existing PDF. I have been able to put images and
>> normal text.
>>
>> I can even convert the HTML into its own PDF file (using HTMLWorker.)
>> Again, I can't see how to load a PDF into a form field on another PDF.
>> Is this possible??? If it is, could you send me some pseudo code as to
>> how one might do it?
>>
>
> If you want to prefill the form (and end up with a PDF that
> still has a form), you're out of luck. If it's your intention
> to flatten the form, you are very close with HTMLWorker.
>
> Instead of using setField(), use getFieldPositions() and use
> the coordinates you retrieved as boundaries for a ColumnText
> object. Feed the ColumnText object with the objects obtained
> with HTMLWorker and go().
>
>
I was able to get it to work but I had to upgrade to the latest version
of iText.
Here is some code for anyone who cares:
AcroFields form = stamp.getAcroFields();
float[] textPos = form.getFieldPositions("ffName");
Rectangle rect = new Rectangle((float)0.0,
(float)0.0, textPos[3] - textPos[1], textPos[4] - textPos[2]);
String tempFileLocation = HTLMtoPDF(rect,
"<html><body><b>hello world</b></body></html>); // use the HTMLWorker
to convert HTML string into a temp PDF file..
PdfReader subReader = new
PdfReader(tempFileLocation);
PdfImportedPage page =
stamp.getImportedPage(subReader,1);
/*this is the template way... */
stamp.getOverContent((int)
textPos[0]).addTemplate(page, textPos[1], textPos[2]);
/* or you can do it by image... this lets you
resize if you want */
Image img = Image.getInstance(page);
img.setAlignment(Image.ALIGN_CENTER);
img.setAbsolutePosition(textPos[1],
textPos[2]);
stamp.getOverContent((int)
textPos[0]).addImage(img);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar