Hello, using Aspose.PDF .NET 19.12, I’m trying to add document-level Javascript to a PDF. Here is the code:
using (Document document = new Document(new FileStream(path, FileMode.Open, FileAccess.ReadWrite)))
{
document.JavaScript["hello"] = "function hello(){ app.alert('hello world'); }";
document.Save();
}
And here is the error I get:
System.InvalidOperationException
HResult=0x80131509
Message=Value could be added only to leaf
Source=Aspose.PDF
StackTrace:
at #=z_uXQUUTOD1x0nWp6D5Ny5DdYGhgbieGG9A==.#=zpbagGsk=(#=zFuVY$ug5e0MI6nubBkMDBMp0k6Hkv$K22g== #=zgMzEBeY=, #=zFuVY$ug5e0MI6nubBkMDBMp0k6Hkv$K22g== #=zgRwocA0=)
at Aspose.Pdf.JavaScriptCollection.#=z7VQd2Js=(#=zDfrLeQu7MCbAmnqNqqTFh7dI979_v2ogUg== #=zWIK7VNA=, String #=zgMzEBeY=, #=zFuVY$ug5e0MI6nubBkMDBMp0k6Hkv$K22g== #=zgRwocA0=)
at Aspose.Pdf.JavaScriptCollection.set_Item(String key, String value)
at AddJavascriptToPDF.AddJavascriptToPDF.Add(String path) in D:\...\AddJavascriptToPDF.cs:line 44
at AddJavascriptToPDF.Program.Main(String[] args) in D:\...\Program.cs:line 24
If I have some existing Javascript in the document, Aspose.PDF will add the hello script correctly, but not if I am adding new document-level Javascript to the document.
The PDF is a simple form with an input text field and a digital signature.