Add PJL command into PDF file with PHP code

这一生的挚爱 提交于 2020-01-29 07:54:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28093063/add-pjl-command-into-pdf-file-with-php-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!