0

Am using WAMP and the printer name is one on the LAN or even on a USB and is present in my devices and printers. This is working when I use "printer_draw_text" to print texts in the code. The problem is just with files. I have the following code which apparently doesnt print files but sends the job to the printer, as it just prints blanks. The file contents are not being printed. Where or what am I missing?

    <?php
    $handle = printer_open("NameHere");
    printer_start_doc($handle, "doc");
    printer_start_page($handle);
    $filename="test.docx";
    $fhandle=fopen($filename, "rb");
    $contents = fread($fhandle, filesize($filename));
    fclose($fhandle);
    printer_set_option($handle, PRINTER_MODE, "RAW");
    printer_write($handle,$contents);
    printer_end_page($handle);
    printer_end_doc($handle);
    printer_close($handle);
    ?>
emmal mbwe
  • 31
  • 7
  • You know that this is going to a printer connected to the server, not the client, right? – Barmar Jan 10 '19 at 06:48
  • @Barmar I dont really understand. Am using WAMP and the printer name is one on the LAN or even on a USB and is present in my devices and printers. This is working when I use "printer_draw_text" to print texts in the code. The problem is just with files. – emmal mbwe Jan 10 '19 at 07:00
  • What directory is the file in? Try using the full pathname? – Barmar Jan 10 '19 at 07:01
  • In the www folder for everthing else. Thanks – emmal mbwe Jan 10 '19 at 07:05
  • Well, you can't open .docx files with fopen and put it directly in printer_write function. printer_write accepts text as second parameter, and .docx file is not saved as plain text. – Boshentz Jan 10 '19 at 07:44
  • @Boshentz Really! How can we handle such files without opening them? – emmal mbwe Jan 10 '19 at 07:53
  • I'm not sure it is possible. There is group of printer_* functions that draws shapes, sets font, adds bmp image, etc... I don't know anyone who made "converter" from docx to this functions group. https://secure.php.net/manual/pl/ref.printer.php – Boshentz Jan 10 '19 at 08:21

0 Answers0