From 5947e091c45d14271eb55c7edb453d4f623dd310 Mon Sep 17 00:00:00 2001 From: Nathan Muggli Date: Thu, 26 Oct 2023 16:31:41 -0600 Subject: [PATCH] Consolidate the roll-printing sample with the regular sample There is now a checkbox on the main UI to select roll printers or all printers. For roll printing, this sample now demonstrates how to check if the printer is capable of roll printing, if the printer is capable of trimming the paper after printing, and how the media length can be a variable value. --- api-samples/printing/README.md | 2 + api-samples/printing/printers.html | 4 + api-samples/printing/printers.js | 139 ++++++++++---- api-samples/printing/roll-printing/README.md | 13 -- .../printing/roll-printing/icons/icon.png | Bin 232 -> 0 bytes .../printing/roll-printing/icons/icon128.png | Bin 3544 -> 0 bytes .../printing/roll-printing/icons/icon16.png | Bin 227 -> 0 bytes .../printing/roll-printing/icons/icon48.png | Bin 765 -> 0 bytes .../printing/roll-printing/manifest.json | 20 -- .../printing/roll-printing/printers.css | 18 -- .../printing/roll-printing/printers.html | 46 ----- .../printing/roll-printing/printers.js | 179 ------------------ .../test.pdf => test-rollprinting.pdf} | Bin 13 files changed, 103 insertions(+), 318 deletions(-) delete mode 100644 api-samples/printing/roll-printing/README.md delete mode 100644 api-samples/printing/roll-printing/icons/icon.png delete mode 100644 api-samples/printing/roll-printing/icons/icon128.png delete mode 100644 api-samples/printing/roll-printing/icons/icon16.png delete mode 100644 api-samples/printing/roll-printing/icons/icon48.png delete mode 100644 api-samples/printing/roll-printing/manifest.json delete mode 100644 api-samples/printing/roll-printing/printers.css delete mode 100644 api-samples/printing/roll-printing/printers.html delete mode 100644 api-samples/printing/roll-printing/printers.js rename api-samples/printing/{roll-printing/test.pdf => test-rollprinting.pdf} (100%) diff --git a/api-samples/printing/README.md b/api-samples/printing/README.md index 2ba7e74fdd..1f477b8163 100644 --- a/api-samples/printing/README.md +++ b/api-samples/printing/README.md @@ -8,6 +8,8 @@ The `chrome.printing` namespace only works on ChromeOS. The sample demonstrates Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation. +If the `'Roll Printers` checkbox is selected, only printers capable of roll printing will appear in the table. In this case, a separate test file is printed and the height of the media can be variable. + ## Implementation Notes Before Chrome 120, `submitJob()` function throws an error when returning a promise. diff --git a/api-samples/printing/printers.html b/api-samples/printing/printers.html index 261f6d1d32..46408898ec 100644 --- a/api-samples/printing/printers.html +++ b/api-samples/printing/printers.html @@ -29,6 +29,8 @@

Print Job:

Printers:

+ + @@ -41,9 +43,11 @@

Printers:

+ +
Default Recently used CapabilitiesSupports trim Status
diff --git a/api-samples/printing/printers.js b/api-samples/printing/printers.js index 9e68aaea1c..2f4640b138 100644 --- a/api-samples/printing/printers.js +++ b/api-samples/printing/printers.js @@ -2,7 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -function onPrintButtonClicked(printerId, dpi) { +let listOfPrinters = []; + +function rollPrintingEnabled() { + return document.getElementById('rollPrinters').checked; +} + +function onPrintButtonClicked(printerId, dpi, performTrim) { let ticket = { version: '1.0', print: { @@ -14,16 +20,34 @@ function onPrintButtonClicked(printerId, dpi) { horizontal_dpi: dpi.horizontal_dpi, vertical_dpi: dpi.vertical_dpi }, - media_size: { - width_microns: 210000, - height_microns: 297000, - vendor_id: 'iso_a4_210x297mm' - }, collate: { collate: false } } }; - fetch('test.pdf') + if (rollPrintingEnabled()) { + filename = 'test-rollprinting.pdf'; + ticket.print.media_size = { + width_microns: 72320, + // Note that this value needs to be between min_height_microns and + // max_height_microns. Usually this matches the height of the document + // being printed. + height_microns: 110000 + }; + // This only makese sense to specify if the printer supports the trim + // option. + if (performTrim) { + ticket.print.vendor_ticket_item = [{id: 'finishings', value: 'trim'}]; + } + } else { + filename = 'test.pdf'; + ticket.print.media_size = { + width_microns: 210000, + height_microns: 297000, + vendor_id: 'iso_a4_210x297mm' + }; + } + + fetch(filename) .then((response) => response.arrayBuffer()) .then((arrayBuffer) => { const request = { @@ -73,48 +97,67 @@ function addCell(parent) { return newCell; } +function supportsRollPrinting(printerInfo) { + // If any of the media size optionis support continuous feed, return true. + const newOptions = printerInfo.capabilities.printer.media_size.option.filter( + (option) => option.is_continuous_feed); + if (newOptions.length > 0) { + return true; + } + return false; +} + function createPrintersTable() { - chrome.printing.getPrinters().then((printers) => { - const tbody = document.createElement('tbody'); - printers.forEach((printer) => { - chrome.printing.getPrinterInfo(printer.id).then((printerInfo) => { - const columnValues = [ - printer.id, - printer.name, - printer.description, - printer.uri, - printer.source, - printer.isDefault, - printer.recentlyUsedRank, - JSON.stringify(printerInfo.capabilities), - printerInfo.status - ]; - - let tr = document.createElement('tr'); - const printTd = document.createElement('td'); - printTd.appendChild( + // Reset this so the table can be rebuilt with either all printers or just + // printers capable of roll printing. + let tbody = document.getElementById('tbody'); + while (tbody.firstChild) { + tbody.removeChild(tbody.firstChild); + } + + listOfPrinters.forEach((printer) => { + if (!rollPrintingEnabled() || supportsRollPrinting(printer.info)) { + // The printer needs to support this specific vendor capability if the + // print job ticket is going to specify the trim option. + const supportsTrim = + printer.info.capabilities.printer.vendor_capability.some( + (capability) => capability.display_name == "finishings/11"); + const columnValues = [ + printer.data.id, + printer.data.name, + printer.data.description, + printer.data.uri, + printer.data.source, + printer.data.isDefault, + printer.data.recentlyUsedRank, + JSON.stringify(printer.info.capabilities), + supportsTrim, + printer.info.status + ]; + + let tr = document.createElement('tr'); + const printTd = document.createElement('td'); + printTd.appendChild( createButton('Print', () => { onPrintButtonClicked( - printer.id, - printerInfo.capabilities.printer.dpi.option[0] + printer.data.id, + printer.info.capabilities.printer.dpi.option[0], + supportsTrim ); }) - ); + ); - tr.appendChild(printTd); + tr.appendChild(printTd); - for (const columnValue of columnValues) { - const td = document.createElement('td'); - td.appendChild(document.createTextNode(columnValue)); - td.setAttribute('align', 'center'); - tr.appendChild(td); - } + for (const columnValue of columnValues) { + const td = document.createElement('td'); + td.appendChild(document.createTextNode(columnValue)); + td.setAttribute('align', 'center'); + tr.appendChild(td); + } - tbody.appendChild(tr); - }); - }); - const table = document.getElementById('printersTable'); - table.appendChild(tbody); + tbody.appendChild(tr); + } }); chrome.printing.onJobStatusChanged.addListener((jobId, status) => { @@ -149,5 +192,17 @@ function createPrintersTable() { } document.addEventListener('DOMContentLoaded', () => { - createPrintersTable(); + chrome.printing.getPrinters().then((printers) => { + printers.forEach((printer) => { + chrome.printing.getPrinterInfo(printer.id).then((printerInfo) => { + listOfPrinters.push({data: printer, info: printerInfo}); + createPrintersTable(); + }); + }); + }); + + let checkbox = document.getElementById('rollPrinters') + checkbox.addEventListener('change', function() { + createPrintersTable(); + }); }); diff --git a/api-samples/printing/roll-printing/README.md b/api-samples/printing/roll-printing/README.md deleted file mode 100644 index 64154da910..0000000000 --- a/api-samples/printing/roll-printing/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# chrome.printing - -This sample demonstrates printing to a roll printer with the `chrome.printing` namespace. - -## Overview - -The `chrome.printing` namespace only works on ChromeOS. The sample demonstrates how to get a list of available printers and display the ones that support roll printing. A new entry is added to the table for each unique width for each printer. A 'Print' button sends a sample PDF to the selected printer and makes a 'Cancel Printing' button visible. This button is visible while the print job's status is `"PENDING"` or `"IN_PROGRESS"`. Note that on some systems, the print job is passed to the printer so quickly that you may never see the 'Cancel Printing' button. - -Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation. - -## Implementation Notes - -Before Chrome 120, `submitJob()` function throws an error when returning a promise. diff --git a/api-samples/printing/roll-printing/icons/icon.png b/api-samples/printing/roll-printing/icons/icon.png deleted file mode 100644 index 19057a5f322e1dd45110f3680517af22c77941ee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 232 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM3?#3wJbMaA83*`;xB}^!GiNpcL04C6YkxyW z4+yn(H?%=WAOi*c|NsAS?~koOZTuxce!&c^Y!Z?-c5Uq)51u^z^}Aw4YY|Y2G0EHA zMPTYCUL7FE!_&nvMB{vN!UD4g?o3-I9pIW_vGYeDgE+f#MAKw><_*oN6#=Z3Gb4ZO zFw|jV3^QB7{9_|Sl1f0W%QBXh?vqL?j#DqF3NkQA9pFvOiRNDfG?T&8)z4*}Q$iB} DE)G)f diff --git a/api-samples/printing/roll-printing/icons/icon128.png b/api-samples/printing/roll-printing/icons/icon128.png deleted file mode 100644 index 13a19d6d817914be248b04ec0a65991d55a66ce5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3544 zcma)K8ps7isz@;bq$s^NF`$MjAVr9j(7`JL0@9@g zE`pRGsF2WG0+)J&fYgWoecyZYX5P;1IkRVGchBtZAHPj7H-ob=3oru!05)SIeT$15 z{aYF7FHSrZ_2uFnXRNPd6-L~2WJ`9i<}D}HfvZ01zkT`*#Ax&iAY+%r#LFvv_gS~= z+sRA3o2mb}(-lo@ZA5BNXLAp>avdj2*BcXgi{^`qbj%UAEj&Cpt6pAu$EXW2Ps5c> z_%yYVzHe(BjD)=RT63kJ8PSkZ!%l66tQKrX9ZUy~o`%N>l^6dvv3R_zSyR-~7P&E9 zU5(%E;8KUW5RFI)G#@_aQHyxMblq)W^00yv(rlmEpC{v(o@QlDfC3yMp{~D9g|ynfHo<4wb`VhDW|k3p&D<% ziX`Pd|5$FX+vDS@-fNE|f&JnBC$q0B_ZA$|MgW|Ak*I*+$2qb?|EDN+*I>`c!6rvO zMSEwj8yDkTS(DQPi^vc4N6UsA@-K5HRSB{4FPVXa*2437YFO~0pVeZ-!$ZNDjbGh} zW~>f}B7uy*e77%$mJSH5t;dRGoA}Y2CKgkq7359l_%ZqL$O7yJzakdH(EStZA5@0$ zDis4joFyk|^qh@NlKK`&H~#8?%89tEt2(=4>z&pO0jeO?W$$ zhgSF?x%w5W?s_Q7FF?ty!#&!Hif+~z{~;f`HI3hF=DlN=m#Q8Ad{r!9Fm8lxiK_6i zg}^aB1wCkouc@4hwg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cH(AY!XZj>OUM#F>m@)YxyqQ?eyB>oo}JU2XJJG9q`t&3Sczu4FS#s+5k J)w;;oe*rlZt(X7+ diff --git a/api-samples/printing/roll-printing/icons/icon16.png b/api-samples/printing/roll-printing/icons/icon16.png deleted file mode 100644 index 7591630c86c39420e8876f6cfc0de925cd6edbbc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!aez;VE0A8bYE?sPS5tdWLvwdS zTX%h1S7R%P(Ewz$^?(>aDUdisuzR_vdj!a=k|4ie24(|ehk~;5ox67JKYHfFKOY8R zQ=pu`r;B5V#O2;|j(iOYJT4dc`9xh?f6u?xs=DdmkMi1+Dy{LR`FuyK*Cp(9-o~(| z_QI<|$qoBA%#jYb6;S9gX$qS_gUq5Uj$Qv|_&=LpSH_&h$!2)8q~jLQXa-MLKbLh* G2~7YWWK~`O diff --git a/api-samples/printing/roll-printing/icons/icon48.png b/api-samples/printing/roll-printing/icons/icon48.png deleted file mode 100644 index f51b2ff243e00d9008d84e71c0e92bf63a8efee6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 765 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBgK_U{nt932_B-|NsBLYSpT~zP<(! z=x=T9Z)oUj=merk)h)fv-Q5lC{mnpbTTer4S3_4aq*Pp-t8v0DafKj9A>EamTaXdLe;$g$ocqZ)!=|>kf z#-A6{zVP_?LdQd9jM^KfN?dht+#n=h*rW4i57VI}A&bTt8yNJhjg@0;g{QCCwXk!l zu3tiG(h9x9Cs{5ZJfylb`=PAJ)COS}*2?G?9z_PurW;Pby2ak+di3En0dY~WjODs# z*{&W~o+#N7UFcNPv3&93aF2$aR{9~$3pVCk$bH@TZdTE!C^38_r*-s)pr!GFq}S}ckqVk0VlqB+Y>7z&+_hO zi#U<^B$qS#jns!}-YVG##0o1+6TGDkZ_bg;WMG(f#Ovk}Z~1A!2x9Pb^>bP0l+XkK D2V-GJ diff --git a/api-samples/printing/roll-printing/manifest.json b/api-samples/printing/roll-printing/manifest.json deleted file mode 100644 index cc6cac612b..0000000000 --- a/api-samples/printing/roll-printing/manifest.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "Roll-printing Extension", - "version": "1.0", - "description": "Demonstrates roll-printing using the chrome.printing namespace.", - "permissions": ["printing"], - "action": { - "default_popup": "printers.html", - "default_icon": { - "16": "icons/icon16.png", - "48": "icons/icon48.png", - "128": "icons/icon128.png" - } - }, - "icons": { - "16": "icons/icon16.png", - "48": "icons/icon48.png", - "128": "icons/icon128.png" - }, - "manifest_version": 3 -} diff --git a/api-samples/printing/roll-printing/printers.css b/api-samples/printing/roll-printing/printers.css deleted file mode 100644 index e97ffda6c4..0000000000 --- a/api-samples/printing/roll-printing/printers.css +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright 2020 The Chromium Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -table, th, td, tr { - border: 1px solid black; -} - -table { - width: 100%; - border-collapse: collapse; -} - -div { - overflow: auto; -} diff --git a/api-samples/printing/roll-printing/printers.html b/api-samples/printing/roll-printing/printers.html deleted file mode 100644 index 6bcfa1ca8e..0000000000 --- a/api-samples/printing/roll-printing/printers.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - Printers - - - - - -

Print Job:

-

On some systems, the print job may leave the queue too quickly to be visible in this list.

-
- - - - - - - - - -
CancelJob IdStatus
-
- -

Printers:

-
- - - - - - - - - - - -
PrintNameDescriptionSizeSupports trimStatus
-
- - diff --git a/api-samples/printing/roll-printing/printers.js b/api-samples/printing/roll-printing/printers.js deleted file mode 100644 index 82769e498d..0000000000 --- a/api-samples/printing/roll-printing/printers.js +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -function onPrintButtonClicked(printerId, dpi, width, performTrim) { - let ticket = { - version: '1.0', - print: { - color: { type: 'STANDARD_MONOCHROME' }, - duplex: { type: 'NO_DUPLEX' }, - page_orientation: { type: 'LANDSCAPE' }, - copies: { copies: 1 }, - dpi: { - horizontal_dpi: dpi.horizontal_dpi, - vertical_dpi: dpi.vertical_dpi - }, - media_size: { - width_microns: width, - // Note that this value needs to be between min_height_microns and - // max_height_microns. Usually this matches the height of the document - // being printed. - height_microns: 110000 - }, - collate: { collate: false } - } - }; - // This only makese sense to specify if the printer supports the trim option. - if (performTrim) { - ticket.print.vendor_ticket_item = [{id: 'finishings', value: 'trim'}]; - } - - fetch('test.pdf') - .then((response) => response.arrayBuffer()) - .then((arrayBuffer) => { - const request = { - job: { - printerId: printerId, - title: 'test job', - ticket: ticket, - contentType: 'application/pdf', - document: new Blob([new Uint8Array(arrayBuffer)], { - type: 'application/pdf' - }) - } - }; - chrome.printing.submitJob(request).then((response) => { - if (response !== undefined) { - console.log(response.status); - } - if (chrome.runtime.lastError !== undefined) { - console.log(chrome.runtime.lastError.message); - } - window.scrollTo(0, document.body.scrollHeight); - }); - }); -} - -function onCancelButtonClicked(jobId) { - chrome.printing.cancelJob(jobId).then((response) => { - if (response !== undefined) { - console.log(response.status); - } - if (chrome.runtime.lastError !== undefined) { - console.log(chrome.runtime.lastError.message); - } - }); -} - -function createButton(label, onClicked) { - const button = document.createElement('button'); - button.innerHTML = label; - button.onclick = onClicked; - return button; -} - -function addCell(parent) { - const newCell = document.createElement('td'); - parent.appendChild(newCell); - return newCell; -} - -function supportsRollPrinting(printerInfo) { - // Only keep the media size options that support continuous feed. When - // creating a print job ticket with a variable height, one of these widths - // must be used. These options don't really need to be filtered - just doing - // this for display purposes and to demonstrate how to determine which - // printers support continuous feed. - const newOptions = printerInfo.capabilities.printer.media_size.option.filter( - (option) => option.is_continuous_feed); - if (newOptions.length > 0) { - printerInfo.capabilities.printer.media_size.option = newOptions; - return true; - } - return false; -} - -function createPrintersTable() { - chrome.printing.getPrinters().then((printers) => { - const tbody = document.createElement('tbody'); - printers.forEach((printer) => { - chrome.printing.getPrinterInfo(printer.id).then((printerInfo) => { - if (supportsRollPrinting(printerInfo)) { - // The printer needs to support this specific vendor capability if the - // print job ticket is going to specify the trim option. - const supportsTrim = - printerInfo.capabilities.printer.vendor_capability.some( - (capability) => capability.display_name == "finishings/11"); - printerInfo.capabilities.printer.media_size.option.forEach((option) => { - const columnValues = [ - printer.name, - printer.description, - JSON.stringify(option), - supportsTrim, - printerInfo.status - ]; - - let tr = document.createElement('tr'); - const printTd = document.createElement('td'); - printTd.appendChild( - createButton('Print', () => { - onPrintButtonClicked( - printer.id, - printerInfo.capabilities.printer.dpi.option[0], - option.width_microns, - supportsTrim - ); - }) - ); - - tr.appendChild(printTd); - - for (const columnValue of columnValues) { - const td = document.createElement('td'); - td.appendChild(document.createTextNode(columnValue)); - td.setAttribute('align', 'center'); - tr.appendChild(td); - } - - tbody.appendChild(tr); - })}}); - }); - const table = document.getElementById('printersTable'); - table.appendChild(tbody); - }); - - chrome.printing.onJobStatusChanged.addListener((jobId, status) => { - console.log(`jobId: ${jobId}, status: ${status}`); - let jobTr = document.getElementById(jobId); - if (jobTr == undefined) { - jobTr = document.createElement('tr'); - jobTr.setAttribute('id', jobId); - - const cancelTd = addCell(jobTr); - let cancelBtn = createButton('Cancel', () => { - onCancelButtonClicked(jobId); - }); - cancelBtn.setAttribute('id', `id ${jobId}-cancelBtn`); - cancelTd.appendChild(cancelBtn); - - const jobIdTd = addCell(jobTr); - jobIdTd.appendChild(document.createTextNode(jobId)); - - let jobStatusTd = addCell(jobTr); - jobStatusTd.id = `${jobId}-status`; - jobStatusTd.appendChild(document.createTextNode(status)); - - document.getElementById('printJobTbody').appendChild(jobTr); - } else { - document.getElementById(`${jobId}-status`).innerText = status; - if (status !== 'PENDING' && status !== 'IN_PROGRESS') { - jobTr.remove(); - } - } - }); -} - -document.addEventListener('DOMContentLoaded', () => { - createPrintersTable(); -}); diff --git a/api-samples/printing/roll-printing/test.pdf b/api-samples/printing/test-rollprinting.pdf similarity index 100% rename from api-samples/printing/roll-printing/test.pdf rename to api-samples/printing/test-rollprinting.pdf