1 Reply Latest reply on Dec 20, 2017 9:55 PM by Bernd Alheit

    How to pass a parameter to PdfAction.JavaScript(jscode, stamper.Writer)

    tonyl41311646

                 // test

                  AcroFields form = stamper.AcroFields;

                  var fields = form.Fields;

                  var fieldKeys = form.Fields.Keys;

                  foreach (string fieldKey in fieldKeys)

                  {

                      if (fieldKey.Contains("timeholder"))

                      {                   

                          float[] fieldPos = form.GetFieldPositions(fieldKey);

                          var fieldLlx = fieldPos[1];

                          var fieldLly = fieldPos[2];

                          var fieldUrx = fieldPos[3];

                          var fieldUry = fieldPos[4];

                          Rectangle recTime = new Rectangle(fieldLlx, fieldLly, fieldUrx, fieldUry);

                          PushbuttonField btnTime = new PushbuttonField(stamper.Writer, recTime, "post");

                          PdfAnnotation timeButton = btnTime.Field;

                          timeButton.Action = PdfAction.JavaScript(

                            "var date = this.getField(\"03 Time timeholder\"); date.value = new Date().toLocaleTimeString();", stamper.Writer

                          );

                          stamper.AddAnnotation(timeButton, 1);

                     }

                }

                stamper.Close();

       

      The above codes work properly, my question is how to pass fieldKey to PdfAction.JavaScript() to replace "03 Time timeholder"

       

      Thanks a lots.

       

      Tony