Google Chrome Extension: Print the page silently
Asked Answered
D

5

18

I'm developing an internal Google Chrome Extension that needs a way to initiate print the current page to the printer. I do not want the default Print dialog to come up (so, javascript:window.print() is out of question).

As far as I understand, this is not possible just with the JS + HTML plug-in, so I'm also open to using the NPAPI plugin also (with a dummy mime-type). And I'm concerned for Windows platform only.

I'm also open for various hacks / workarounds if possible, though a standard solution would be nice.

If you think this is not possible, let me know if you know any feature request logged for it?

Any suggestions/clarifications are welcome..

Drayage answered 31/1, 2011 at 10:44 Comment(3)
Did you ever finish extension? It is exactly what I am looking for...Swaggering
No, I couldn't do anything for silent printing. :(Drayage
Disable print preview in Google Chrome on Windows Close Google Chrome From your desktop, right click Google Chrome Click Properties In the dialog box, add ‘ –disable-print-preview‘ at the end of the Target field sans the apostrophe (make sure to include the space before –) Click Apply support.dryfta.com/…Augustina
C
18

In chrome (v18+) we have the --kiosk --kiosk-printing switches. One can print automatically to default printer without print confirmation.

You can see it from this video http://www.youtube.com/watch?v=D6UHjuvI7IE

Calpe answered 16/2, 2012 at 23:20 Comment(4)
Will these options be available in chrome://flags also? Or are they command-line only?Drayage
Chrome doesn't work well with our label printer. If IE had a similar switch that would be great!Wedlock
video is not availableRoosevelt
If anyone interested, here's the video from WayBack Machine - web.archive.org/web/20130311214549/http://www.youtube.com/…Wot
S
1

Since NPAPI allows you to create native C++ plugins that you can interact with through an object tag (which you can use from an extension), that would probably be the way to do it.

The tricky bit is that I don't know of a good way to get the bits for printing the page. The only person I know of who has done something similar to this actually got the window handle for the browser (available through NPAPI) and scraped the bits off of it to print that way, but that won't take into account print stylesheets or anything. You could also try using automation events to try to control the print dialog, but I have no idea if that would work or not.

By design, the browsers try not to let you do something like this, as it could open some serious vulnerabilities if any website could just start printing things to your printer without confirmation...

Anyway, if you find a way to do it with C++ you can use FireBreath to ease the creation of the NPAPI plugin.

Shoal answered 31/1, 2011 at 16:40 Comment(1)
"The tricky bit is that I don't know of a good way to get the bits for printing the page." <- This part can be done an the extension level, rather than the plugin level.Farrago
F
0

There are various extensions that take snapshots of the current web page (for example, this one); you could adapt one to send the image to a printer via an NPAPI plugin.

Farrago answered 31/1, 2011 at 15:2 Comment(3)
Is there any other way you are aware/think of without using screenshot? Also, can you please provide me info/link on how to "send the image to a printer" on Windows?Drayage
I didn't say anything about screenshots; go look at the plugin I linked to. It actually renders the page (including the parts scrolled out of view) to an image, it doesn't take a screenshot.Farrago
If you need to learn how to write native printing code on Windows, I'd suggest posting a new question; it's totally tangential to Chrome extensions and NPAPI.Farrago
E
0

I've recently been looking for a similar ability, and it seems like it would be quite possible using Chrome's new native messaging api.

https://developer.chrome.com/extensions/nativeMessaging

There are plenty of examples of this with C#, but here is one quick example of troubleshooting Chrome native messaging with a basic C# application

Native messaging from chrome extension to native host written in C#

I realize this may be a day late and a dollar short, but in case anyone else comes across this question, this is the solution that worked for me. From inside a C# app, you can directly print to installed printers using the PrintDocument class. If you figured out a way to get the page image, this would be far easier than using firebreath or NPAPI.

Encarnalize answered 16/6, 2015 at 1:55 Comment(0)
A
0

Disable print preview in Google Chrome on Mac

  1. Quit Google Chrome
  2. Launch Terminal on your Mac. (Search “Terminal” using the Search box)
  3. Type defaults write com.google.Chrome DisablePrintPreview -bool true
  4. Close Terminal and open Google Chrome

Disable print preview in Google Chrome on Windows

  1. Close Google Chrome
  2. From your desktop, right click Google Chrome
  3. Click Properties
  4. In the dialog box, add ‘ –disable-print-preview‘ at the end of the Target field sans the apostrophe (make sure to include the space before –)
  5. Click Apply

Disable print preview in Firefox on Mac

  • In the address bar type “about:config” and press Enter.
  • Right click on the page, hover over ‘New’ and click on ‘Boolean’
  • Type ‘print.always_print_silent’ as the preference name and click ‘OK’
  • Click on ‘true’ and click ‘OK’.
  • Close the about:config window.

Disable print preview in Firefox on Windows

  1. In the address bar type “about:config” and press Enter.
  2. Right click on the page, hover over ‘New’ and click on ‘Boolean’ Type
  3. ‘print.always_print_silent‘ as the preference name and click ‘OK’
  4. Click on ‘true’ and click ‘OK’.
  5. Close the about:config window.

https://support.dryfta.com/how-to-disable-print-preview-in-chrome-firefox-on-windows-mac/

Augustina answered 13/8, 2021 at 5:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.