Reputation: 390
I'm dealing with a printer that can accept an escape code (i.e. printer command) printed as normal text.
For example, if I create a plain text file and write "~TR%10 10 20 20?" then print this, the printer recognize it as a command and doesn't print that bit of text on the paper.
When I try to do this via a postscript file (created from PHP using PS module), I can't make the printer to recognize the same text as command. Instead it gets printed on paper.
Is there a PS command/format that I can use to ensure this bit of text is sent to the printer as is?
Thanks
UPDATE: I tried it with a PDF file as well (using PHP + TCPDF), but had no luck either.
UPDATE 2: Adding sample code
$ps = ps_new();
ps_open_file($ps, '/var/www/data/test.ps');
ps_set_info($ps, 'BoundingBox', '0 0 1011 638');
ps_set_info($ps, 'Orientation', 'Landscape');
ps_set_info($ps, "Creator", "PHP");
ps_set_info($ps, "Title", "Test");
ps_set_info($ps, "Keywords", "test");
ps_begin_page($ps, 1011, 638);
ps_set_parameter($ps, 'SearchPath', '/var/www/data/font');
$psfont = ps_findfont($ps, "ARIALN_0", "", 1); // Arial Narrow font
ps_setfont($ps, $psfont, 10.0);
ps_show_xy($ps, "ABC", 10, 10);
ps_show_xy($ps, "~TR%41 4 53 11?", 10, 50);
ps_end_page($ps);
ps_close($ps);
ps_delete($ps);
header('Content-type: application/postscript');
header('Content-Disposition: attachment; filename="test.ps"');
readfile('/var/www/data/test.ps');
Upvotes: 2
Views: 1972
Reputation: 19504
Well I don't really know anything about PHP, but you certainly don't want to use ps_show_x_y
. This undoubtedly maps to the postscript show
operator whose job it is to display text on the printed page.
From the docs, it looks like Just write it straight to the file, bypassing all the ps_module stuff. And as Ken says, it should be before any other postscript code if you want the printer to recognize it. In particular, it will need to be before the magic number '%!' that the printer uses to detect a postscript program and enter the appropriate mode.ps_include_file
is the method you want.
And of course, doing this will make the ps-file non-portable. gs, distiller, other printers, none of them will want to accept this as a postscript document.
As george mentions in a comment, whatever this control-code might do (which you haven't yet disclosed), might be available through the postscript side, too. The thing to do is to locate the PPD file for the printer (Postscript Printer Definition). This file contains postscript snippets to do printer-specific tasks. It's outfitted with heavy DSC comments and seemingly bizarre formatting to enable it to be parsed by program, but all this should make it easy to locate the snippet you need, assuming it is in fact available.
Upvotes: 4
Reputation: 31199
I don't see any way this is going to work. Your printer may be able to process random escape characters when its not interpreting PostScript, but it certainly won't be able to do so once you enter the PostScript interpreter.
This is because its perfectly possible to have binary data (which matches your escape character) in the body of a PostScript program. If the printer input handler processed that data instead, then the PostScript wouldn't work.
So you need to send you escape codes to the printer before the PostScript interpreter is started, or after it complete, you can't send it in the middle.
Upvotes: 2