Issue reading and updating Javascript

I am having an issue reading the javascript from a PDF created by our CAD system. I can view and update the javascript manually in Adobe Pro but when I attempt to use Aspose I can read the keys of the javascripts but not the contents themselves. When I attempt to retrieve the contents I get a null reference exception.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Aspose.Pdf.JavaScriptCollection.get_Item(String key)

I test the same code with a basic PDF I create in adobe and I am able to read the contents no problem.

Below is a sample program I made to read and log the contents of both PDFs. I attached a zip with all the data required to recreate the error. In the zip is a sample PDF from the CAD system (TestModel.pdf), the basic PDF I created in adobe(TestPdf.pdf), and the log from running the program. To test send the path of this folder as the only arg to the program. It will also need a license file, I did not include ours.

This has all been tested with the latest Nuget package.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

using Aspose.Pdf;

namespace JavascriptTest
{
    class Program
    {
        static List<string> Log = new List<string>();
        static void Main(string[] args)
        {
            var dataDir = args[0];

            try
            {
                var licensepath = $"{dataDir}\\Aspose.PDF.NET.lic";
                License license = new License();
                using (FileStream fs = new FileStream(licensepath, FileMode.Open))
                {
                    license.SetLicense(fs);
                }
                Log.Add("License set");

                ListJavascripts($"{dataDir}\\TestPdf.pdf");
                ListJavascripts($"{dataDir}\\TestModel.pdf");
            }
            catch (Exception ex)
            {
                Log.Add(ex.ToString());
            }
            finally 
            {
                File.WriteAllLines($"{dataDir}\\log.txt", Log);
            }
        }

        static void ListJavascripts(string path)
        {
            var doc = new Document(path);

            Log.Add("Listing document javascripts");
            IList keys = (IList)doc.JavaScript.Keys;
            Log.Add($"{keys.Count} Javascripts found.");

            foreach (string key in keys)
            {
                try
                {
                    Log.Add($"{key}\n{doc.JavaScript[key]}\n");
                }
                catch (Exception ex)
                {
                    Log.Add($"Error retrieving contents of {key}.\n{ex}");
                }
            }
            doc.Dispose();
        }
    }
}

Data.7z (512.6 KB)

@Alexander96856

We tested the scenario using Aspose.PDF for .NET 22.11 and did not notice any issues. The API was able to extract the JavaScript Keys. image.png (42.7 KB)

Would you please confirm if you have tested with 22.11 version? In case issue is still persisting, please share a sample console application that is able to reproduce the issue. We will again test the scenario in our environment and address it accordingly.

I am also able to see the keys, but I cannot see the text of the keys.

I have tested in 22.11 (I included that in the original post).

I already included a sample console app both in the text of the post and in the attached data zip.

@Alexander96856

We have logged an issue as PDFNET-53151 in our issue tracking for further investigation on this case. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

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