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

Free Support Forum - aspose.com

Javascript in PDF not working in Adobe Acrobat Reader

Hello,

I'm trying to add some javascript to a pdf document. I created a simple test case to test it.

When I open the PDF file in Acrobat Professional (Version 8.1.0) the javascript works like expected.

However when I open it in Acrobat Reader (Version 8.1.1 or Version 9.0.0) the javascript doesn't display.

Could somebody explain why? I'm using Aspose.Pdf 3.9.0.0

Source code:

Pdf mypdf = new Pdf();

Aspose.Pdf.Section sec1 = mypdf.Sections.Add();
sec1.Paragraphs.Add(new Text("Hello World"));

String str = "";

str += "var inch = 72;";
str += "for (var p = 0; p < this.numPages ; p++) {";
str += "var aRect = this.getPageBox( {nPage: p} );";
str += "aRect[0] = 540.0;";
str += "aRect[1] = 0.0;";
str += "aRect[2] = 576.0;";
str += "aRect[3] = 792;";
str += "var f = this.addField(\"PrintField\" + p, \"text\", p, aRect);";
str += "f.delay = false;";
str += "f.print = true;";
str += "f.hidden = false;";
str += "f.rotation = 90;";
str += "f.textSize = 10;";
str += "f.textFont = font.HelvB;";
str += "f.textColor = color.red;";
str += "f.alignment = \"right\";";
str += "f.readonly = true;";
str += "f.value = \"aaaa\";";
str += "}";

mypdf.JavaScripts = new JavaScripts();
mypdf.JavaScripts.Add( str );

mypdf.Save( "c:\\test.pdf" );

I found the problem, addField is not possible in Adobe Acrobat Reader.

So this problem is solved.