directly print with php

前端 未结 1 1949
半阙折子戏
半阙折子戏 2021-01-07 06:22

I try to print directly with php library php_printer.dll, my problem is that my printer print strange words instead of PDF file.

Here is my code:

           


        
相关标签:
1条回答
  • 2021-01-07 07:16

    Well... your contents consists of all tags and you are giving a text type output to your printer.

    Of course it is going to print like that.

    If you want to do a straight print with only the text Write a test 20012-10-24, then you probably need to create it in another PHP file, read the output with, ie, file_get_contents and then do your printing with the results received.


    Now printing a PDF file is a totally different issue. You can print it via shell execution:

    shell_exec( 'lpr /path/to/file/filename.pdf' );
    

    Or with a PHP class found here:

    require_once( 'PrintIPP.php' );
    
    $ipp = new PrintIPP();
    $ipp->setHost( 'localhost' );
    $ipp->setPrinterURI( '/printers/epson' );
    $ipp->setData( '/path/to/file/filename.pdf' );
    
    $ipp->printJob();
    
    0 讨论(0)
提交回复
热议问题