I have a .NET project that allows users to enter some text and select and
image and then generates a new PDF by plugging in the user-supplied values
into text box fields in a source PDF file. We are currently using
ActivePDF's PDF Toolkit product, but would like to switch to iTextSharp.
Currently, I have a prototype using iTextSharp that works beautifully in
populating text into the text box fields. However, I am running into some
difficulty in populating an image into a text box field. With ActivePDF's
PDF Toolkit, we add an image to a field using the following code:
*toolkitObject*.SetFormFieldData(*fieldName*, *fullPathToImageFile*, -995)
That *-995* somehow is what tells PDF Toolkit that an image is being
supplied, and PDF Toolkit adds the image and resizes it to fit within the
bounding fields of the text box field *fieldName*.
How do I do this in iTextSharp? I did some Googling and came up with this
article, which seems pretty spot on:
http://coolwebdeveloper.com/2008/10/how-to-use-itextsharp-net-pdf-library-to-insert-text-and-image-in-an-existing-pdf-form-template/
In it, the author presents code that (presumably) creates an *Image* object,
determines the position of the text box field, resizes the image, and then
adds the image to that field. I say "presumably" because the code seems to
have some errors (perhaps he is using an earlier version of iTextSharp). For
instance, there is this line of code to determine the field position:
float[] imageArea = testForm.GetFieldPositions(”testImage1″);
(Here, *testForm* is an AcroFields object.) However, when I examine
the *GetFieldPositions
*method, it tells me it returns an *IList<FieldPosition>*, not an array of
floats.
I'm at a bit of a loss as to what to do here and would appreciate any
guidance.
Thanks!
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/