skip to Main Content

I would like to automatically print labels locally via a website using silent print. My PHP script running with XAMPP on Windows.

<?php
ob_end_clean();
ignore_user_abort();
ob_start();
header("Connection: close");
header("Content-Length: " . ob_get_length());
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: https://xxx");
ob_end_flush();
flush();

$target = __DIR__ . "\testToPrintDyn.pdf";
move_uploaded_file($_FILES['file']['tmp_name'], $target);

$printer = $_POST['printer'];

$commandText = '"C:\Program Files (x86)\Foxit Software\Foxit PDF Reader\FoxitPDFReader.exe" /t "'.$target.'" "'.$printer.'"';

file_put_contents("print.txt", $commandText);

shell_exec($commandText);
?>

Running this script, the label will be printed 90° rotated. When I copy the content of the "print.txt" manually to the command line, everything is printed well. using "exec" ends in the same 90° result.

Does anyone have any ideas on how I can proceed here to get closer to the problem? Thank you very much!

2

Answers


  1. Chosen as BEST ANSWER

    I'm a big step further. I normally start the httpd.exe via Windows Autostart. If I stop the running Apache server and start the same file manually with admin rights, then printing works. If I create httpd.exe as a "task scheduler" with admin rights, then it doesn't work either. But for me this is a much more tangible problem than a rotating PDF page when printing :-D so I'll have to read up a bit more on how to autostart Apache with the right admin rights.


  2. If you want to print from PHP to a label printer, do not use the software supplied. Instead print raw to the port (virtual or otherwise) that the printer uses.

    If you printer is USB, set it up as a network enabled printer, set the share name, and that’s what you print to.

    I recently wrote an offline label print webpage for a company who couldn’t print labels when the network went down.

    HTH

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search