Merge PDF documents into single file using Aspose.PDF for .NET - JavaScript Validation is not working in output

Hi,

I am try to merge a PDF (provided by client) having JavaScript validation for the fields in PDF, with another PDF (secure or non secure) using Aspose.PDF. But the merged PDF does not have JavaScript Validation on the fields. Please suggest how to retain validation while merging two PDF’s.

Thanks
Pankaj Toshniwal

@PankajToshiwal

Would you kindly share sample PDF document(s) for our reference. We will test the scenario in our environment and address it accordingly.

@asad.ali

Please find the code we used to merged the PDF as attachment. The ‘PDF_With_Validation’ PDF file is the one having JavaScript validation for the fields. The ‘Sample_PDF’ PDF file is a sample pdf we are merging with ‘PDF_With_Validation’ file to get a new merged file. The ‘Merged’ is the resultant file after merging the above mentioned files, and this ‘Merged’ does not have that JavaScript validation for the fields that ‘PDF_With_Validation’ file have.

MergedPdfCode.zip (990.8 KB)

@PankajToshiwal

We were able to reproduce the issue in our environment while using Aspose.PDF for .NET 20.4 and have logged it as PDFNET-48020 in our issue tracking system. We will further work on it and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hey Asad,

Is this a product issue and require update to the code? or do we a work around to have this working in our project. This is time sensitive and we need to deliver on this asap.

THanks
Jagdeep

@jagdeep.walia

Yes, the issue is detected in the API and has been logged for correction. We are afraid that we cannot offer any workaround until it is investigated. The issue has been logged under free/normal support model and has low priority. It will be resolved on a first come first serve basis. However, you can check our paid support option in case the issue is a blocker for you and needs to be resolved on an urgent basis. We will surely inform you as soon as we have additional updates in this regard. Please spare us some time.

We are sorry for the inconvenience.

Unfortunately we are unable to use the product until this is fixed and we request to please have this taken on priority and not force us to use paid subscription for a product related bug. Our project is on hold due to the product bug. If unable to help, please provide appropriate channel to discuss this issue as why we should be paying for an issue which is product related

@jagdeep.walia

We surely value your concerns and would like to share with you that we have logged your concerns and escalated the issue to next level. We will definitely consider your concerns during investigation of the issue and inform you as soon as we make some significant progress towards ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-48020) have been fixed in Aspose.PDF for .NET 20.5.

hi @asad.ali,

We have updated the DLL with the latest one and merged the file again. But the issue still persist. On click of master checkbox, it doesn’t allow clicking the child check-boxes. I have attached the image of the issue and the new merged pdf using the Aspose.PDF 20.5. I had already attached the code sample of our approach earlier. Please let us know if any change is required in our approach.

Please look into this asap.MergedPDFIssue.zip (569.9 KB)

@PankajToshiwal

Please use following code snippet to concatenate PDF file and preserve actions:

   PdfFileEditor pfe = new PdfFileEditor();
   pfe.KeepActions = true;
   pfe.Concatenate("sample-pdf.pdf", "pdf-with-validation.pdf", "result.pdf");

In case you still face any issue, please feel free to let us know.

Hi @asad.ali,

We have tried the given code snippet to merge the PDF’s but its working only when we put
“pdf-with-validation.pdf” as first file and then merge some other PDF as second file. When we put “pdf-with-validation.pdf” as second file and try to merge the file in that case issue still persist. The correct order for our requirement is put any PDF as first file and then put “pdf-with-validation.pdf” as second file and merge them. In this case the issue mentioned still exist.

Please suggest.

@PankajToshiwal

We have tested the scenario in our environment with Aspose.PDF for .NET 20.5 and were unable to notice any issue. We tried both orders during concatenation and attached are the files we obtained in which validation is working.

resultVS.pdf (1.1 MB)
resultSV.pdf (1.1 MB)

SV = "sample + validation
VS = "validation + sample"

Hi @asad.ali,
I have checked the files that you have attached and the issue that i have mentioned “On click of master checkbox, it doesn’t allow clicking the child check-boxes” is also exist in your file “resultSV.pdf”. I am attaching issue image. Please suggest.

resultSV_Issue.PNG (36.5 KB)

@PankajToshiwal

We will surely investigate this and share investigation results with you as soon as it is complete.

hi @asad.ali,

Any update?

@PankajToshiwal

We have further investigated the scenario and found that it is not a Bug. Your document Pdf_With_Validation contains JavaScript code which manages field validation, field visibility, etc. Please find the full JavaScript code in attached 48020.js.48020.zip (40.7 KB)

A problematic checkbox field has name chk1a and its dependent checkboxes are chl1a1, chk1a2, chk1a3. The issue is in javascript code placed in CS90_Custom section. Function validchk() contains the following code:

function validchk(ball) {
    //function handleme2(hidefield,startfield,hideifvalue,emptyval,req) {
    //function handleme(hidefield,startfield,hideifnotvalue,emptyval,req) {
    if (this.pageNum == 1 || ball) {
        var q = 0;
        if (ball || trigger.name == "chkP_1") {
            //participant
            handleme2("TailleP_1", "chkP_1", "Off", "", true);
            handleme2("TailleUP_1", "chkP_1", "Off", "Off", true);
            handleme2("PoidsP_1", "chkP_1", "Off", "", true);
            handleme2("PoidsUP_1", "chkP_1", "Off", "Off", true);
            handleme2("SexeP_1", "chkP_1", "Off", "Off", true);
......................
    if (this.pageNum == 0 || ball) {

        this.getField("ParticipantNom_1").value = trim(this.getField("ParticipantNom_0").valueAsString + " " + this.getField("ParticipantPrenom_0").valueAsString);
        this.getField("Police_1").value = this.getField("Police_0").value;
        this.getField("Certificat_1").value = this.getField("Certificat_0").value;

        if (ball || trigger.name == "chk1a") {
            handleme2("chk1a1", "chk1a", "Off", "Off", false);
            handleme2("chk1a2", "chk1a", "Off", "Off", false);
            handleme2("chk1a3", "chk1a", "Off", "Off", false);
        }
.......

Please note that block for field “chk1a” (if (ball || trigger.name == “chk1a”)…) if placed inside block " if (this.pageNum == 0 || ball) {"
This, this condition will work ONLY when this field is on the first page (its number is 0 in JavaScript code since internal page indexes are zero-based). After concatenation, this.pageNum = 1 for this field which causes incorrect work of this function (and other validation which is dependent of page).

In order to demonstrate this, we modified JavaScript code of the document by replacing condition : “if (this.pageNum == 1 || ball)” instead of “if (this.pageNum == 0 || ball)”.

Please check the attached document PDF-with-validation-modified.pdf. We also added app.alert which shows this.pageNum value. You can see that checkbox does not work properly in the document but it will work if you concatenate this document with another one, placing the validation document in second place.

Thus, in order to fix the issue, JavaScript code in your document should be fixed in order to make it independent of the page number.

Pdf-with-validation-modified.pdf (634.5 KB)

Hi @asad.ali,

Thanks for the update.