pedroroccon's avatar

Laravel and thermal printers

Greetings,

I'm developing an application that's hosted on a webserver. My application simples get a user input and them print that on a thermal printer (Argox OS2140). The problem is: The app is hosted on a remote server, but the thermal printer is locally installed on my computer.

Anyone knows a solution that I can integrate the local thermal printer in my web application? The difficult is find a way to print the generated file, as the thermal printer accepts only command line and my remote server can't send the command to my local computer.

Regards,

0 likes
10 replies
tykus's avatar

You could have the web application push jobs onto a queue and then run the queue worker locally on your computer. PHP can execute shell commands using the Symfony Process class, e.g. a pseudo-example:

$process = new Process(['print', $content]);

$process->run();

If you use the database for your queue, then this is a relatively simple solution providing you keep the local and remote code in sync.

pedroroccon's avatar

Hmm nice! Unfortunately I need a simpler solution because it's not me that'll use the applications. Something more intuitive.

tykus's avatar

More intuitive how? Which part is not intuitive?

pedroroccon's avatar

I was thinking in something like a desktop application, or something more "encapsulated".

To execute this solution, I'll need to install in my customer a local webserver, with php, and all the other stuff.

I get the ideia, but i'm trying to simplify a little more.

tykus's avatar

something like a desktop application

Ok, there was no way to guess that is what you were looking for whenever you posted on a Laravel PHP Web Application Framework forum.

You can write a desktop application (for your OS of choice) and there is nothing to prevent you connecting to, and reading/writing data to, the same database that the web server writes to; however, this is probably not the forum to get answers for such questions.

skauk's avatar

You can go with the route of printing a page from the browser as well. For termal printers, however, you'll need to carefully design a view that will produce a meaningful output on your particular printer model. This will probably require a bit of experimentation.

pedroroccon's avatar

@tykus Great! I agree that this forum isn't the best place to get the answers. I started this thread just for get some ideas. I was thinking that maybe someone already made that in a easier way.

Maybe i'll stick with your first ideia and install a local webserver in my customer computer.

However I appreciate the support! Thanks

Regards,

pedroroccon's avatar

@skauk I can only send the print layout through a file in a command line, because the browser doesn't support RAW prints. Basically the browser send the following code as a string to the printer and not interpret the PCLA, PCLB, PCLZ commands like:

^CFA,30
^FO50,300^FDJohn Doe^FS
^FO50,340^FD100 Main Street^FS
^FO50,380^FDSpringfield TN 39021^FS
^FO50,420^FDUnited States (USA)^FS
^CFA,15
^FO600,300^GB150,150,3^FS
^FO638,340^FDPermit^FS
^FO638,390^FD123456^FS
^FO50,500^GB700,1,3^FS

I read about this, and found some extensions that prints RAW files in the Chrome, but I don't want to depend of a extensions and specifique browsers.

tykus's avatar
tykus
Best Answer
Level 104

Check out Laravel Zero for the local application - it is Laravel for CLI. You can schedule a command top run every minute which can get the new records in the shared DB, and generate the file required by the printer

pedroroccon's avatar

@tykus Awesome! You simplified a lot. I'll keep your first idea, but with the Laravel Zero. Thanks for the support!

Please or to participate in this conversation.