Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







Recently, we had a customer who wanted to create a PDF that would automatically prompt the user to print the document. Our initial suggestion involved adding a "JavaScript PDF action" to the "open" event of the document.
using System;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;
namespace Create_Auto_Print_PDF {
class Program {
static void Main(string[] args) {
PDFDocument doc = new PDFDocument();
// Use this statement to make the viewer application display
// the Print dialog and allow the user to specify the print settings
doc.AddOpenActionJavaScript("this.print();");
// Use the following statement (instead of the previous one)
// to make the viewer application attempt to silently print the
// document (to the default printer using default settings).
// Note: There still will be a confirmation dialog prompt to the user
doc.AddOpenActionJavaScript("this.print(false);");
doc.WriteText("This PDF will attempt to print itself when you open it.");
doc.Save("Auto_Print_PDF1.pdf");
doc.Close();
}
}
}
Our customer came back saying that the document worked fine in AdobeĀ® Reader but not in another PDF viewer. Even in Adobe Reader, the document may not have worked as intended if JavaScript scripting was turned off.
Our alternative solution involves the use of "print named action" in place of the JavaScript action.
using System;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;
namespace Create_Auto_Print_PDF {
class Program {
static void Main(string[] args) {
PDFDocument doc = new PDFDocument();
doc.AddOpenActionNamed(PDFActionName.Print);
doc.WriteText("This PDF will attempt to print itself when you open it.");
doc.Save("Auto_Print_PDF2.pdf");
doc.Close();
}
}
}
When we checked, the second PDF document worked as intended in both viewers. However, we would like to introduce a caveat here that the "print" and several other named actions available in PDFOne .NET are undocumented features* that are supported by Adobe Reader.
* - As of PDF Reference Version 1.7.
---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).