Paper limit size using printer_draw_text php

Asked

Viewed 280 times

0

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

It’s all right, but when the text is big, it doesn’t print everything, it has a standard print size. I couldn’t find anything about it. Follows 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: I know php is not the best option for local printing, but it is the one I need to use in the project.

1 answer

0


The function printer_draw_text works like this:

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

You are increasing from 40 by 40 and probably after an amount 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: never used thermal printers, I know how they are, but technically speaking I do not know if for each amount of paper will be considered a page.

  • 1

    Thank you very much. It makes sense yes. I am not at home, I will test later and I speak if solved. But thank you for your reply.

  • @Denisdias adjusted the code in a way that will be enough for you to adjust in the variable $linhasPorPagina line limit per page.

  • Thank you very much. I’m afraid only printer print when I close the page. But after 6:00 PM I will test.

  • @Denisdias glad you warned me, although it’s a different situation now that I realized that the script could generate an empty page at the end, so I changed the order of the IF, I just came by to say.

  • It worked. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.