._vue静默打印小票">
当前位置:   article > 正文

electron-vue静默打印_vue静默打印小票

vue静默打印小票
  1. //主进程监听调用
  2. ipcMain.on("print", (event, args) => {
  3. createPrint(args, false);
  4. // PRINT.next(args);
  5. });
  6. function createPrint(config, debug) {
  7. const fs = require("fs");
  8. let def = {
  9. backgroundColor: "#fff",
  10. show: debug,
  11. };
  12. let win = new BrowserWindow(def);
  13. if (debug) {
  14. win.once("ready-to-show", () => {
  15. win.show();
  16. });
  17. }
  18. win.loadURL(config.url);
  19. win.webContents.on("did-finish-load", () => {
  20. if (debug) {
  21. win.webContents
  22. .printToPDF({
  23. pageSize: "A4",
  24. })
  25. .then((data) => {
  26. fs.writeFile("/tmp/print.pdf", data, (error) => {
  27. if (error) throw error;
  28. console.log("Write PDF successfully.");
  29. });
  30. })
  31. .catch((error) => {
  32. console.log(error);
  33. });
  34. } else {
  35. win.webContents.print(
  36. {
  37. silent: true,
  38. deviceName: config.code,
  39. margins:{
  40. marginType:"custom",
  41. },
  42. copies: parseInt(config.number)
  43. }
  44. )
  45. }
  46. });
  47. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/804752
推荐阅读
  

闽ICP备14008679号