._vue静默打印小票">
赞
踩
- //主进程监听调用
- 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)
- }
- )
-
- }
- });
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。