You need to put some javascript inside the PDF to make the fields read only. Do 
not use formflatting.
For instance, you can put this script in an opening event of the form: for each 
field, set the read only property.
 
> Date: Fri, 7 Mar 2008 05:27:34 -0800> From: [EMAIL PROTECTED]> To: 
> [email protected]> Subject: [iText-questions] AcroFields 
> - PDFStamper - Problem with Custom Formatting on Fields> > > Hi,> > I have 
> read through a lot of posts regarding PDF stamper and have not seen a> post 
> regarding populating fields which contain custom formatting. I am not> sure 
> if I am doing this correctly so some advice or help would be> appreciated:> > 
> Background:> > Basically I am trying to stamp a field on a pre-existing PDF 
> which contains> form elements. The form element on the PDF contains some 
> simple custom> formatting as follows (JavaScript code) - In the Field 
> properties of the> form field the Custom Format Script is as follows:> > if 
> (event.value < 0.0) {> this.getField("sign").value = "-"> } else {> 
> this.getField("sign").value = " "> }> event.value = util.printf("%,0.2f", 
> Math.abs(event.value));> > The purpose of this JavaScript is to format a 
> given number as the absolute> value of the number and populate another field 
> with the sign of the number,> for example, “1234.5” would be displayed as 
> “1,234.50” in the main field and> “ “ in the sign field and “-1234.5” should 
> be displayed as “1,234.50” in the> main field and “-“ in the sign field (it’s 
> for a financial based> application).> > iText code:> > I load and populate 
> the the pre-formatted PDF as follows, the values which> are to be populated 
> are held in a HasMap (called map):> > // Create the stamper> PdfStamper 
> stamper = new PdfStamper(copyReader, out);> > // Get the fields for stamping> 
> AcroFields form = stamper.getAcroFields();> 
> form.setGenerateAppearances(true);> > // For each field in the map> for 
> (String key : map.keySet()) {> > // Set the value to the PDF> 
> form.setField(key, map.get(key));> }> > // Flatten the form - this means that 
> only the data is> displayed, not the form entry fields> 
> stamper.setFormFlattening(true);> > // Close the stamper> stamper.close();> > 
> Problem:> > When I open the PDF which is created the custom formatting has 
> not been> applied. Example, if I set the field to a value of “-1234.5” the 
> PDF> displays “-1234.5” rather than the formatted values (“1,234.50” and 
> “-“). I> have noticed that this is also the case for other fields which use> 
> “standard” formatting (i.e. not custom formatting). These fields also seem> 
> to show the unformatted value.> > Setting the “setFormFlattening(false)” 
> statement displays the values> correctly on the PDF, however, I require the 
> fields to be protected (this is> a read only version of the document, the 
> users are not allowed to update the> information). I have also been able to 
> set the protected flag on the> underlying form field, this does not have any 
> effect on the outcome (i.e.> the formatting has not taken place).> > Has 
> anyone else seen this problem? I am currently using iText version 2.0.7,> and 
> viewing the PDFs using Acrobat Reader 8.1> > Thanks,> > Bino> > > -- > View 
> this message in context: 
> http://www.nabble.com/AcroFields---PDFStamper---Problem-with-Custom-Formatting-on-Fields-tp15891169p15891169.html>
>  Sent from the iText - General mailing list archive at Nabble.com.> > > 
> -------------------------------------------------------------------------> 
> 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> Buy the iText 
> book: http://itext.ugent.be/itext-in-action/
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------------------------------------------------------------------
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
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to