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 = MakeObjectAspose::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