@esslassi/electron-printer 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +235 -167
- package/lib/electronPrinter.d.ts +52 -24
- package/lib/electronPrinter.js +82 -31
- package/package.json +1 -1
- package/src/linux_printer.cpp +312 -112
- package/src/linux_printer.h +21 -11
- package/src/mac_printer.cpp +317 -110
- package/src/mac_printer.h +21 -12
- package/src/main.cpp +42 -13
- package/src/print.cpp +288 -207
- package/src/printer_interface.h +48 -10
- package/src/windows_printer.cpp +271 -134
- package/src/windows_printer.h +40 -11
- package/test.js +120 -0
package/README.md
CHANGED
|
@@ -1,251 +1,319 @@
|
|
|
1
|
-
|
|
1
|
+
# 📦 @esslassi/electron-printer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cross-platform native printer driver for **Windows, macOS, and Linux**, built with Node-API (N-API).
|
|
4
|
+
Works in **Node.js** and **Electron**.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Supports:
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
* 🖨 List printers
|
|
9
|
+
* 📄 Print raw/text/command data
|
|
10
|
+
* 📁 Print files
|
|
11
|
+
* 📋 Get printer driver options
|
|
12
|
+
* 📑 Get selected paper size
|
|
13
|
+
* 📦 Get job status
|
|
14
|
+
* ⛔ Cancel / pause / resume jobs
|
|
15
|
+
* 🔄 Promise (async/await) wrappers included
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
---
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
* Get the system default printer
|
|
13
|
-
* Get detailed printer status
|
|
14
|
-
* Direct printing (raw printing)
|
|
15
|
-
* TypeScript support
|
|
16
|
-
* Asynchronous API (Promises)
|
|
17
|
-
* Compatible with Node.js and Electron
|
|
19
|
+
## 🚀 Installation
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
```bash
|
|
22
|
+
npm install @esslassi/electron-printer
|
|
23
|
+
```
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
* Electron >= 20.0.0
|
|
23
|
-
* Windows or Linux
|
|
24
|
-
* For Windows: Visual Studio Build Tools
|
|
25
|
-
* For Linux: CUPS development headers
|
|
25
|
+
If using Electron:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
|
|
28
|
+
npx electron-rebuild
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🧩 Supported Platforms
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
| OS | Backend |
|
|
36
|
+
| ------- | ------------ |
|
|
37
|
+
| Windows | WinSpool API |
|
|
38
|
+
| macOS | CUPS |
|
|
39
|
+
| Linux | CUPS |
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# 📖 Usage
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import * as printer from '@esslassi/electron-printer'
|
|
35
47
|
```
|
|
36
48
|
|
|
37
|
-
|
|
49
|
+
---
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
# 🖨 Printer Management
|
|
52
|
+
|
|
53
|
+
### Get all printers
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const printers = printer.getPrinters()
|
|
44
57
|
```
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
### Async version
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
```ts
|
|
62
|
+
const printers = await printer.getPrintersAsync()
|
|
63
|
+
```
|
|
49
64
|
|
|
50
|
-
|
|
51
|
-
const printer = require('@esslassi/electron-printer');
|
|
65
|
+
---
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
printer.getPrinters()
|
|
55
|
-
.then(printers => {
|
|
56
|
-
console.log('Available printers:', printers);
|
|
57
|
-
})
|
|
58
|
-
.catch(console.error);
|
|
67
|
+
### Get single printer
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
printer.
|
|
62
|
-
|
|
63
|
-
console.log('Default printer:', defaultPrinter);
|
|
64
|
-
})
|
|
65
|
-
.catch(console.error);
|
|
69
|
+
```ts
|
|
70
|
+
const details = printer.getPrinter("My Printer")
|
|
71
|
+
```
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Print directly
|
|
75
|
-
const printOptions = {
|
|
76
|
-
printerName: 'Printer Name',
|
|
77
|
-
data: 'Text to print',
|
|
78
|
-
dataType: 'RAW' // optional (default is 'RAW')
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
printer.printDirect(printOptions)
|
|
82
|
-
.then(result => {
|
|
83
|
-
console.log('Result:', result);
|
|
84
|
-
})
|
|
85
|
-
.catch(console.error);
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### Get default printer
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const defaultPrinter = printer.getDefaultPrinterName()
|
|
86
79
|
```
|
|
87
80
|
|
|
88
|
-
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### Get printer driver options
|
|
89
84
|
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} from '@esslassi/electron-printer';
|
|
85
|
+
```ts
|
|
86
|
+
const options = printer.getPrinterDriverOptions("My Printer")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const printers: Printer[] = await printer.getPrinters();
|
|
100
|
-
console.log('Printers:', printers);
|
|
91
|
+
### Get selected paper size
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
```ts
|
|
94
|
+
const paper = printer.getSelectedPaperSize("My Printer")
|
|
95
|
+
```
|
|
104
96
|
|
|
105
|
-
|
|
106
|
-
printerName: 'Printer Name'
|
|
107
|
-
};
|
|
108
|
-
const status: Printer = await printer.getStatusPrinter(statusOptions);
|
|
109
|
-
console.log('Status:', status);
|
|
97
|
+
---
|
|
110
98
|
|
|
111
|
-
|
|
112
|
-
printerName: 'Printer Name',
|
|
113
|
-
data: Buffer.from('Text to print'),
|
|
114
|
-
dataType: 'RAW'
|
|
115
|
-
};
|
|
99
|
+
# 🖨 Printing
|
|
116
100
|
|
|
117
|
-
|
|
118
|
-
console.log('Result:', result);
|
|
101
|
+
---
|
|
119
102
|
|
|
120
|
-
|
|
121
|
-
|
|
103
|
+
## 🟢 Print Raw/Text Data (Callback)
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
printer.printDirect({
|
|
107
|
+
data: "Hello Printer\n\n",
|
|
108
|
+
printer: "My Printer",
|
|
109
|
+
type: "RAW",
|
|
110
|
+
success: (jobId) => {
|
|
111
|
+
console.log("Printed. Job ID:", jobId)
|
|
112
|
+
},
|
|
113
|
+
error: (err) => {
|
|
114
|
+
console.error("Print error:", err)
|
|
122
115
|
}
|
|
123
|
-
}
|
|
116
|
+
})
|
|
124
117
|
```
|
|
125
118
|
|
|
126
|
-
|
|
119
|
+
---
|
|
127
120
|
|
|
128
|
-
|
|
121
|
+
## 🟢 Print Raw/Text Data (Async/Await)
|
|
129
122
|
|
|
130
|
-
|
|
123
|
+
```ts
|
|
124
|
+
const jobId = await printer.printDirectAsync({
|
|
125
|
+
data: Buffer.from("Hello Printer\n\n"),
|
|
126
|
+
printer: "My Printer",
|
|
127
|
+
type: "RAW"
|
|
128
|
+
})
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
interface Printer {
|
|
134
|
-
name: string;
|
|
135
|
-
isDefault: boolean;
|
|
136
|
-
status: string;
|
|
137
|
-
details: {
|
|
138
|
-
location?: string;
|
|
139
|
-
comment?: string;
|
|
140
|
-
driver?: string;
|
|
141
|
-
port?: string;
|
|
142
|
-
[key: string]: string | undefined;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
130
|
+
console.log("Printed. Job ID:", jobId)
|
|
145
131
|
```
|
|
146
132
|
|
|
147
133
|
---
|
|
148
134
|
|
|
149
|
-
|
|
135
|
+
## 🟢 Print File (Callback)
|
|
150
136
|
|
|
151
|
-
|
|
137
|
+
```ts
|
|
138
|
+
printer.printFile({
|
|
139
|
+
filename: "./file.txt",
|
|
140
|
+
printer: "My Printer",
|
|
141
|
+
success: (jobId) => console.log(jobId),
|
|
142
|
+
error: (err) => console.error(err)
|
|
143
|
+
})
|
|
144
|
+
```
|
|
152
145
|
|
|
153
146
|
---
|
|
154
147
|
|
|
155
|
-
|
|
148
|
+
## 🟢 Print File (Async)
|
|
156
149
|
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
```ts
|
|
151
|
+
const jobId = await printer.printFileAsync({
|
|
152
|
+
filename: "./file.txt",
|
|
153
|
+
printer: "My Printer"
|
|
154
|
+
})
|
|
161
155
|
```
|
|
162
156
|
|
|
163
157
|
---
|
|
164
158
|
|
|
165
|
-
|
|
159
|
+
# 📦 Job Management
|
|
166
160
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Get Job Details
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
const job = printer.getJob("My Printer", 42)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Async
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
const job = await printer.getJobAsync("My Printer", 42)
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Cancel / Pause / Resume Job
|
|
176
178
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* manual-feed
|
|
183
|
-
* paper-problem
|
|
184
|
-
* busy
|
|
185
|
-
* printing
|
|
186
|
-
* output-bin-full
|
|
187
|
-
* not-available
|
|
188
|
-
* waiting
|
|
189
|
-
* processing
|
|
190
|
-
* initializing
|
|
191
|
-
* warming-up
|
|
192
|
-
* toner-low
|
|
193
|
-
* no-toner
|
|
194
|
-
* page-punt
|
|
195
|
-
* user-intervention
|
|
196
|
-
* out-of-memory
|
|
197
|
-
* door-open
|
|
179
|
+
```ts
|
|
180
|
+
printer.setJob("My Printer", 42, "CANCEL")
|
|
181
|
+
printer.setJob("My Printer", 42, "PAUSE")
|
|
182
|
+
printer.setJob("My Printer", 42, "RESUME")
|
|
183
|
+
```
|
|
198
184
|
|
|
199
185
|
---
|
|
200
186
|
|
|
201
|
-
## Supported
|
|
187
|
+
## Get Supported Job Commands
|
|
202
188
|
|
|
203
|
-
|
|
204
|
-
|
|
189
|
+
```ts
|
|
190
|
+
const commands = printer.getSupportedJobCommands()
|
|
191
|
+
```
|
|
205
192
|
|
|
206
193
|
---
|
|
207
194
|
|
|
208
|
-
|
|
195
|
+
# 📄 Supported Print Formats
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const formats = printer.getSupportedPrintFormats()
|
|
199
|
+
```
|
|
209
200
|
|
|
210
|
-
|
|
201
|
+
Typical values:
|
|
211
202
|
|
|
212
|
-
|
|
213
|
-
|
|
203
|
+
* `RAW`
|
|
204
|
+
* `TEXT`
|
|
205
|
+
* `COMMAND`
|
|
206
|
+
* `AUTO`
|
|
214
207
|
|
|
215
|
-
|
|
216
|
-
|
|
208
|
+
> Windows supports RAW/TEXT/COMMAND directly.
|
|
209
|
+
> macOS/Linux support additional formats via CUPS.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
# 🧠 TypeScript Types
|
|
214
|
+
|
|
215
|
+
Fully typed. Example:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
export interface PrintDirectOptions {
|
|
219
|
+
data: string | Buffer
|
|
220
|
+
printer?: string
|
|
221
|
+
type?: 'RAW' | 'TEXT' | 'COMMAND' | 'AUTO'
|
|
222
|
+
options?: { [key: string]: string }
|
|
223
|
+
}
|
|
217
224
|
```
|
|
218
225
|
|
|
219
|
-
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
# ⚡ Promise Wrappers Included
|
|
220
229
|
|
|
221
|
-
|
|
230
|
+
Built-in async wrappers:
|
|
222
231
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
232
|
+
* `printDirectAsync`
|
|
233
|
+
* `printFileAsync`
|
|
234
|
+
* `getPrintersAsync`
|
|
235
|
+
* `getPrinterAsync`
|
|
236
|
+
* `getJobAsync`
|
|
237
|
+
|
|
238
|
+
No extra wrapper needed.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
# 🧪 Example Full Test
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import * as printer from '@esslassi/electron-printer'
|
|
246
|
+
|
|
247
|
+
async function test() {
|
|
248
|
+
const printers = await printer.getPrintersAsync()
|
|
249
|
+
const defaultPrinter = printer.getDefaultPrinterName()
|
|
250
|
+
|
|
251
|
+
const jobId = await printer.printDirectAsync({
|
|
252
|
+
data: "Test print\n\n",
|
|
253
|
+
printer: defaultPrinter,
|
|
254
|
+
type: "RAW"
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
const job = await printer.getJobAsync(defaultPrinter!, Number(jobId))
|
|
258
|
+
|
|
259
|
+
console.log(job)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
test()
|
|
227
263
|
```
|
|
228
264
|
|
|
229
265
|
---
|
|
230
266
|
|
|
231
|
-
|
|
267
|
+
# 🏗 Architecture
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
Node.js / Electron
|
|
271
|
+
↓
|
|
272
|
+
N-API
|
|
273
|
+
↓
|
|
274
|
+
PrinterFactory
|
|
275
|
+
↓
|
|
276
|
+
Windows | macOS | Linux drivers
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Native C++ backend with platform-specific implementations.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
# 🔧 Development
|
|
284
|
+
|
|
285
|
+
Build from source:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npx node-gyp rebuild
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Electron:
|
|
232
292
|
|
|
233
293
|
```bash
|
|
234
|
-
|
|
235
|
-
cd electron-printer
|
|
236
|
-
npm install
|
|
237
|
-
npm run rebuild
|
|
238
|
-
node test.js
|
|
294
|
+
npx electron-rebuild
|
|
239
295
|
```
|
|
240
296
|
|
|
241
297
|
---
|
|
242
298
|
|
|
243
|
-
|
|
299
|
+
# 📜 License
|
|
244
300
|
|
|
245
301
|
MIT
|
|
246
302
|
|
|
247
303
|
---
|
|
248
304
|
|
|
249
|
-
|
|
305
|
+
# 👨💻 Author
|
|
306
|
+
|
|
307
|
+
Esslassi
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
If you want, I can also generate:
|
|
312
|
+
|
|
313
|
+
* 🔥 NPM package.json template
|
|
314
|
+
* 🧱 binding.gyp optimized version
|
|
315
|
+
* ⚡ Prebuild support (no node-gyp required for users)
|
|
316
|
+
* 🧪 Jest test suite
|
|
317
|
+
* 📦 CLI tool version
|
|
250
318
|
|
|
251
|
-
|
|
319
|
+
Tell me the next step 🚀
|
package/lib/electronPrinter.d.ts
CHANGED
|
@@ -1,33 +1,61 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type PrintOnSuccessFunction = (jobId: string) => any;
|
|
2
|
+
export type PrintOnErrorFunction = (err: Error) => any;
|
|
3
|
+
export interface PrintDirectOptions {
|
|
3
4
|
data: string | Buffer;
|
|
4
|
-
|
|
5
|
+
printer?: string;
|
|
6
|
+
type?: 'RAW' | 'TEXT' | 'COMMAND' | 'AUTO';
|
|
7
|
+
options?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
success?: PrintOnSuccessFunction;
|
|
11
|
+
error?: PrintOnErrorFunction;
|
|
5
12
|
}
|
|
6
|
-
export interface
|
|
13
|
+
export interface PrintFileOptions {
|
|
14
|
+
filename: string;
|
|
15
|
+
printer?: string;
|
|
16
|
+
success?: PrintOnSuccessFunction;
|
|
17
|
+
error?: PrintOnErrorFunction;
|
|
18
|
+
}
|
|
19
|
+
export interface PrinterDetails {
|
|
7
20
|
name: string;
|
|
8
21
|
isDefault: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
location?: string;
|
|
12
|
-
comment?: string;
|
|
13
|
-
driver?: string;
|
|
14
|
-
port?: string;
|
|
15
|
-
[key: string]: string | undefined;
|
|
22
|
+
options: {
|
|
23
|
+
[key: string]: string;
|
|
16
24
|
};
|
|
17
25
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export interface GetStatusPrinterOptions {
|
|
24
|
-
printerName: string;
|
|
26
|
+
export interface PrinterDriverOptions {
|
|
27
|
+
[key: string]: {
|
|
28
|
+
[key: string]: boolean;
|
|
29
|
+
};
|
|
25
30
|
}
|
|
26
|
-
export
|
|
31
|
+
export type JobStatus = 'PAUSED' | 'PRINTING' | 'PRINTED' | 'CANCELLED' | 'PENDING' | 'ABORTED';
|
|
32
|
+
export type JobCommand = "CANCEL" | "PAUSE" | "RESUME";
|
|
33
|
+
export interface JobDetails {
|
|
34
|
+
id: number;
|
|
27
35
|
name: string;
|
|
28
|
-
|
|
36
|
+
printerName: string;
|
|
37
|
+
user: string;
|
|
38
|
+
format: string;
|
|
39
|
+
priority: number;
|
|
40
|
+
size: number;
|
|
41
|
+
status: JobStatus[];
|
|
42
|
+
completedTime: Date;
|
|
43
|
+
creationTime: Date;
|
|
44
|
+
processingTime: Date;
|
|
29
45
|
}
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
46
|
+
export declare function getPrinters(): PrinterDetails[];
|
|
47
|
+
export declare function getPrinter(printerName: string): PrinterDetails;
|
|
48
|
+
export declare function getPrinterDriverOptions(printerName: string): PrinterDriverOptions;
|
|
49
|
+
export declare function getSelectedPaperSize(printerName: string): string;
|
|
50
|
+
export declare function getDefaultPrinterName(): string | undefined;
|
|
51
|
+
export declare function printDirect(options: PrintDirectOptions): void;
|
|
52
|
+
export declare function printFile(options: PrintFileOptions): void;
|
|
53
|
+
export declare function getSupportedPrintFormats(): string[];
|
|
54
|
+
export declare function getJob(printerName: string, jobId: number): JobDetails;
|
|
55
|
+
export declare function setJob(printerName: string, jobId: number, command: JobCommand): void;
|
|
56
|
+
export declare function getSupportedJobCommands(): string[];
|
|
57
|
+
export declare function printDirectAsync(options: Omit<PrintDirectOptions, 'success' | 'error'>): Promise<string>;
|
|
58
|
+
export declare function printFileAsync(options: Omit<PrintFileOptions, 'success' | 'error'>): Promise<string>;
|
|
59
|
+
export declare function getJobAsync(printerName: string, jobId: number): Promise<JobDetails>;
|
|
60
|
+
export declare function getPrintersAsync(): Promise<PrinterDetails[]>;
|
|
61
|
+
export declare function getPrinterAsync(printerName: string): Promise<PrinterDetails>;
|
package/lib/electronPrinter.js
CHANGED
|
@@ -3,36 +3,87 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.printDirect = printDirect;
|
|
7
|
-
exports.getStatusPrinter = getStatusPrinter;
|
|
8
6
|
exports.getPrinters = getPrinters;
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
7
|
+
exports.getPrinter = getPrinter;
|
|
8
|
+
exports.getPrinterDriverOptions = getPrinterDriverOptions;
|
|
9
|
+
exports.getSelectedPaperSize = getSelectedPaperSize;
|
|
10
|
+
exports.getDefaultPrinterName = getDefaultPrinterName;
|
|
11
|
+
exports.printDirect = printDirect;
|
|
12
|
+
exports.printFile = printFile;
|
|
13
|
+
exports.getSupportedPrintFormats = getSupportedPrintFormats;
|
|
14
|
+
exports.getJob = getJob;
|
|
15
|
+
exports.setJob = setJob;
|
|
16
|
+
exports.getSupportedJobCommands = getSupportedJobCommands;
|
|
17
|
+
exports.printDirectAsync = printDirectAsync;
|
|
18
|
+
exports.printFileAsync = printFileAsync;
|
|
19
|
+
exports.getJobAsync = getJobAsync;
|
|
20
|
+
exports.getPrintersAsync = getPrintersAsync;
|
|
21
|
+
exports.getPrinterAsync = getPrinterAsync;
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const native = require(path_1.default.join(__dirname, '../build/Release/electron_printer.node'));
|
|
24
|
+
/* ===========================
|
|
25
|
+
DIRECT NATIVE EXPORTS
|
|
26
|
+
=========================== */
|
|
27
|
+
function getPrinters() {
|
|
28
|
+
return native.getPrinters();
|
|
29
|
+
}
|
|
30
|
+
function getPrinter(printerName) {
|
|
31
|
+
return native.getPrinter(printerName);
|
|
32
|
+
}
|
|
33
|
+
function getPrinterDriverOptions(printerName) {
|
|
34
|
+
return native.getPrinterDriverOptions(printerName);
|
|
35
|
+
}
|
|
36
|
+
function getSelectedPaperSize(printerName) {
|
|
37
|
+
return native.getSelectedPaperSize(printerName);
|
|
38
|
+
}
|
|
39
|
+
function getDefaultPrinterName() {
|
|
40
|
+
return native.getDefaultPrinterName();
|
|
41
|
+
}
|
|
42
|
+
function printDirect(options) {
|
|
43
|
+
native.printDirect(options);
|
|
44
|
+
}
|
|
45
|
+
function printFile(options) {
|
|
46
|
+
native.printFile(options);
|
|
47
|
+
}
|
|
48
|
+
function getSupportedPrintFormats() {
|
|
49
|
+
return native.getSupportedPrintFormats();
|
|
50
|
+
}
|
|
51
|
+
function getJob(printerName, jobId) {
|
|
52
|
+
return native.getJob(printerName, jobId);
|
|
53
|
+
}
|
|
54
|
+
function setJob(printerName, jobId, command) {
|
|
55
|
+
native.setJob(printerName, jobId, command);
|
|
56
|
+
}
|
|
57
|
+
function getSupportedJobCommands() {
|
|
58
|
+
return native.getSupportedJobCommands();
|
|
59
|
+
}
|
|
60
|
+
/* ==================================================
|
|
61
|
+
PROMISE WRAPPERS (Async/Await Friendly)
|
|
62
|
+
================================================== */
|
|
63
|
+
function printDirectAsync(options) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
native.printDirect({
|
|
66
|
+
...options,
|
|
67
|
+
success: (jobId) => resolve(jobId),
|
|
68
|
+
error: (err) => reject(err)
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function printFileAsync(options) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
native.printFile({
|
|
75
|
+
...options,
|
|
76
|
+
success: (jobId) => resolve(jobId),
|
|
77
|
+
error: (err) => reject(err)
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function getJobAsync(printerName, jobId) {
|
|
82
|
+
return Promise.resolve(native.getJob(printerName, jobId));
|
|
83
|
+
}
|
|
84
|
+
function getPrintersAsync() {
|
|
85
|
+
return Promise.resolve(native.getPrinters());
|
|
86
|
+
}
|
|
87
|
+
function getPrinterAsync(printerName) {
|
|
88
|
+
return Promise.resolve(native.getPrinter(printerName));
|
|
38
89
|
}
|