Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 842
jack.cap.rooney Avatar asked Jan 22 '15 15:01

jack.cap.rooney


1 Answers

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:

  • Here <ESC> denotes the escape character (27 in decimal, 1B in hex).
  • <CR> denotes the carriage return character (13 in dec, 0D in hex). It is optional within PJL.
  • <LF> denotes the line feed charaxter (10 in dec, 0A in hex). It is required within PJL.
  • <ESC>%-12345X denotes the 'Universal Exit Language' command (UEL). It is required in PJL. It defines beginning and end of any PJL-based data stream.

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.

like image 84
Kurt Pfeifle Avatar answered Oct 27 '22 21:10

Kurt Pfeifle