Print, Kiosk Printing and PDF
Applications created with ExeOutput for PHP can print webpages directly to a printer or save them as PDF files.
You can customize some properties of the printing process via the "Printer" component.
Print Preview¶
By default, print preview is enabled. This means that end users will see the following dialog box when they select Print:
Tip
You can disable the Print Preview by setting EnablePrintPreview to false in the "Printer" component.
Direct Print or Kiosk Printing¶
ExeOutput for PHP allows you to print directly to the default printer without prompting the end user, a feature known as kiosk printing.
To enable kiosk printing, edit the "Printer" component and ensure EnablePrintPreview is set to false and EnableKioskPrint is set to true.
Programmatically Enable or Disable Kiosk Printing / Print Preview¶
It is possible to enable and disable kiosk printing and/or print preview at runtime using JavaScript, PHP, or HEScript.
The following global variables are used internally by the PHP application to control kiosk printing or print preview. You can change their values to modify the behavior.
Variable Name | Description |
---|---|
PrintPreviewEnabled | 1 or 0. If 1, print preview is enabled. |
KioskPrintEnabled | 1 or 0. If 1, kiosk printing is enabled. |
For example, the following code enables kiosk printing at runtime. Simply add this HEScript code to the UserMain script:
procedure EnableKiosk;
begin
SetGlobalVar("KioskPrintEnabled", "1", false);
SetGlobalVar("KioskPrintCopies", "1", false);
SetGlobalVar("PrintPreviewEnabled", "0", false);
end;
The same functionality in JavaScript:
<script language="JavaScript">
exeoutput.SetGlobalVariable('KioskPrintEnabled', '1', false);
exeoutput.SetGlobalVariable('KioskPrintCopies', '1', false);
exeoutput.SetGlobalVariable('PrintPreviewEnabled', '0', false);
</script>
Print to PDF¶
You can allow end users to export the current webpage as a PDF. For example, clicking the Print to PDF button will prompt the end user for the filename of the PDF file, which will then be saved to that location.
Programmatically save directly to a PDF file¶
You can use the PrintPDF and PrintPDFFile HEScript functions.
-
PrintPDF will perform the same action as described above (clicking the Print to PDF button).
-
PrintPDFFile will export the PDF directly to the file you specify.
For example, the following code will export the current webpage as a PDF file. The PDF file is named "mydoc.pdf" and stored inthe current user's My Documents folder. Just add this HEScript code to the UserMain script:
procedure ExportPDFSample;
var
S: String;
begin
S := GetGlobalVar("HEMyDocDirectory", "C:") + "\mydoc.pdf";
PrintPDFFile(S);
end;
Another possibility with JavaScript: window.exportPDF(pdffilename) is a JavaScript extension available in ExeOutput apps. This allows you to export the content of the window as a PDF file.
pdffilename
enables you to pass the full path and filename of the PDF file to be exported.
For example:
<script language="javascript">
// Callback for save dialog box - content contains the full path to the future PDF file.
function DemoSavePDF(content) {
if (content === "") return;
window.exportPDF(content);
}
function exportpdf() {
// Run HEScript script SavePDFDlgFile defined in UserMain to get the PDF filename.
exeoutput.GetHEScriptCom('hescript://UserMain.SavePDFDlgFile', DemoSavePDF);
}
</script>