How to force a website to print

前端 未结 5 1132
自闭症患者
自闭症患者 2021-01-20 21:02

This is going to sound like an odd request, but... I have a web application that is set up to collect data and store it into a database on regular intervals. The application

5条回答
  •  情话喂你
    2021-01-20 21:49

    As others have pointed out – isn't really possible to complete the print task in a web browser dialog window without human intervention or macros to control the mouse.

    Instead of having the browser do the printing, I would suggest you have your ajax requests trigger something that saves the data to be printed into a file (wkhtmltopdf is one option) and have your web server (which could be Linux, OSX, Windows Server) monitor a folder and print (and then delete) whatever appears in that folder. In OSX you could do this quite easily with Automator. In Linux you could write a bash script that monitors the folder every X minutes (via cron) and runs the lpr program to send files to the printer. On Windows... well, I have no idea what you'd do, but I do recall seeing something like a folder-as-print-queue option in older versions of Windows in the printer's properties. I could be making that up, though.

提交回复
热议问题