Hello,
I was wondering if it is possible to specify an open action (to be more specific: make sure the print dialog is opened automatically when the pdf document is opened) using DynamicPDF.
I've been searching through the documentation but could not find anything. According to the PDF reference the "openaction" should be an entry in the document catalog.
Create an open action for a pdf
Re: Create an open action for a pdf
Support · Apr 28, 2011Hello,
You can achieve your requirement by adding document level JavaScript to the PDF document using our DynamicPDF product. This will open a dialog box saying "This document is trying to print. Do you want to allow this?". Below is the sample code for it.
ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
string text = "Hello ASPX C# World...\nFrom DynamicPDF™ Generator for NET\nDynamicPDF.com";
Label label = new Label(text, 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center);
// Adding Javascript to the document
DocumentJavaScript javaScript = new DocumentJavaScript("Test", "this.print({bUI: false, bSilent: false, bShrinkToFit: true});");
document.JavaScripts.Add(javaScript);
page.Elements.Add(label);
document.Pages.Add(page);
document.Draw(@"C:/MyDocument.pdf");
Thanks,
ceTe Software Support Team.
Re: Create an open action for a pdf
Forum member · Apr 28, 2011hello,
thank you for the quick reply. I've tested something like this before and indeed noticed the dialog box. However, I have an example pdf in which this box does not appear, but a normal print dialog opens. Is this also possible?
Re: Create an open action for a pdf
Support · Apr 28, 2011Hello,
You may have to use some JavaScript which can open a normal print dialog and add this JavaScript to the document using our DynamicPDF product. There is no direct method or property in our API which will open a print dialog while opening the PDF document.
Thanks,
ceTe Software Support Team.
Re: Create an open action for a pdf
Forum member · Apr 28, 2011thank you very much. I've managed to open the regular print dialog using the following code:
Dim objDoc As New ceTe.DynamicPDF.Merger.MergeDocument("c:\temp\pdf.pdf", New ceTe.DynamicPDF.Merger.MergeOptions())
objDoc.JavaScripts.Add(New ceTe.DynamicPDF.DocumentJavaScript("print", "app.setTimeOut('print()',100)"))
objDoc.Draw("c:\temp\javascript.pdf")
The timeout makes sure document is actually displayed before the dialog is opened.