Print pdf file on printer by IP in PHP

278 Views Asked by At

I have pdf file on server. And I need pass it to printer by IP and print. I have Windows and dont have printer , but my boss's site has Linux and printer (star emae printer). So he will get me IP address and I need pass pdf file to that printer.

I tried use PDFtoPrinter.exe and other tools.

I tried this:

$printerIP = entity_configuration::getConfigValue('printer_ip');
        echo "Printer IP = ".$printerIP.'<br>';
        $fileToPrint = $_SERVER["DOCUMENT_ROOT"]."/receipts/".CLIENT_ID."/receipt.pdf";
        if(file_exists($fileToPrint)){
            echo "Yes, we have file here:".$fileToPrint.'<br>';
        }
        if (strpos(strtolower(PHP_OS), 'win') !== false) {
            exec("print /D:\"$printerIP\" \"$fileToPrint\"", $output, $returnCode);
        } else {
            exec("lpr -P '$printerIP' -r '$fileToPrint'", $output, $returnCode);
        }
        obj_dump($output);
        if ($returnCode === 0) {
            echo "Print job submitted successfully.";
        } else {
            echo "Failed to submit the print job.";
        }

PDFtoPrinter.exe opens printer dialog for enter file name (and then save in Documents , think because i use virtual printer). Not sure how it will work with real IP. I need have auto name for file.

using exec("$pathLib $fileToPrint /s "$printerIP""); I dont see result, any errors but also dont see any files in Documents folder. And not sure is lpr command correct?

Please help me if you worked with it. Thanks.

0

There are 0 best solutions below