Adding the php_printer extension to php has no effect
青松哥
青松哥 2019-03-29 17:30:39
0
3
1746

Recently I want to use php to connect to the printer to print content. I have done some steps but there is no response. Please help me find the reason:

  1. I use php7.25 For the Apache version, I downloaded the latest php_printer.dll.

  2. After downloading, unzip the file and place it in the php7.25 version directory: E:\phpStudy\php\php-7.2 .5\ext

  3. To modify php.ini, I added the following sentence: extension=php_printer.dll. Then save and restart the server.

  4. Use it in PHP:

    $handle = printer_open("ZDesigner 105SL 203DPI");

    Report an error directly: Fatal error: Uncaught Error: Call to undefined function printer_open() in E:\phpStudy\WWW\test\1.php:3 Stack trace: #0 {main} thrown in E:\phpStudy\WWW\test\1.php on line 3

青松哥
青松哥

reply all(2)
秋香姐家的小书童

1. Requirements

Use PHP control to connect to the printer

Continuously print dynamic data in real time on site

2. Configuration

php operating environment is installed correctly ( Apache|Nginx + PHP)

Download the php_printer.dll extension corresponding to the php version

Add the extension file to the ext directory

Edit php.ini and add extension=php_printer.dll ;

3. Use

1. Basic code structure:

<?php$handle = printer_open('printer name');
printer_start_doc($handle, "doc name");
printer_start_page($handle);
printer_set_option($handle, PRINTER_MODE, "RAW");//具体的打印部分printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);?>

The above is the basic code structure. If printer_start_doc and printer_start_page are not specified, the printer will not print. of.

2. Introduction to printing methods of specific text and graphics

Initial setting of the printer: printer_set_option, you can set the printing mode, doc title, number of print copies, paper format, etc., refer to printer_set_option document.

Create a font: $font = printer_create_font('simsun', font height, font width, font thickness, whether it is italic, whether to underline, whether to add strikethrough, direction); see details.

Before printing text, you must first select the font printer_select_font($handle, $font);

Use printer_draw_text($handle,'text to be printed', starting x, starting y) ;

4. Pitfalls encountered

Using a server-side weakly typed scripting language to deal with hardware is originally a trivial matter, and there are many hardships in the process.

The server I started configuring on Windows was Apache. When printing, I was always unable to print out the normal size and always printed three pages in a row. Later, when I used the php command directly on the command line to run the script, I could print normally. Ultimately, the reason was that the permission to run the Apache service was changed to a normal user and changed to a super administrator, or you could log in as a super administrator.

font, some printers come with corresponding client software. But using PHP to control printer software is useless, so creating fonts is a pitfall. For the name of the font, first find the corresponding text in the windows font folder, then right-click the properties to view the name, which needs to be filled in printer_create_font the first parameter. However:

Some types of Chinese fonts cannot be displayed normally. There is no solution so far. It may be that the printer has limited memory and cannot hold all font files.

To create a font, you need to specify the width and height, but I don’t know what the unit of width and height is, so I can only try it myself

The same way to specify the position of the problem requires the x y position coordinate value, the method is printer_draw_line drawing A diagonal line is calculated based on the aspect ratio.

Print Chinese garbled characters, reason: the data submitted using the form is UTF-8 encoded, and the printer is not necessarily UTF-8 encoded. You need to consult the manual to convert the encoding format.

Continuous printing of dozens or hundreds of windows was directly killed, blue screen Smecta. In the end, it is a problem with the Apache process. Every printing will create a process. However, Apache's process recycling seems to be not timely. In the end, the system dies directly. Trying to make configuration changes such as the maximum number of connections has no effect. Final solution: Replace the Nginx server and the problem is solved.


秋香姐家的小书童

PHP operates the printer. Wouldn’t it be better to use JS directly?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!