Automatically Print Image from Website

前端 未结 9 704
一生所求
一生所求 2020-12-05 05:37

A coworker and I were having a discussion about what is and isn\'t possible within the browser.

Then a question came up that neither of us could answer with certaint

相关标签:
9条回答
  • 2020-12-05 06:20

    As far as I know, there is no way to print a document directly, without some client intervention, like setting browser flags. In our current project we need to print directly to the default printer, but at least with Chrome you can do it easily with additional startup arguments.

    To print directly to the OS default printer you can use:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:\tmp --kiosk-printing http://www.contoso.com

    Another option, which may also be useful, is tos use the native print dialog instead of chromes print preview.

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:\tmp --disable-print-preview http://www.contoso.com

    Note, that window.print() and/or Ctrl-P behave accordingly the mentioned settings.

    I know, that this does not exactly answers the OPs question, but I think it somewhat related, and for web based enterprise applications this is a quite common use case. Maybe someone find it useful.

    For Firefox I recommend Seamless Print Addon

    0 讨论(0)
  • 2020-12-05 06:29

    I think at best you would need an ActiveX component using base windows API to obtain a device context for the default printer and try and print an embedded image using assumed values for the printer settings.

    0 讨论(0)
  • 2020-12-05 06:30

    You can't bypass the print dialog, as far as I know. That would be a pretty obvious security flaw if the browser allowed that. But you can bring up the print dialog with "window.print()".

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