How to force a website to print

前端 未结 5 1101
自闭症患者
自闭症患者 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:37

    There is a similar Question at How do I create a web based print server?

    We optet for creating a native print client. See http://mdornseif.github.com/2011/01/08/PDF-on-appengine.html for details.

    0 讨论(0)
  • 2021-01-20 21:40

    The print functionality is handled by the browser (and is thus unique per browser), it can be called (by javascript), but cannot be forced to print

    (here's the javascript to call the print method in the browser)

    <script language="Javascript1.2">
      <!--
      function printpage() {
      window.print();
      }
      //-->
    </script>
    
    0 讨论(0)
  • 2021-01-20 21:43

    You could write a separate application that has a web-browser control, and have it do the printing for you. There's no way to do it in a regular browser, though --- think of the implications of that.

    0 讨论(0)
  • 2021-01-20 21:47

    you can bring up the print dialog using JS, i think its window.print(), which you could put with your ajax call. regarding the auto click i am not sure.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题