Note that there are some explanatory texts on larger screens.

plurals
  1. POmPDF auto print issue
    text
    copied!<p>I'm using a php class, mpdf, which generates PDF's very nicely. I'm trying to get the file to automatically print (i.e., open the print dialog) when rendered. I've extended the core functioning with the code below to add javascript to the pdf. The pdf is rendered but without auto-printing. Any help would be great. Thanks!</p> <pre><code> require('mpdf.php'); class PDF_JavaScript extends mPDF { var $javascript; var $n_js; function IncludeJS($script) { $this-&gt;javascript=$script; } function _putjavascript() { $this-&gt;_newobj(); $this-&gt;n_js=$this-&gt;n; $this-&gt;_out('&lt;&lt;'); $this-&gt;_out('/Names [(EmbeddedJS) '.($this-&gt;n+1).' 0 R]'); $this-&gt;_out('&gt;&gt;'); $this-&gt;_out('endobj'); $this-&gt;_newobj(); $this-&gt;_out('&lt;&lt;'); $this-&gt;_out('/S /JavaScript'); $this-&gt;_out('/JS '.$this-&gt;_textstring($this-&gt;javascript)); $this-&gt;_out('&gt;&gt;'); $this-&gt;_out('endobj'); } function _putresources() { parent::_putresources(); if (!empty($this-&gt;javascript)) { $this-&gt;_putjavascript(); } } function _putcatalog() { parent::_putcatalog(); if (!empty($this-&gt;javascript)) { $this-&gt;_out('/Names &lt;&lt;/JavaScript '.($this-&gt;n_js).' 0 R&gt;&gt;'); } } } class PDF_AutoPrint extends PDF_Javascript { function AutoPrint($dialog=false) { //Embed some JavaScript to show the print dialog or start printing immediately $param=($dialog ? 'true' : 'false'); $script="print($param);"; $this-&gt;IncludeJS($script); } } $mpdf = new PDF_AutoPrint('', 'Letter', 0, '', 12.7, 12.7, 14, 12.7, 8, 8); $stylesheet = file_get_contents('eabill.css'); $mpdf-&gt;WriteHTML($stylesheet,1); $mpdf-&gt;WriteHTML($message,2); $mpdf-&gt;AutoPrint(true); $mpdf-&gt;Output(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload