To get printer information, there are two methods provided by the chrome.printing API
:
- getPrinters returns a list of available printers with their ID, name, and description.
- getPrinterInfo takes the printer ID and returns the capabilities of that printer.
We will use both of these methods when we build printers.html.
Copy the following code into printers.html to show all the available printers:
Create a file named printers.css
. This CSS file will provide styling. Copy the following code:
Now, add functions to retrieve available printers in printers.js
.
The following code will:
- Call
chrome.printing.getPrinters()
to get all available printers. - Call
chrome.printing.getPrinterInfo()
with the printer.id from the getPrinters()
response to get more detailed information, including capabilities.
You can see an example of the capabilities returned here:
Update your printers.js
file to the below:
Now, you have a page that will display a table of printers, including their capabilities.