我有一个pritter通过USB端口连接到我的电脑.我运行Windows 7.
这是简单的代码:
var ipp=require('ipp')
var fs = require('fs');
fs.readFile('filename.pdf', function(err, data) {
if (err)
throw err;
var printer = ipp.Printer("http://localhost/ipp/printer");
var msg = {
"operation-attributes-tag": {
"requesting-user-name": "William",
"job-name": "My Test Job",
"document-format": "application/pdf"
},
data: data
};
printer.execute("Print-Job", msg, function(err, res){
if(err){
console.log(err);
}
console.log(res);
});
});
Run Code Online (Sandbox Code Playgroud)
我如何解决我的本地priter地址写在这里:
var printer = ipp.Printer("http://localhost/ipp/printer");
Run Code Online (Sandbox Code Playgroud)
?
任何人都知道如何为 Node.js 设置 USB 打印机。我无法为其配置界面。这是我的代码
enter code here const ThermalPrinter = require("../node-thermal-printer").printer;
const Types = require("../node-thermal-printer").types;
const electron = typeof process !== 'undefined' && process.versions &&
!!process.versions.electron;
async function testConnection () {
let printer = new ThermalPrinter({
type: 'star',
interface: "Gold" //name of the printer
});
printer.print("hi");
let isConnected = await printer.isPrinterConnected()
console.log("Printer connected:", isConnected);
}
testConnection();
Run Code Online (Sandbox Code Playgroud)