Print from PHP with coordinates

-1

Good day developers, I am developing something in PHP , but I need to know if there is any way to print with coordinates, I have experience in c # with the impressions and there is a way to do it by means of values in x - y, but looking for how to do it in php I have not been able to find much, just like send to print from the browser creating a HTML document but it is not what I need, since I need to be able to print with a template of receipts.

How can I make the impression?

    
asked by jose marquez 05.06.2018 в 03:42
source

1 answer

1

PHP has an extension that allows you to print to a printer connected to the server using the printing features ( sadly the documentation is not available in Spanish and the extension is only for Windows).

The most difficult thing about this extension is to make it work (I tried it in the past with WampServer and I did not get it), you can find the necessary files in official PHP page and instructions on how to install them here (although the basic idea is to copy the DLL to the PHP extensions folder and activate it in php.ini).

Once you have the extension installed and running, you can use the method printer_draw_text to put text in the specified coordinates (my translation):

  

Description

void printer_draw_text ( resource $printer_handle , string $text , int $x , int $y )
     

The function draws text in the x position, and using the selected font.

     

Parameters

     

printer_handle
  printer_handle must be a valid driver for a printer.

     

text
  The text to write.

     

x
  x is the x coordinate of the position.

     

and
  and it is the y-coordinate of the position.

And here is an example of how it is used taken from that same php.net page (I have renamed some variables to make it easier to follow and added comments to facilitate understanding):

<?php
// conectamos a la impresora y comenzamos un documento de impresión
$controlador = printer_open();
printer_start_doc($controlador, "Mi Documento");
printer_start_page($controlador);

// seleccionamos una fuente Arial con 72x48 pixels de alto x ancho y sin negrita
$fuente = printer_create_font("Arial", 72, 48, 400, false, false, false, 0);
printer_select_font($controlador, $fuente);

// escribimos el texto "Test" en la posición 10,10 de la página
printer_draw_text($controlador, "Test", 10, 10);
printer_delete_font($fuente);

// finalizamos el documento y cerramos la conexión con la impresora
printer_end_page($controlador);
printer_end_doc($controlador);
printer_close($controlador);
?>
    
answered by 05.06.2018 / 15:48
source