phppdfzend-frameworkpjl

Add PJL command into PDF file with PHP code


How can I insert a PJL command into PDF without having to convert PDF to PostScript

*STARTPJL
@PJL SET STAPLE=LEFTTOP
*ENDPJL

after I send it to printer via FTP or LPR.

I'm using Zend_Pdf to create PDF documents.

**I tried unsuccessfully this code

$a .= "<ESC>%-12345X@PJL<CR><LF>";
$a .= "@PJL SET OUTBIN=OUTBIN101<CR><LF>";
$a .= "@PJL SET STAPLE=LEFTTOP<CR><LF>";
$a .= "@PJL ENTER LANGUAGE = PDF<CR><LF>";
$a .= file_get_contents("/www/zendsvr/htdocs/GDA/public/pdf/test.pdf");
$a .= "<ESC>%-12345X";

$myfile = fopen("/www/zendsvr/htdocs/GDA/public/pdf/t.pdf", "w");
fwrite($myfile, $a);
fclose($myfile);

the document is printed correctly but does not change the drawe and not clamp, any suggestions?


Solution

  • I'm not going to explain how to achieve the following points with PHP. These points merely explain the most important fundamentals to be familiar with when dealing with PJL and with PJL regarding PDF-based print jobs. You have to 'translate' this generic info to PHP yourself....


    You cannot insert PJL commands into PDF. But you can prepend PJL commands to a PDF print job.

    Also, it is not meaningful to do this after you send it to a printer via FTP or via LPR. It is only meaningful if you do it before sending the file.

    Next, your example PJL code is not valid for most purposes. The standard way to prepend PJL lines to a PDF print job file is this:

    <ESC>%-12345X@PJL<CR><LF>
    @PJL SET STAPLE=LEFTTOP<CR><LF>
    @PJL    [... more PJL commands if required ...]
    @PJL ENTER LANGUAGE = PDF<CR><LF>
    [... all bytes of the PDF file, starting with '%PDF-1.' ...]
    [... all bytes of the PDF file ............................]
    [... all bytes of the PDF file ............................]
    [... all bytes of the PDF file, ending with '%%EOF' .......]
    <ESC>%-12345X
    

    Explanations:

    Lastly, please note:

    1. Not all printers and not all LPR print services are able to deal with PDF-based print jobs.

    2. Also, not all printers and not all LPR print services are able to honor PJL commands which are prepended to print job files.