Directly printing PDF from PHP or JS - javascript

So, I have this application in Symfony, I use a printer for some stickers, which is fine using JS window.print(), but now, I need to print PDFs and I cannot ask the user to do anything.
Is it possible to directly send the PDF to the printer either from PHP or JS?
I can setup a local server which will be connected on the same network with the printer.
I cannot find nothing about directly printing except some PHP 4.0.4 version extension.
I'm using Symfony 4 with PHP 7.3 and JS for the front end stuff.
Can you please advise if there is a library for PHP or I can skip the print button on window.print() in JS.
Thanks in advance

Directly this shouldn´t be possible, but what if your Printer has got a smb-hotfolder functionality? Then you could write out files into this hotfolder. Regards

Related

Javascript to print with wifi printer

I´m making a simple webapp, I want that when it is open in mobile phones print some data using the user´s wifi printer which most of cases will be an Epson L355.
Can anybody give me a clue or sample to achieve this?
Thank you all.
You won't be able to do this because you don't have access to the user's printer. Instead, you can just generate a pdf and redirect user on it.
The user will then be able to download / print the pdf via his inline PDF viewer.
You can do it by following this :
How to force files to open in browser instead of download (pdf)?

reading & writing sqlite database with javascript

I am currently trying to get my head around database's and web programming.
I currently have 3 files index.html, script.js (empty at the minute) and test_db.sqlite.
I am trying to pull info from the sqlite database, create a javascript variable with the info and the print it to the html with the document.getElementById method.
What I'd having trouble with is reading the database using javascript. I am willing to use jquery or any other extra JS scripts, but I cannot use php as I intend to use this to create a cross platform app with a python web wrapper on windows & linux and phonegap for iOS and Android.
I also need to figure out to write to the database with javascript.
Thank you for any help in advance.
You have to dump the database (you can use .dump command in sqlite3)
Then you can send that dump to de front-end (the navigator)
You can use WebSql API to create the database and execute all commands of the dump to recreate
Warning, this does'nt work in Firefox. It works only in Chrome and Safari

How to print PDF data from InAppBrowser (PhoneGap)

I am using PhoneGap / Steroids for an iOS app.
In PhoneGap, I request a pdf from the server. The pdf is received in base64 format.
I am able to successfully preview the pdf using InAppBrowser:
window.open( "data:application/pdf;base64," + pdf.data, "_blank" );
However what I really need is to send this pdf data to the printer via AirPrint. Is it possible to do this using InAppBrowser? If not, what is the recommended method?
Thanks (in advance) for your help
Well, I don't think there is any use for InAppBrowser for this purpose. What you should look instead is for plugin that connects to AirPrint such as Cordova Print Plugin. This allows you to connect to AirPrint from within your JavaScript code. I'm not sure about if it fits all of your purposes, though, but take a look.

Automatically print a webpage to pdf

While using browsers like Chrome and Firefox, there is an option to print the page to PDF (that is saving the webpage as a PDF file).
Print this page
This code opens up the print page from where the user should manually choose print to PDF. Can this be done automatically? If so please help.
You can not print page to pdf with Javascript. You have to use server side script to print page to pdf. In PHP, you can use 3rd party PDF library like http://www.tcpdf.org .
There is not much available to print to PDF in Javascript.
The most supported option is indeed to generate it server-side using a library such as tcpdf (as shown by Thein Hla Maw).
I don't think Mark's solution is the correct one, since it requires the users to have some software installed.
For pure javascript PDF generation, there is this.
NB : thanks SO :-)
Yes... provided that your users have a few things installed.
They need a PDF print driver, such as PrimoPDF
If you want to automatically print to this driver, they need to have a plugin installed, such as JS Print Setup (for Firefox) or MeadCo ScriptX for IE
Then, using the API of said plugin, you can choose which driver to print to. You can even skip the print dialog.
A better option, however, would be the generate the PDF server-side, stream it to them, and then use JavaScript inside the PDF to automatically open the print dialog as soon as they view it. This way they don't need any plugins.

Rails 3/JavaScript: Print PDFs to default printer

I have an app that generates PDFs and I want it to be able to print the PDF to the client default printer. How can I accomplish that?
Thanks
Edit: Javascript link could also work.
You could embed javascript in your pdf.
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acro6JSGuide.pdf
So when you generate the PDF, use this.print() when the document is opened.
Rails only sends the PDF to the browser, and the browser/user handles printing. You really can't control what printer it gets sent to...

Categories