@esslassi/electron-printer 0.0.5 → 0.0.7

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 CHANGED
@@ -1,251 +1,319 @@
1
- Here is the clean **README.md** content ready to copy and paste:
2
-
3
- ---
4
-
5
- # Electron Printer (@esslassi/electron-printer)
6
-
7
- Node.js and Electron bindings for printer management and direct printing. Supports Windows and Linux (CUPS).
8
-
9
- ## Features
10
-
11
- * List all available printers
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
18
-
19
- ## Requirements
20
-
21
- * Node.js >= 18.20.6
22
- * Electron >= 20.0.0
23
- * Windows or Linux
24
- * For Windows: Visual Studio Build Tools
25
- * For Linux: CUPS development headers
26
-
27
- ```bash
28
- sudo apt-get install libcups2-dev
29
- ```
30
-
31
- ## Installation
32
-
33
- ```bash
34
- npm install @esslassi/electron-printer
35
- ```
36
-
37
- For development:
38
-
39
- ```bash
40
- git clone https://github.com/esslassi/electron-printer.git
41
- cd electron-printer
42
- npm install
43
- npm run rebuild
44
- ```
45
-
46
- ## Usage
47
-
48
- ### JavaScript
49
-
50
- ```javascript
51
- const printer = require('@esslassi/electron-printer');
52
-
53
- // List all printers
54
- printer.getPrinters()
55
- .then(printers => {
56
- console.log('Available printers:', printers);
57
- })
58
- .catch(console.error);
59
-
60
- // Get default printer
61
- printer.getDefaultPrinter()
62
- .then(defaultPrinter => {
63
- console.log('Default printer:', defaultPrinter);
64
- })
65
- .catch(console.error);
66
-
67
- // Check printer status
68
- printer.getStatusPrinter({ printerName: 'Printer Name' })
69
- .then(status => {
70
- console.log('Printer status:', status);
71
- })
72
- .catch(console.error);
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);
86
- ```
87
-
88
- ### TypeScript
89
-
90
- ```typescript
91
- import printer, {
92
- Printer,
93
- PrintDirectOptions,
94
- GetStatusPrinterOptions
95
- } from '@esslassi/electron-printer';
96
-
97
- async function example() {
98
- try {
99
- const printers: Printer[] = await printer.getPrinters();
100
- console.log('Printers:', printers);
101
-
102
- const defaultPrinter: Printer = await printer.getDefaultPrinter();
103
- console.log('Default printer:', defaultPrinter);
104
-
105
- const statusOptions: GetStatusPrinterOptions = {
106
- printerName: 'Printer Name'
107
- };
108
- const status: Printer = await printer.getStatusPrinter(statusOptions);
109
- console.log('Status:', status);
110
-
111
- const printOptions: PrintDirectOptions = {
112
- printerName: 'Printer Name',
113
- data: Buffer.from('Text to print'),
114
- dataType: 'RAW'
115
- };
116
-
117
- const result = await printer.printDirect(printOptions);
118
- console.log('Result:', result);
119
-
120
- } catch (error) {
121
- console.error('Error:', error);
122
- }
123
- }
124
- ```
125
-
126
- ## API
127
-
128
- ### getPrinters(): Promise<Printer[]>
129
-
130
- Lists all printers installed on the system.
131
-
132
- ```typescript
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
- }
145
- ```
146
-
147
- ---
148
-
149
- ### getDefaultPrinter(): Promise<Printer>
150
-
151
- Returns the system default printer.
152
-
153
- ---
154
-
155
- ### getStatusPrinter(options: GetStatusPrinterOptions): Promise<Printer>
156
-
157
- ```typescript
158
- interface GetStatusPrinterOptions {
159
- printerName: string;
160
- }
161
- ```
162
-
163
- ---
164
-
165
- ### printDirect(options: PrintDirectOptions): Promise<string>
166
-
167
- ```typescript
168
- interface PrintDirectOptions {
169
- printerName: string;
170
- data: string | Buffer;
171
- dataType?: 'RAW' | 'TEXT' | 'COMMAND' | 'AUTO';
172
- }
173
- ```
174
-
175
- ### Possible Status Values
176
-
177
- * ready
178
- * offline
179
- * error
180
- * paper-jam
181
- * paper-out
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
198
-
199
- ---
200
-
201
- ## Supported Platforms
202
-
203
- * Windows (32/64-bit)
204
- * Linux (CUPS)
205
-
206
- ---
207
-
208
- ## Troubleshooting
209
-
210
- ### Windows
211
-
212
- 1. Install Visual Studio Build Tools
213
- 2. Run:
214
-
215
- ```bash
216
- npm run rebuild
217
- ```
218
-
219
- 3. Verify printer access permissions
220
-
221
- ### Linux
222
-
223
- ```bash
224
- sudo apt-get install libcups2-dev
225
- sudo service cups status
226
- sudo usermod -a -G lp $USER
227
- ```
228
-
229
- ---
230
-
231
- ## Development
232
-
233
- ```bash
234
- git clone https://github.com/esslassi/electron-printer.git
235
- cd electron-printer
236
- npm install
237
- npm run rebuild
238
- node test.js
239
- ```
240
-
241
- ---
242
-
243
- ## License
244
-
245
- MIT
246
-
247
- ---
248
-
249
- ## Author
250
-
251
- Esslassi
1
+ # 📦 @esslassi/electron-printer
2
+
3
+ Cross-platform native printer driver for **Windows, macOS, and Linux**, built with Node-API (N-API).
4
+ Works in **Node.js** and **Electron**.
5
+
6
+ Supports:
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
16
+
17
+ ---
18
+
19
+ ## 🚀 Installation
20
+
21
+ ```bash
22
+ npm install @esslassi/electron-printer
23
+ ```
24
+
25
+ If using Electron:
26
+
27
+ ```bash
28
+ npx electron-rebuild
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 🧩 Supported Platforms
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'
47
+ ```
48
+
49
+ ---
50
+
51
+ # 🖨 Printer Management
52
+
53
+ ### Get all printers
54
+
55
+ ```ts
56
+ const printers = printer.getPrinters()
57
+ ```
58
+
59
+ ### Async version
60
+
61
+ ```ts
62
+ const printers = await printer.getPrintersAsync()
63
+ ```
64
+
65
+ ---
66
+
67
+ ### Get single printer
68
+
69
+ ```ts
70
+ const details = printer.getPrinter("My Printer")
71
+ ```
72
+
73
+ ---
74
+
75
+ ### Get default printer
76
+
77
+ ```ts
78
+ const defaultPrinter = printer.getDefaultPrinterName()
79
+ ```
80
+
81
+ ---
82
+
83
+ ### Get printer driver options
84
+
85
+ ```ts
86
+ const options = printer.getPrinterDriverOptions("My Printer")
87
+ ```
88
+
89
+ ---
90
+
91
+ ### Get selected paper size
92
+
93
+ ```ts
94
+ const paper = printer.getSelectedPaperSize("My Printer")
95
+ ```
96
+
97
+ ---
98
+
99
+ # 🖨 Printing
100
+
101
+ ---
102
+
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)
115
+ }
116
+ })
117
+ ```
118
+
119
+ ---
120
+
121
+ ## 🟢 Print Raw/Text Data (Async/Await)
122
+
123
+ ```ts
124
+ const jobId = await printer.printDirectAsync({
125
+ data: Buffer.from("Hello Printer\n\n"),
126
+ printer: "My Printer",
127
+ type: "RAW"
128
+ })
129
+
130
+ console.log("Printed. Job ID:", jobId)
131
+ ```
132
+
133
+ ---
134
+
135
+ ## 🟢 Print File (Callback)
136
+
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
+ ```
145
+
146
+ ---
147
+
148
+ ## 🟢 Print File (Async)
149
+
150
+ ```ts
151
+ const jobId = await printer.printFileAsync({
152
+ filename: "./file.txt",
153
+ printer: "My Printer"
154
+ })
155
+ ```
156
+
157
+ ---
158
+
159
+ # 📦 Job Management
160
+
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
+ ```
174
+
175
+ ---
176
+
177
+ ## Cancel / Pause / Resume Job
178
+
179
+ ```ts
180
+ printer.setJob("My Printer", 42, "CANCEL")
181
+ printer.setJob("My Printer", 42, "PAUSE")
182
+ printer.setJob("My Printer", 42, "RESUME")
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Get Supported Job Commands
188
+
189
+ ```ts
190
+ const commands = printer.getSupportedJobCommands()
191
+ ```
192
+
193
+ ---
194
+
195
+ # 📄 Supported Print Formats
196
+
197
+ ```ts
198
+ const formats = printer.getSupportedPrintFormats()
199
+ ```
200
+
201
+ Typical values:
202
+
203
+ * `RAW`
204
+ * `TEXT`
205
+ * `COMMAND`
206
+ * `AUTO`
207
+
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
+ }
224
+ ```
225
+
226
+ ---
227
+
228
+ # ⚡ Promise Wrappers Included
229
+
230
+ Built-in async wrappers:
231
+
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()
263
+ ```
264
+
265
+ ---
266
+
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:
292
+
293
+ ```bash
294
+ npx electron-rebuild
295
+ ```
296
+
297
+ ---
298
+
299
+ # 📜 License
300
+
301
+ MIT
302
+
303
+ ---
304
+
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
318
+
319
+ Tell me the next step 🚀
package/binding.gyp CHANGED
@@ -1,57 +1,57 @@
1
- {
2
- "targets": [
3
- {
4
- "target_name": "electron_printer",
5
- "sources": [
6
- "src/main.cpp",
7
- "src/print.cpp",
8
- "src/printer_factory.cpp"
9
- ],
10
- "include_dirs": [
11
- "<!@(node -p \"require('node-addon-api').include\")"
12
- ],
13
- "dependencies": [
14
- "<!(node -p \"require('node-addon-api').gyp\")"
15
- ],
16
- "defines": [ "NAPI_CPP_EXCEPTIONS" ],
17
- "conditions": [
18
- ['OS=="win"', {
19
- "sources": ["src/windows_printer.cpp"],
20
- "libraries": ["winspool.lib"],
21
- "msvs_settings": {
22
- "VCCLCompilerTool": {
23
- "ExceptionHandling": 1
24
- }
25
- }
26
- }],
27
- ['OS=="mac"', {
28
- "sources": ["src/mac_printer.cpp"],
29
- "libraries": ["-lcups"],
30
- "include_dirs": [
31
- "/usr/include/cups"
32
- ],
33
- "xcode_settings": {
34
- "OTHER_CFLAGS": ["-Wall"],
35
- "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
36
- "CLANG_CXX_LIBRARY": "libc++",
37
- "MACOSX_DEPLOYMENT_TARGET": "10.7"
38
- }
39
- }],
40
- ['OS=="linux"', {
41
- "sources": ["src/linux_printer.cpp"],
42
- "libraries": ["-lcups"],
43
- "include_dirs": [
44
- "/usr/include/cups"
45
- ],
46
- "cflags": [
47
- "-Wall",
48
- "-fexceptions"
49
- ],
50
- "cflags_cc": [
51
- "-fexceptions"
52
- ]
53
- }]
54
- ]
55
- }
56
- ]
57
- }
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "electron_printer",
5
+ "sources": [
6
+ "src/main.cpp",
7
+ "src/print.cpp",
8
+ "src/printer_factory.cpp"
9
+ ],
10
+ "include_dirs": [
11
+ "<!@(node -p \"require('node-addon-api').include\")"
12
+ ],
13
+ "dependencies": [
14
+ "<!(node -p \"require('node-addon-api').gyp\")"
15
+ ],
16
+ "defines": [ "NAPI_CPP_EXCEPTIONS" ],
17
+ "conditions": [
18
+ ['OS=="win"', {
19
+ "sources": ["src/windows_printer.cpp"],
20
+ "libraries": ["winspool.lib"],
21
+ "msvs_settings": {
22
+ "VCCLCompilerTool": {
23
+ "ExceptionHandling": 1
24
+ }
25
+ }
26
+ }],
27
+ ['OS=="mac"', {
28
+ "sources": ["src/mac_printer.cpp"],
29
+ "libraries": ["-lcups"],
30
+ "include_dirs": [
31
+ "/usr/include/cups"
32
+ ],
33
+ "xcode_settings": {
34
+ "OTHER_CFLAGS": ["-Wall"],
35
+ "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
36
+ "CLANG_CXX_LIBRARY": "libc++",
37
+ "MACOSX_DEPLOYMENT_TARGET": "10.7"
38
+ }
39
+ }],
40
+ ['OS=="linux"', {
41
+ "sources": ["src/linux_printer.cpp"],
42
+ "libraries": ["-lcups"],
43
+ "include_dirs": [
44
+ "/usr/include/cups"
45
+ ],
46
+ "cflags": [
47
+ "-Wall",
48
+ "-fexceptions"
49
+ ],
50
+ "cflags_cc": [
51
+ "-fexceptions"
52
+ ]
53
+ }]
54
+ ]
55
+ }
56
+ ]
57
+ }