Announcement

Collapse
No announcement yet.

Embedded JS print action : Parameters not working

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Embedded JS print action : Parameters not working

    I've built a PDF with the following embedded JS code :
    Code:
    var pp = this.getPrintParams();
    pp.NumCopies=40;
    this.print(pp);
    This should open the print dialog box with the "Copies" field set to 40, but it doesn't work (the print dialog box opens but "Copies" is still set to 1)
    I've tried this with Adobe Acrobat Reader and it works.

    Is there another syntax to use in order to make this work ?
    Thanks.

    PS :
    I'm using Foxit Reader v9.0.1.1049, on a Windows 10 64-bit computer, and the PDF has been generated using the PHP libraries FPDF and FPDI

  • #2
    TBRea

    Could you please provide the mentioned PDF document and indicate where you embed the JS code to so we could take a closer look on our side? Thank you.
    If it is inconvenient to upload the file here, you may email to support@foxitsoftware.com. Thank you.

    Comment


    • #3
      You'll find the PDF document attached.

      The PDF document is generated via a PHP script, using the FPDF and FPDI libraries.

      Hereafter's the full PHP code :

      PHP Code:
      $file FCPATH 'assets/download/' $_GET['file'];
      include(
      'assets/fpdi/src/autoload_print.php');

      /*header('Content-type: application/pdf');
      header('Content-Disposition: inline; filename="'.$_GET['file'].'"');
      header('Cache-Control: private, max-age=0, must-revalidate');
      header('Pragma: public');*/

      $pdf = new PDF_AutoPrint();
      $pageCount $pdf->setSourceFile($file);
      for (
      $i=1$i<=$pageCount$i++) {
          
      $tplIdx $pdf->importPage($i'/MediaBox');
          
      $size $pdf->getTemplateSize($tplIdx);
          
      $pdf->addPage();
          
      $pdf->useTemplate($tplIdx00$size['width'], $size['height'], true);
      }

      $pdf->AutoPrint($_GET['qty']);
      $pdf->Output($_GET['file'], 'D'); 


      And hereafter's the code from the assets/fpdi/src/autoload_print.php file:

      PHP Code:
      use setasign\Fpdi\Fpdi;
      use 
      setasign\Fpdi\PdfReader;

      require_once(
      FCPATH 'assets/fpdf/fpdf.php');
      require_once(
      FCPATH 'assets/fpdi/src/autoload.php');

      class 
      PDF_JavaScript extends Fpdi {
          
          protected 
      $javascript;
          protected 
      $n_js;

          function 
      IncludeJS($script$isUTF8=false) {
              if(!
      $isUTF8)
                  
      $script=utf8_encode($script);
              
      $this->javascript=$script;
          }

          function 
      _putjavascript() {
              
      $this->_newobj();
              
      $this->n_js=$this->n;
              
      $this->_put('<<');
              
      $this->_put('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
              
      $this->_put('>>');
              
      $this->_put('endobj');
              
      $this->_newobj();
              
      $this->_put('<<');
              
      $this->_put('/S /JavaScript');
              
      $this->_put('/JS '.$this->_textstring($this->javascript));
              
      $this->_put('>>');
              
      $this->_put('endobj');
          }

          function 
      _putresources() {
              
      parent::_putresources();
              if (!empty(
      $this->javascript)) {
                  
      $this->_putjavascript();
              }
          }

          function 
      _putcatalog() {
              
      parent::_putcatalog();
              if (!empty(
      $this->javascript)) {
                  
      $this->_put('/Names <</JavaScript '.($this->n_js).' 0 R>>');
              }
          }
          
      }

      class 
      PDF_AutoPrint extends PDF_JavaScript {
          
          function 
      AutoPrint($qty 1) {
              
      $script '';
              
      $script .= 'var pp = this.getPrintParams();';
              
      $script .= 'pp.NumCopies=' $qty ';';
              
      $script .= 'this.print(pp);';
              
      $this->IncludeJS($script);
          }
          

      Attached Files

      Comment

      Working...
      X