spdf-to-printer
Version:
A utility to print PDF files from Node.js and Electron
1 lines • 3.58 kB
JavaScript
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(global,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=3)}([function(t,e,r){"use strict";const{execFile:n}=r(5);t.exports=(t,e=[],r)=>new Promise((i,o)=>{n(t,e,(t,e)=>{t?o(t):i(r?r(e):e)})})},function(t,e){t.exports=require("os")},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";switch(r(1).platform()){case"darwin":case"linux":t.exports={print:r(4),getPrinters:r(6),getDefaultPrinter:r(7)};break;case"win32":t.exports={print:r(8),getPrinters:r(11),getDefaultPrinter:r(12)};break;default:!function(){throw new Error("Platform not supported")}()}},function(t,e,r){"use strict";const n=r(2),i=r(0);t.exports=(t,e={})=>{if(!t)throw"No PDF specified";if("string"!=typeof t)throw"Invalid PDF name";if(!n.existsSync(t))throw"No such file";const r=[t],{printer:o,unix:s}=e;if(o&&r.push("-d",o),s){if(!Array.isArray(s))throw"options.unix should be an array";s.map(t=>r.push(...t.split(" ")))}return i("lp",r)}},function(t,e){t.exports=require("child_process")},function(t,e,r){"use strict";const n=r(0),i=r(1);t.exports=()=>{const t=t=>t.trim().split("\n").map(t=>t.indexOf(" ")>0?t.substr(0,t.indexOf(" ")):t);return console.log(t),n("lpstat","darwin"===i.platform()?["-e"]:["-a"],t)}},function(t,e,r){"use strict";const n=r(0);t.exports=()=>n("lpstat",["-d"],t=>t.substr(t.indexOf(":")+1).trim())},function(t,e,r){"use strict";const n=r(9),i=r(2),o=r(0),{fixPathForAsarUnpack:s}=r(10);t.exports=(t,e={})=>{if(!t)throw"No PDF specified";if("string"!=typeof t)throw"Invalid PDF name";if(!i.existsSync(t))throw"No such file";let r=n.join(__dirname,"SumatraPDF.exe");r=s(r);const u=[],{printer:c,win32:p}=e;if(c?u.push("-print-to",c):u.push("-print-to-default"),p){if(!Array.isArray(p))throw"options.win32 should be an array";p.map(t=>u.push(...t.split(" ")))}return u.push("-silent",t),o(r,u)}},function(t,e){t.exports=require("path")},function(t,e,r){"use strict";r.r(e),r.d(e,"fixPathForAsarUnpack",(function(){return i}));const n="electron"in process.versions&&process.mainModule&&process.mainModule.filename.includes("app.asar"),i=t=>n?t.replace("app.asar","app.asar.unpacked"):t},function(t,e,r){"use strict";const n=r(0);t.exports=()=>n("wmic",["printer","get","name"],t=>t.trim().split(/\s*[\r\n]+/).slice(1))},function(t,e,r){"use strict";const n=r(0);t.exports=()=>n("wmic",["printer","get","name,default"],t=>{const e=t.trim().split(/\s*[\r\n]+/).slice(1).filter(t=>0===t.indexOf("TRUE"));return 0===e.length?"":e[0].replace(/TRUE\s+/,"")})}])}));