Reputation: 73
im trying to get a extension working which can grab the printed document through an event. I found the printerProvider Api. Afterwards i added the custom printer like that
chrome.printerProvider.onPrintRequested.addListener(function (job, status) {
console.log(job,status)
});
chrome.printerProvider.onGetPrintersRequested.addListener(
function ( resultCallback ) {
resultCallback( [{
id: '',
name: 'Custom Printer',
description: ''
}] );
}
);
Im struggling what id i have to fill in that i get the print dialog to work. I found this question which displays a way to add a network printer. (Google JavaScript API - Chrome.printerProvider: Printer id format)
Is there a way to get the PrintJob without actually printing to a specified printer in the id or if not is it possible to print to a pdf and get the PrintJob after saving (Windows 10 adds the "Microsoft Print to PDF Printer. But i dont know its id")?
Upvotes: 0
Views: 786
Reputation: 73
I have found the answer to my question. To be able to get the pdf content you have to use this code
chrome.printerProvider.onGetPrintersRequested.addListener(
function ( resultCallback ) {
resultCallback( [{
id: 'customprinter',
name: 'Custom Printer',
description: ''
}] );
}
);
chrome.printerProvider.onGetCapabilityRequested.addListener(function (printerId, resultCallback) {
console.log(printerId);
if(printerId == 'customprinter') {
resultCallback(capabilities);
}
});
For the capabilities variable you can use the example provided in the documentation https://developers.google.com/cloud-print/docs/cdd#cdd-example
When you set the capabilities a preview will be displayed and you are able to print. In onPrintRequested you will then get the printjob.
Upvotes: 2