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

Free Support Forum - aspose.com

Adding Javascript an existing PDF file

Hi I have a pdf file and I want to see printdialog when client users click the document.

I use the following code


fs = new FileStream(su.MapPath("../../QDMSFiles/TEMPFOL/") + tempFileName, System.IO.FileMode.Open);

Byte[] buffer = new Byte[fs.Length];

fs.Read(buffer, 0, (



contentEditor = new PdfContentEditor();



Rectangle rectangle = new System.Drawing.Rectangle(100, 100, 200, 200);


"this.print({bUI:true,bSilent:false,bShrinkToFit:true});", new System.Drawing.Rectangle(0, 0, 100, 100), 1, System.Drawing.Color.Red);// save updated PDF document



But printdialog appears when I click rectangle I want to see print dialog when pdf load

Hi there,

Thanks for your inquiry. You can add JavaScript to OpenAction() method of document class for the desired results. Please check following code snippet. Hopefully it will serve the purpose.

Document doc = new Document(myDir+“test.pdf”);
doc.OpenAction = new JavascriptAction(“this.print({bUI:true,bSilent:false,bShrinkToFit:true});”);
doc.Save(myDir + “JavaScript_Output.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,