Chrome Extensions for silent printing?

I made a quiet printable web application that prints a PDF file. The key was to add JavaScript to the PDF file, which silently prints itself.

To do this, I open the PDF with the acrobat reader in chrome, which allows me to execute the script (with the appropriate permissions).

But, as announced, this solution will not work after chrome 45, as the npapi problem.

I suggest that a possible solution might be to use the recently released printProvider from chrome extensions.

However, I cannot imagine how to fire any printProvider events. So the question is, is there a chrome extension for making a web application without printing, and how can I run and process a print job for an embedded HTML PDF page.

+8
javascript printing google-chrome-extension
source share
3 answers

Finally, I found an acceptable solution to this problem, since I could not find it, but I read a lot of posts with the same problem as I left my solution here.

So, first you need to add your printer to Google Cloud Print, and then you will need to add proyect to the Google Developer Console

Then add this script and anytime you need to print something, execute the print () function. This method will print the document specified in the content.

The application will ask for your permission to manage your printers.

function auth() { gapi.auth.authorize({ 'client_id': 'YOUR_GOOGLE_API_CLIENT_ID', 'scope': 'https://www.googleapis.com/auth/cloudprint', 'immediate': true }); } function print() { var xhr = new XMLHttpRequest(); var q = new FormData() q.append('xsrf', gapi.auth.getToken().access_token); q.append('printerid', 'YOUR_GOOGLE_CLOUD_PRINTER_ID'); q.append('jobid', ''); q.append('title', 'silentPrintTest'); q.append('contentType', 'url'); q.append('content',"http://www.pdf995.com/samples/pdf.pdf"); q.append('ticket', '{ "version": "1.0", "print": {}}'); xhr.open('POST', 'https://www.google.com/cloudprint/submit'); xhr.setRequestHeader('Authorization', 'Bearer ' + gapi.auth.getToken().access_token); xhr.onload = function () { try { var r = JSON.parse(xhr.responseText); console.log(r.message) } catch (e) { console.log(xhr.responseText) } } xhr.send(q) } window.addEventListener('load', auth); 
 <script src="https://apis.google.com/js/client.js"></script> 

In any case, this script throws an "Access-Control-Allow-Origin" error, even if it appears in the documentation ... I could not get it to work :(

The Google APIs support requests and responses using Share Resource (CORS). You do not need to download the entire JavaScript client library to use CORS. However, if you want your application to access the user's personal information, it should still work with the Google OAuth 2.0 engine. To make this possible, Google provides a standalone auth client, a subset of the JavaScript client.

So, to quit this, I had to install this chrome CORS extension. I am sure someone will improve this script to avoid this chrome extension.

+6
source share

After uninstalling npapi, I do not think that this is possible exclusively programmatically. The only current way that I know to get chrome to print quietly is to use the chrome kiosk mode, which is the flag (mode) that you must set when chrome starts.

Take a look at these SO posts:

Silent printing (direct) using KIOSK mode in Google Chrome

Running Chrome with an extension in kiosk mode

+1
source share

You can register the application in the URI scheme to make the local application print without interference. The setup is quite simple and straightforward. This is an unhindered experience. I posted the solution here with a complete example:

stack overflow

+1
source share

All Articles