Paper size limit using printer_draw_text php

0

I'm facing a very strange problem in thermal printer printing using php.

Everything is right, however the text is great it did not print everything, it has a standard print size. I could not find anything about it. Follow my code

function imprimir($texto){

$handle = printer_open("Daruma DR800");

printer_set_option($handle, PRINTER_MODE, "RAW",PRINTER_FORMAT_CUSTOM); 

printer_start_doc($handle, "Print"); // Name Document 

printer_start_page($handle);

$font = printer_create_font("Arial",40,16,PRINTER_FW_NORMAL,false,false,false,0);
printer_select_font($handle, $font);

$posicao = 10;
for($i = 0; $i < count($texto); $i++){
printer_draw_text($handle, $texto[$i], 10, $posicao);

$posicao = $posicao + 40;

}

printer_delete_font($font);

printer_end_page($handle);

printer_end_doc($handle);

printer_close($handle); 

}

The variable $texto is an array of strings.

Note: php is not the best option for local printing, but it is the one I need to use in the project.

    
asked by anonymous 28.09.2017 / 17:33

1 answer

0

The printer_draw_text function works like this:

printer_draw_text ( resource, string, posiçãoX, posiçãoY)

You are increasing from 40 to 40 and probably after a lot of text you need to use:

$linhaAtual = 0; //usado apenas para checar a linha atual
$linhasPorPagina = 12; //Ajuste aqui para definir o limite de linhas por pag

for ($i = 0; $i < count($texto); $i++){

    if ($linhaAtual > $linhasPorPagina) {
        $linhaAtual = 0; //Linha atual da página volta para zero

        $posicao = 0; //Volta a posição para zero

        printer_end_page($handle); //Finaliza a página
        printer_start_page($handle); //Inicia uma nova página
    }

    printer_draw_text($handle, $texto[$i], 10, $posicao);

    $posicao = $posicao + 40;

    $linhaAtual++; //Soma mais uma linha
}

printer_delete_font($font);

printer_end_page($handle);
  

Note: I have never used thermal printers, I know how they are, but technically speaking I do not know if for every amount of paper it will be considered a page.

    
28.09.2017 / 17:46