electron-vue静默打印

    科技2025-10-12  3

    //主进程监听调用 ipcMain.on("print", (event, args) => { createPrint(args, false); // PRINT.next(args); }); function createPrint(config, debug) { const fs = require("fs"); let def = { backgroundColor: "#fff", show: debug, }; let win = new BrowserWindow(def); if (debug) { win.once("ready-to-show", () => { win.show(); }); } win.loadURL(config.url); win.webContents.on("did-finish-load", () => { if (debug) { win.webContents .printToPDF({ pageSize: "A4", }) .then((data) => { fs.writeFile("/tmp/print.pdf", data, (error) => { if (error) throw error; console.log("Write PDF successfully."); }); }) .catch((error) => { console.log(error); }); } else { win.webContents.print( { silent: true, deviceName: config.code, margins:{ marginType:"custom", }, copies: parseInt(config.number) } ) } }); }

     

    Processed: 0.011, SQL: 8