UNPKG

spdf-to-printer

Version:

A utility to print PDF files from Node.js and Electron

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