We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

C++ Aspose::Pdf::Facades::PdfJavaScriptStripper System::NullReferenceException

I am using version 20.9 of the Aspose.Pdf for C++ Linux.

I am trying to strip Javascript from a PDF and whenever I run the Strip() method in the PdfJavaScriptStripper class, I get a System::NullReferenceException.

The following is my code to execute:

System::String path = System::String::FromUtf8(argv[1]);
System::String outputpath = path + u"-cleaned";

Console::WriteLine(u"Path: {0}",path);

Console::WriteLine(u"Output Path: {0}",outputpath);
auto stripper = MakeObject<Aspose::Pdf::Facades::PdfJavaScriptStripper>();
bool cleaned = stripper->Strip(path,outputpath);

The value passed into the application is “calendar.pdf”. I’ve validated that if I don’t execute the Strip() function I get all the metadata returned from the PDF and no other execeptions. It is only when I run the strip() do I get the exeception. I’ve also validated that I can execute the method ToString() against the stripper object after it is constructed, so the stripper object is not null.

I’ve also tried to run against multiple PDFs with scripts and all fail. I’m also outputting in my application if the PDF has javascript and the library is outputting true for the hasJavascript property for the PDF.

Additionally, I am also having an issue retrieving the javascript from a PDF once I get the key back.

I am able to get the key by using

 auto javascript = doc->get_JavaScript();
auto keys = javascript->get_Keys();
 auto val = keys->idx_get(0);

Console::WriteLine(u"Value: {0}",val);  //this outputs the key to the console.

 System::String script = javascript->idx_get(val);  //this throws an exception of System::NullReferenceException

@sulox45

Could you please share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.

The files I’ve been testing with are available at https://www.pdfscripting.com/public/Free-Sample-PDF-Files-with-scripts.cfm.

The main one I’ve tested with that give me the error is JavaScript Popup Calendar.

Thanks,

Matt

@sulox45

We have logged an issue as PDFCPP-1440 in our issue management system for the sake of further investigation. 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 apologize for the inconvenience.

OKay thanks.