|
@@ -1,5 +1,40 @@
|
|
|
+import { printDirect, getDefaultPrinterName, getJob } from 'printer'
|
|
|
|
|
|
+const requestPrint = ({data}) => {
|
|
|
+ data = data.replace(/(data:[a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+.*,)/, '')
|
|
|
|
|
|
-export const printHandler = () => {
|
|
|
- console.log('printing')
|
|
|
+ const buffer = Buffer.from(data, 'base64')
|
|
|
+ const asciiData = buffer.toString('ascii')
|
|
|
+
|
|
|
+ console.log(asciiData)
|
|
|
+
|
|
|
+ const defaultPrinter = getDefaultPrinterName()
|
|
|
+
|
|
|
+ printDirect({
|
|
|
+ data: asciiData,
|
|
|
+ printer: defaultPrinter,
|
|
|
+ type: 'PDF',
|
|
|
+ success: jobId => {
|
|
|
+ const job = getJob(defaultPrinter, jobId)
|
|
|
+
|
|
|
+ if (job.status.includes('PRINTING')) {
|
|
|
+ console.log('imprimiendo')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (job.status.includes('PRINTED')) {
|
|
|
+ console.log('impreso')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(job)
|
|
|
+ },
|
|
|
+ error: e => {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export const printHandler = socket => {
|
|
|
+ socket.on('request-print', requestPrint)
|
|
|
}
|