Printing with PHP - Different font sizes?

好久不见. 提交于 2021-01-29 05:20:04

问题


I work at a school and am writing a wizard-style front end for our helpdesk. Students will grab the tablet, fill in their name, pick the issue they're having and a ticket will be opened on the system.

We have a receipt printer shared at the desk and using PHP's printer_* functions, I'm able to print out simple receipts using RAW mode. The student will take the receipt back to class to show the teacher as proof they were with us. So far my code works great:

$handle = printer_open("EPSON TM-T88IV Receipt"); // The name of our printer on Windows
printer_set_option($handle, PRINTER_PAPER_FORMAT, PRINTER_FORMAT_CUSTOM); // Custom paper format
printer_set_option($handle, PRINTER_PAPER_WIDTH, "80"); // 80mm wide
printer_set_option($handle, PRINTER_MODE, "RAW"); // And raw printing mode
printer_write($handle, "Hello world\nPrinting is fun\nGoodbye"); // Sample text
printer_close($handle);

But what I'd like to know is, how do I do fancy formatting, such as a larger font size, bold text or possibly even a logo? (the latter, not so important, it's just a wishlist thing)

I see you can set the modes to text and EMF (Enhanced Metafile Format?), but can't seem to find much info on generating EMF from PHP. I've seen escape codes on a few sites, but these seem to be printer specific and not human readable.

Any suggestions?


回答1:


It seems you should use both functions printer_create_font and printer_draw_test and you will be able using them something like this (code from PHP manual):

<?php
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);

$font = printer_create_font("Arial", 72, 48, 400, false, false, false, 0);
printer_select_font($handle, $font);
printer_draw_text($handle, "test", 10, 10);
printer_delete_font($font);

printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
?>



回答2:


You can do this.

$font1 = printer_create_font("Arial", 600, 400, 4000, false, false, false, 0); 
$font2 = printer_create_font("Arial", 200, 150, 1500, false, false, false, 0); 
printer_select_font($handle, $font1); 
printer_draw_text($handle, '1', 100, 100); 
printer_select_font($handle, $font2); 
printer_draw_text($handle, '2', 1000, 500); 


来源:https://stackoverflow.com/questions/24546491/printing-with-php-different-font-sizes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!