Not able get the check if pdf has Javascript

Hello,
I am not able to detect if the pdf has the Javascript. I have attached a sample pdf file for your reference

In code I am checking for the Javascript.Keys. if the count >0 then I decide it has the javascript for my validation.

 IList keys = (System.Collections.IList)pdfdoc.JavaScript.Keys

For this pdf file this is throwing null reference exception.

Exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.

Sample pdf file
'PDF for B48.pdf (54.4 KB)

@sidcode

We have been able to reproduce the issue in our environment when we tested the scenario using Aspose.PDF for .NET 21.3. Hence, have logged it as PDFNET-49747 in our issue tracking system. We will further look into its details and keep you posted with its resolution status. Please be patient and spare us little time.

We apologize for your inconvenience.

@asad.ali

When this issue can be resolved? We have a Product release So we are expecting a solution before 15th of May’21.
It would be good if you provide us the resolution date So that I can plan accordingly .

With Regards,
Sid

@sidcode

The issue has recently been logged in our issue tracking system and is pending for initial review. It will be investigated and resolved on a first come first serve basis. We are afraid that we cannot share any tentative timeline for the issue fix before it is fully investigated. However, we have recorded your concerns and will surely update you once we have additional updates in this regard. Please spare us some time.

We apologize for the inconvenience.

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

@aspose.notifier problem still persists.
I tried with your new dll. Please find the attached screen shot.

image.png (47.7 KB)

@sidcode

We were able to notice that the exception was fixed which was thrown by the API but JavaScript was still unable to be detected in 21.5 version of the API. Therefore, another ticket as PDFNET-49932 has been logged in our issue tracking system for the sake of correction. We will let you know once it is resolved. Please give us some time,

We apologize for your inconvenience.

Hi @asad.ali
I am seeing that the ticket is closed. Just wanted to know in which version of Aspose this fix is available.

With Regards,
Sid

@sidcode

Please try to use Aspose.PDF for .NET 21.10 in order to prevent the issue that was logged. Please also note that Document may contain JavaScript in a several clauses:

  • directly in the document;
  • actions of page;
  • annotations of page;

To get all JavaScript you need to check all of this points.

    Document pdfdoc = new Document(dataDir + "PDF for B48.pdf");
    var keys = (System.Collections.IList)pdfdoc.JavaScript.Keys;
    //search JavaScript in actions of page
    List<JavascriptAction> javaScript= new List<JavascriptAction>();
    var onOpenAction = pdfdoc.Pages[1].Actions.OnOpen;
    var onCloseAction = pdfdoc.Pages[1].Actions.OnClose;

    if (onOpenAction!= null&& onOpenAction is JavascriptAction)
        javaScript.Add((JavascriptAction)onOpenAction);

    if(onCloseAction!=null&&onCloseAction is JavascriptAction)
        javaScript.Add((JavascriptAction)onCloseAction);

    //search JavaScript in annotations of page
    foreach (var annotations in pdfdoc.Pages[1].Annotations)
    {
        foreach (var action in annotations.Actions)
        {
            if(action is JavascriptAction)
                javaScript.Add((JavascriptAction)action);
        }
    }