iText doesn't process the PDF Javascript and I don't think that you will
find anything to do it except from Adobe. If you know what the formating
will be you can set the field with the value and what will be actually
displayed, for example:
form.setField(key, "1234.5", "1,234.50");
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of binoIchi
> Sent: Friday, March 07, 2008 11:33 AM
> To: itext-questions@lists.sourceforge.net
> 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 seed this problem? I am currently using iText
> version 2.0.7,
> and viewing the PDFs using Acrobat Reader 8.1
>
> Thanks,
>
> Bino
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/