PDF Flattening and JavaScript

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v8)  /  PDF Flattening and JavaScript

DynamicPDF CoreSuite for .NET (v8) Forum

 Feb 04 2016 2:59 PM
I am collecting information from a web application, placing this information into a PDF template that contains JavaScript to populate/calculate many of the other data fields of the document. When the PDF is saved in a flattened format, the JavaScript to calculate many of the fields is removed resulting in those data items being 0 or not filled out. Is there a way to retain the JavaScript for a flattened PDF? The customer wants the data fields locked, i.e. the cursor can not be placed in the field. Flattening does this but marking the data field as read-only does not. The cursor can still be placed in the field, albeit, the value can not be changed. So, whatever implementation meets that need would be the desire. Thanks!
 Feb 04 2016 4:51 PM
Posted by a ceTe Software moderator
Hello,

It is not possible to retain the form field java script during flattening. The goal of fattening a PDF form is to remove the form field and replace it with a static label that contains form field data. When the form is flattened, any java script that is associated with the form field is removed along with the form field itself. If you want the java script to work, the only option is to keep the form field and make it read-only.


Thanks,
ceTe Software Support Team.


 Feb 04 2016 5:28 PM
Is there an alternate implementation so that the cursor cannot enter a specific field? I tried onfocus and setting the cursor to a specific field but the field flashed and on double click I was ultimately able to enter the read only field. Can't change it, but I can enter it.
 Feb 05 2016 4:50 PM
Posted by a ceTe Software moderator
Hello,

Our library does not have any alternate implementation available that will prevent the cursor from entering the read-only form field.

Some PDF viewers may allow the user to enter the read-only field and some may not and all this depends on how that specific PDF viewer is designed. Our product does not have any control over how a specific PDF viewer behaves with respect to the read-only form fields.

Thanks,
ceTe Software Support Team.
 Feb 25 2016 3:26 PM
Shouldn't the form retain the calculated JavaScript field even though it has been flattened. I understand that the JavaScript is lost as well as the field meta-data. As an example, field A=10, field B=15, field C (JavaScript calculated) = 25. Flatten form, A=10, B=10, C=0. Is this correct behavior? Thanks again!
 Feb 25 2016 3:35 PM
Typo B=15
 Feb 26 2016 8:46 AM
Posted by a ceTe Software moderator
Hello,

Please send over the following information to support@cete.com. We would need to take a look at this info in order to provide you with appropriate feedback for your last question.

1. Input PDF template used.
2. Code used to fill and flatten the PDF template.
3. Output PDF. 

Thanks,
ceTe Software Support Team.
 Feb 29 2016 4:57 PM
Posted by a ceTe Software moderator
Hello,

We have reviewed the information you sent. In the example you have described in your previous forum post; the form field C (or the calculate field value) will be zero after flattening and that is the correct behavior. The reason for this is; the javascript calculations are executed when the PDF is opened in a PDF viewer and not when the PDF is loaded and flattened in memory. Since the form fields and their associated java script are removed during flattening, when the resulting (flattened) PDF is opened in a PDF viewer the value will show up as zero.

The only way to retain those javascript calculated field values is to do the calculation manually in C# code and assign the value to that field before you flatten the PDF.

            PdfDocument pdfTemplate = new PdfDocument(@"c:\ceTe\UnFlattened_Zero.pdf");
            MergeDocument document = new MergeDocument(pdfTemplate)
            {
                InitialPageZoom = PageZoom.FitWidth,
                PdfFormat = PdfFormat.SinglePass
            };

            //Calculate the field value manually here and assign the resulting value to the field.
            document.Form.Fields["TOTAL1[0]"].Value = "$10.50";

            document.Form.Output = FormOutput.Flatten;
            document.InitialPage = 1;

            document.Draw(@"c:\ceTe\Flattened_Zero.pdf");


Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 1:13 AM.