@capgo/capacitor-printer 7.0.0
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/CapgoPrinter.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +353 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/capgo/printer/Printer.java +362 -0
- package/android/src/main/java/com/capgo/printer/PrinterPlugin.java +122 -0
- package/dist/docs.json +520 -0
- package/dist/esm/definitions.d.ts +489 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +106 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +120 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +123 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PrinterPlugin/Printer.swift +207 -0
- package/ios/Sources/PrinterPlugin/PrinterPlugin.swift +148 -0
- package/ios/Tests/PrinterPluginTests/PrinterPluginTests.swift +10 -0
- package/package.json +85 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
export interface PrinterPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Presents the printing UI to print files encoded as base64 strings.
|
|
4
|
+
*
|
|
5
|
+
* **Platform Behavior:**
|
|
6
|
+
* - **iOS**: Uses UIPrintInteractionController with base64 decoded data
|
|
7
|
+
* - **Android**: Uses PrintManager with base64 decoded data
|
|
8
|
+
* - **Web**: Creates a blob from base64 data and opens print dialog
|
|
9
|
+
*
|
|
10
|
+
* **Performance Warning:**
|
|
11
|
+
* Large files can lead to app crashes due to memory constraints when decoding base64.
|
|
12
|
+
* For files larger than 5MB, it's recommended to use printFile() instead.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The base64 data and configuration for printing
|
|
15
|
+
* @returns Promise that resolves when print dialog is dismissed
|
|
16
|
+
* @throws Error if base64 data is invalid or printing fails
|
|
17
|
+
* @since 7.0.0
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Print a base64 encoded PDF
|
|
21
|
+
* await Printer.printBase64({
|
|
22
|
+
* name: 'Invoice #12345',
|
|
23
|
+
* data: 'JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...',
|
|
24
|
+
* mimeType: 'application/pdf',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Print a base64 encoded image
|
|
28
|
+
* await Printer.printBase64({
|
|
29
|
+
* name: 'Product Photo',
|
|
30
|
+
* data: '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDA...',
|
|
31
|
+
* mimeType: 'image/jpeg',
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
printBase64(options: PrintBase64Options): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Presents the printing UI to print device files.
|
|
38
|
+
*
|
|
39
|
+
* **Platform Behavior:**
|
|
40
|
+
* - **iOS**: Uses UIPrintInteractionController with file URL. Supports file:// paths or paths relative to app's documents directory.
|
|
41
|
+
* - **Android**: Uses PrintManager with file path. Supports both content:// URIs and file:// paths.
|
|
42
|
+
* - **Web**: Reads file and opens print dialog
|
|
43
|
+
*
|
|
44
|
+
* **Supported File Types:**
|
|
45
|
+
* - PDF documents (application/pdf)
|
|
46
|
+
* - Images: JPEG, PNG, GIF, HEIC, HEIF
|
|
47
|
+
*
|
|
48
|
+
* @param options - The file path and configuration for printing
|
|
49
|
+
* @returns Promise that resolves when print dialog is dismissed
|
|
50
|
+
* @throws Error if file path is invalid, file not found, or unsupported file type
|
|
51
|
+
* @since 7.0.0
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // iOS: Print from app documents directory
|
|
55
|
+
* await Printer.printFile({
|
|
56
|
+
* name: 'Contract',
|
|
57
|
+
* path: 'file:///var/mobile/Containers/Data/Application/.../Documents/contract.pdf',
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* // Android: Print from content URI
|
|
61
|
+
* await Printer.printFile({
|
|
62
|
+
* name: 'Receipt',
|
|
63
|
+
* path: 'content://com.android.providers.downloads.documents/document/123',
|
|
64
|
+
* mimeType: 'application/pdf',
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Android: Print from file path
|
|
68
|
+
* await Printer.printFile({
|
|
69
|
+
* name: 'Photo',
|
|
70
|
+
* path: 'file:///storage/emulated/0/Download/photo.jpg',
|
|
71
|
+
* mimeType: 'image/jpeg',
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
printFile(options: PrintFileOptions): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Presents the printing UI to print HTML documents.
|
|
78
|
+
*
|
|
79
|
+
* **Platform Behavior:**
|
|
80
|
+
* - **iOS**: Renders HTML in WKWebView, then prints using UIPrintInteractionController
|
|
81
|
+
* - **Android**: Renders HTML in WebView, then prints using PrintManager
|
|
82
|
+
* - **Web**: Creates iframe with HTML content and triggers print dialog
|
|
83
|
+
*
|
|
84
|
+
* **HTML Requirements:**
|
|
85
|
+
* - Should be a complete HTML document with proper structure
|
|
86
|
+
* - Can include inline CSS styles or style tags
|
|
87
|
+
* - External resources (images, stylesheets) should use absolute URLs
|
|
88
|
+
* - Print-specific CSS can be added using @media print rules
|
|
89
|
+
*
|
|
90
|
+
* **CSS Print Styling:**
|
|
91
|
+
* Use CSS media queries to customize print output:
|
|
92
|
+
* - Control page breaks: page-break-before, page-break-after, page-break-inside
|
|
93
|
+
* - Hide elements: display: none for no-print classes
|
|
94
|
+
* - Adjust font sizes and colors for print
|
|
95
|
+
*
|
|
96
|
+
* @param options - The HTML content and configuration for printing
|
|
97
|
+
* @returns Promise that resolves when print dialog is dismissed
|
|
98
|
+
* @throws Error if HTML is invalid or printing fails
|
|
99
|
+
* @since 7.0.0
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Simple HTML document
|
|
103
|
+
* await Printer.printHtml({
|
|
104
|
+
* name: 'Sales Report',
|
|
105
|
+
* html: '<html><body><h1>Q4 Sales Report</h1><p>Revenue: $125,000</p></body></html>',
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* // HTML with print-specific CSS
|
|
109
|
+
* await Printer.printHtml({
|
|
110
|
+
* name: 'Styled Invoice',
|
|
111
|
+
* html: `
|
|
112
|
+
* <html>
|
|
113
|
+
* <head>
|
|
114
|
+
* <style>
|
|
115
|
+
* @media print {
|
|
116
|
+
* body { font-size: 12pt; }
|
|
117
|
+
* .no-print { display: none; }
|
|
118
|
+
* h1 { page-break-before: always; }
|
|
119
|
+
* }
|
|
120
|
+
* </style>
|
|
121
|
+
* </head>
|
|
122
|
+
* <body>
|
|
123
|
+
* <h1>Invoice #12345</h1>
|
|
124
|
+
* <p>Amount due: $299.99</p>
|
|
125
|
+
* <button class="no-print">Don't print this button</button>
|
|
126
|
+
* </body>
|
|
127
|
+
* </html>
|
|
128
|
+
* `,
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
printHtml(options: PrintHtmlOptions): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Presents the printing UI to print PDF documents.
|
|
135
|
+
*
|
|
136
|
+
* **Platform Behavior:**
|
|
137
|
+
* - **iOS**: Uses UIPrintInteractionController with PDF file URL
|
|
138
|
+
* - **Android**: Uses PrintManager with PdfDocument
|
|
139
|
+
* - **Web**: Creates object URL and opens print dialog
|
|
140
|
+
*
|
|
141
|
+
* **File Path Requirements:**
|
|
142
|
+
* - **iOS**: Must be file:// path or relative to app's documents directory
|
|
143
|
+
* - **Android**: Supports content:// URIs (from downloads, media store) or file:// paths
|
|
144
|
+
* - **Web**: Must be accessible file path
|
|
145
|
+
*
|
|
146
|
+
* @param options - The PDF file path and configuration for printing
|
|
147
|
+
* @returns Promise that resolves when print dialog is dismissed
|
|
148
|
+
* @throws Error if PDF path is invalid, file not found, or not a valid PDF
|
|
149
|
+
* @since 7.0.0
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* // Print PDF from app storage
|
|
153
|
+
* await Printer.printPdf({
|
|
154
|
+
* name: 'Annual Report 2024',
|
|
155
|
+
* path: 'file:///var/mobile/Containers/Data/Application/.../Documents/report.pdf',
|
|
156
|
+
* });
|
|
157
|
+
*
|
|
158
|
+
* // Print PDF from Android downloads
|
|
159
|
+
* await Printer.printPdf({
|
|
160
|
+
* name: 'Downloaded Document',
|
|
161
|
+
* path: 'content://com.android.providers.downloads.documents/document/123',
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
printPdf(options: PrintPdfOptions): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Presents the printing UI to print web view content.
|
|
168
|
+
*
|
|
169
|
+
* Prints the current content displayed in your app's web view.
|
|
170
|
+
*
|
|
171
|
+
* **Platform Behavior:**
|
|
172
|
+
* - **iOS**: Uses UIPrintInteractionController with WKWebView's view printable
|
|
173
|
+
* - **Android**: Uses WebView.createPrintDocumentAdapter() with PrintManager
|
|
174
|
+
* - **Web**: Triggers window.print() for current page
|
|
175
|
+
*
|
|
176
|
+
* **Print Styling:**
|
|
177
|
+
* Supports CSS print media queries for customization. The web view's current
|
|
178
|
+
* styles will be applied, including any @media print rules.
|
|
179
|
+
*
|
|
180
|
+
* **Use Cases:**
|
|
181
|
+
* - Print the current app screen/page
|
|
182
|
+
* - Print web-based reports or dashboards
|
|
183
|
+
* - Print user-generated content displayed in web view
|
|
184
|
+
*
|
|
185
|
+
* @param options - Optional configuration for printing (name only)
|
|
186
|
+
* @returns Promise that resolves when print dialog is dismissed
|
|
187
|
+
* @throws Error if web view is not available or printing fails
|
|
188
|
+
* @since 7.0.0
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Print current web view with default name
|
|
192
|
+
* await Printer.printWebView();
|
|
193
|
+
*
|
|
194
|
+
* // Print with custom job name
|
|
195
|
+
* await Printer.printWebView({
|
|
196
|
+
* name: 'Dashboard Screenshot',
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* // Use with print-specific CSS in your HTML
|
|
200
|
+
* // Add this to your app's CSS:
|
|
201
|
+
* // @media print {
|
|
202
|
+
* // .no-print { display: none; }
|
|
203
|
+
* // body { font-size: 12pt; }
|
|
204
|
+
* // }
|
|
205
|
+
* await Printer.printWebView({
|
|
206
|
+
* name: 'User Profile',
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
printWebView(options?: PrintOptions): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Get the native Capacitor plugin version.
|
|
213
|
+
*
|
|
214
|
+
* Returns the hardcoded plugin version from native code (iOS/Android) or
|
|
215
|
+
* package version (Web). This is useful for debugging and ensuring plugin
|
|
216
|
+
* compatibility.
|
|
217
|
+
*
|
|
218
|
+
* @returns Promise that resolves with the plugin version string
|
|
219
|
+
* @throws Error if getting the version fails
|
|
220
|
+
* @since 7.0.0
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const { version } = await Printer.getPluginVersion();
|
|
224
|
+
* console.log('Printer plugin version:', version);
|
|
225
|
+
* // Output: "7.0.0"
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
getPluginVersion(): Promise<{
|
|
229
|
+
version: string;
|
|
230
|
+
}>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Options for printing base64 encoded data.
|
|
234
|
+
*
|
|
235
|
+
* @since 7.0.0
|
|
236
|
+
*/
|
|
237
|
+
export interface PrintBase64Options extends PrintOptions {
|
|
238
|
+
/**
|
|
239
|
+
* Valid base64 encoded string representing the file content.
|
|
240
|
+
*
|
|
241
|
+
* The base64 string should NOT include the data URL prefix (e.g., "data:application/pdf;base64,").
|
|
242
|
+
* Only provide the raw base64 encoded content.
|
|
243
|
+
*
|
|
244
|
+
* **Performance Considerations:**
|
|
245
|
+
* - Base64 encoding increases data size by approximately 33%
|
|
246
|
+
* - Large files (>5MB) may cause memory issues when decoding
|
|
247
|
+
* - Consider using printFile() for large documents
|
|
248
|
+
*
|
|
249
|
+
* **Platform Notes:**
|
|
250
|
+
* - **iOS**: Decoded to NSData and passed to UIPrintInteractionController
|
|
251
|
+
* - **Android**: Decoded to byte array and written to temporary file
|
|
252
|
+
* - **Web**: Converted to Blob for printing
|
|
253
|
+
*
|
|
254
|
+
* @since 7.0.0
|
|
255
|
+
* @example 'JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...'
|
|
256
|
+
*/
|
|
257
|
+
data: string;
|
|
258
|
+
/**
|
|
259
|
+
* MIME type of the base64 encoded data.
|
|
260
|
+
*
|
|
261
|
+
* **Supported types:**
|
|
262
|
+
* - `application/pdf` - PDF documents
|
|
263
|
+
* - `image/jpeg` - JPEG images
|
|
264
|
+
* - `image/png` - PNG images
|
|
265
|
+
* - `image/gif` - GIF images (iOS/Android only)
|
|
266
|
+
* - `image/heic` - HEIC images (iOS only)
|
|
267
|
+
* - `image/heif` - HEIF images (iOS only)
|
|
268
|
+
*
|
|
269
|
+
* **Platform Support:**
|
|
270
|
+
* - All platforms support PDF, JPEG, and PNG
|
|
271
|
+
* - GIF support varies by platform
|
|
272
|
+
* - HEIC/HEIF are iOS-specific formats
|
|
273
|
+
*
|
|
274
|
+
* @since 7.0.0
|
|
275
|
+
* @example 'application/pdf'
|
|
276
|
+
* @example 'image/jpeg'
|
|
277
|
+
*/
|
|
278
|
+
mimeType: string;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Options for printing files from device storage.
|
|
282
|
+
*
|
|
283
|
+
* @since 7.0.0
|
|
284
|
+
*/
|
|
285
|
+
export interface PrintFileOptions extends PrintOptions {
|
|
286
|
+
/**
|
|
287
|
+
* Path to the file to print.
|
|
288
|
+
*
|
|
289
|
+
* **iOS Path Formats:**
|
|
290
|
+
* - `file://` URL: Full file URL path
|
|
291
|
+
* - Relative path: Path relative to app's documents directory
|
|
292
|
+
* - Must be within app's accessible directories (documents, temporary, cache)
|
|
293
|
+
*
|
|
294
|
+
* **Android Path Formats:**
|
|
295
|
+
* - `content://` URI: Content provider URI (recommended for external files)
|
|
296
|
+
* - `file://` path: Direct file system path
|
|
297
|
+
* - Must have read permission for the file
|
|
298
|
+
*
|
|
299
|
+
* **Common Use Cases:**
|
|
300
|
+
* - App documents: Files saved in app's document directory
|
|
301
|
+
* - Downloads: Files from system downloads folder (use content:// on Android)
|
|
302
|
+
* - Temporary files: Files in app's temporary/cache directory
|
|
303
|
+
* - Shared storage: Files from external storage (Android, requires permissions)
|
|
304
|
+
*
|
|
305
|
+
* @since 7.0.0
|
|
306
|
+
* @platform ios Supports file:// paths and relative paths
|
|
307
|
+
* @platform android Supports content:// URIs and file:// paths
|
|
308
|
+
* @example 'content://com.android.providers.downloads.documents/document/123'
|
|
309
|
+
* @example 'file:///var/mobile/Containers/Data/Application/.../Documents/document.pdf'
|
|
310
|
+
* @example 'file:///storage/emulated/0/Download/receipt.pdf'
|
|
311
|
+
*/
|
|
312
|
+
path: string;
|
|
313
|
+
/**
|
|
314
|
+
* MIME type of the file.
|
|
315
|
+
*
|
|
316
|
+
* **Platform Behavior:**
|
|
317
|
+
* - **Android**: REQUIRED for content:// URIs. Helps the system determine how to handle the file.
|
|
318
|
+
* Optional for file:// paths (auto-detected from extension).
|
|
319
|
+
* - **iOS**: Ignored. File type is auto-detected from file extension.
|
|
320
|
+
* - **Web**: Optional. Auto-detected if not provided.
|
|
321
|
+
*
|
|
322
|
+
* **Common MIME Types:**
|
|
323
|
+
* - `application/pdf` - PDF documents
|
|
324
|
+
* - `image/jpeg` - JPEG images
|
|
325
|
+
* - `image/png` - PNG images
|
|
326
|
+
* - `image/gif` - GIF images
|
|
327
|
+
*
|
|
328
|
+
* @since 7.0.0
|
|
329
|
+
* @default Undefined (auto-detected from file extension)
|
|
330
|
+
* @platform android Used for content:// URIs and file type detection
|
|
331
|
+
* @platform ios Ignored (auto-detected)
|
|
332
|
+
* @example 'application/pdf'
|
|
333
|
+
* @example 'image/jpeg'
|
|
334
|
+
*/
|
|
335
|
+
mimeType?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Options for printing HTML content.
|
|
339
|
+
*
|
|
340
|
+
* @since 7.0.0
|
|
341
|
+
*/
|
|
342
|
+
export interface PrintHtmlOptions extends PrintOptions {
|
|
343
|
+
/**
|
|
344
|
+
* HTML content to print.
|
|
345
|
+
*
|
|
346
|
+
* **Content Requirements:**
|
|
347
|
+
* - Should be a complete HTML document with `<html>`, `<head>`, and `<body>` tags
|
|
348
|
+
* - Can include inline CSS styles or `<style>` tags
|
|
349
|
+
* - External resources (images, fonts) should use absolute URLs
|
|
350
|
+
* - JavaScript is not executed during print rendering
|
|
351
|
+
*
|
|
352
|
+
* **Print Optimization Tips:**
|
|
353
|
+
* - Use `@media print` CSS rules for print-specific styling
|
|
354
|
+
* - Control page breaks with `page-break-before`, `page-break-after`, `page-break-inside`
|
|
355
|
+
* - Hide UI elements using `.no-print { display: none; }` class
|
|
356
|
+
* - Adjust font sizes for readability (12pt is standard for print)
|
|
357
|
+
* - Use print-friendly colors (avoid dark backgrounds)
|
|
358
|
+
*
|
|
359
|
+
* **Platform Rendering:**
|
|
360
|
+
* - **iOS**: Rendered in WKWebView before printing
|
|
361
|
+
* - **Android**: Rendered in WebView before printing
|
|
362
|
+
* - **Web**: Rendered in hidden iframe before printing
|
|
363
|
+
*
|
|
364
|
+
* **Character Encoding:**
|
|
365
|
+
* - UTF-8 is recommended and default
|
|
366
|
+
* - Include charset in HTML: `<meta charset="UTF-8">`
|
|
367
|
+
*
|
|
368
|
+
* @since 7.0.0
|
|
369
|
+
* @example '<html><body><h1>Hello World</h1><p>This is a test document.</p></body></html>'
|
|
370
|
+
* @example
|
|
371
|
+
* ```typescript
|
|
372
|
+
* const htmlWithStyles = `
|
|
373
|
+
* <html>
|
|
374
|
+
* <head>
|
|
375
|
+
* <meta charset="UTF-8">
|
|
376
|
+
* <style>
|
|
377
|
+
* @media print {
|
|
378
|
+
* body { font-family: Arial, sans-serif; font-size: 12pt; }
|
|
379
|
+
* .no-print { display: none; }
|
|
380
|
+
* h1 { color: #333; page-break-before: always; }
|
|
381
|
+
* }
|
|
382
|
+
* </style>
|
|
383
|
+
* </head>
|
|
384
|
+
* <body>
|
|
385
|
+
* <h1>Invoice #12345</h1>
|
|
386
|
+
* <p>Amount: $299.99</p>
|
|
387
|
+
* </body>
|
|
388
|
+
* </html>
|
|
389
|
+
* `;
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
html: string;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Options for printing PDF documents.
|
|
396
|
+
*
|
|
397
|
+
* @since 7.0.0
|
|
398
|
+
*/
|
|
399
|
+
export interface PrintPdfOptions extends PrintOptions {
|
|
400
|
+
/**
|
|
401
|
+
* Path to the PDF document.
|
|
402
|
+
*
|
|
403
|
+
* **iOS Path Formats:**
|
|
404
|
+
* - `file://` URL: Full file URL path to PDF document
|
|
405
|
+
* - Relative path: Path relative to app's documents directory
|
|
406
|
+
* - Must be within app's accessible directories (documents, temporary, cache)
|
|
407
|
+
* - PDF must be valid and not password-protected
|
|
408
|
+
*
|
|
409
|
+
* **Android Path Formats:**
|
|
410
|
+
* - `content://` URI: Content provider URI (recommended for external PDFs)
|
|
411
|
+
* - `file://` path: Direct file system path to PDF
|
|
412
|
+
* - Must have read permission for the file
|
|
413
|
+
* - Supports both single-page and multi-page PDFs
|
|
414
|
+
*
|
|
415
|
+
* **Web Path Formats:**
|
|
416
|
+
* - Relative or absolute path accessible from web context
|
|
417
|
+
* - Must be a valid PDF file
|
|
418
|
+
*
|
|
419
|
+
* **Validation:**
|
|
420
|
+
* - File must exist at the specified path
|
|
421
|
+
* - File must be a valid PDF (checked by magic number/header)
|
|
422
|
+
* - File must be readable by the app
|
|
423
|
+
*
|
|
424
|
+
* **Common Sources:**
|
|
425
|
+
* - App documents: PDFs saved in app's document directory
|
|
426
|
+
* - Downloads: PDFs from system downloads (use content:// on Android)
|
|
427
|
+
* - Generated PDFs: Temporary PDFs created by the app
|
|
428
|
+
* - Network downloads: PDFs downloaded and saved locally
|
|
429
|
+
*
|
|
430
|
+
* @since 7.0.0
|
|
431
|
+
* @platform ios Supports file:// paths and relative paths
|
|
432
|
+
* @platform android Supports content:// URIs and file:// paths
|
|
433
|
+
* @platform web Supports accessible file paths
|
|
434
|
+
* @example 'content://com.android.providers.downloads.documents/document/123'
|
|
435
|
+
* @example 'file:///var/mobile/Containers/Data/Application/.../Documents/document.pdf'
|
|
436
|
+
* @example 'file:///storage/emulated/0/Download/report.pdf'
|
|
437
|
+
* @example 'Documents/invoice-2024.pdf'
|
|
438
|
+
*/
|
|
439
|
+
path: string;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Base options for all print operations.
|
|
443
|
+
*
|
|
444
|
+
* @since 7.0.0
|
|
445
|
+
*/
|
|
446
|
+
export interface PrintOptions {
|
|
447
|
+
/**
|
|
448
|
+
* Name of the print job.
|
|
449
|
+
*
|
|
450
|
+
* **Usage:**
|
|
451
|
+
* - Displayed in the system print queue
|
|
452
|
+
* - Shown in print history/logs
|
|
453
|
+
* - May appear in printer status displays
|
|
454
|
+
* - Used as default filename for "Save as PDF" option
|
|
455
|
+
*
|
|
456
|
+
* **Platform Behavior:**
|
|
457
|
+
* - **iOS**: Shown in print preview header and activity view
|
|
458
|
+
* - **Android**: Displayed in print job notification and print queue
|
|
459
|
+
* - **Web**: Used as document title in print dialog
|
|
460
|
+
*
|
|
461
|
+
* **Best Practices:**
|
|
462
|
+
* - Use descriptive names (e.g., "Invoice #12345", "Q4 Report")
|
|
463
|
+
* - Keep under 50 characters for better display
|
|
464
|
+
* - Avoid special characters that may cause issues in filenames
|
|
465
|
+
* - Include relevant identifiers (order numbers, dates, etc.)
|
|
466
|
+
*
|
|
467
|
+
* **Examples:**
|
|
468
|
+
* - "Invoice #12345"
|
|
469
|
+
* - "Sales Report - 2024 Q4"
|
|
470
|
+
* - "Customer Receipt - John Doe"
|
|
471
|
+
* - "Product Photo - SKU-ABC123"
|
|
472
|
+
*
|
|
473
|
+
* @since 7.0.0
|
|
474
|
+
* @default 'Document'
|
|
475
|
+
* @platform ios Shown in print preview and activity view
|
|
476
|
+
* @platform android Shown in print queue and notifications
|
|
477
|
+
* @platform web Used as document title in print dialog
|
|
478
|
+
* @example 'Invoice #12345'
|
|
479
|
+
* @example 'Annual Report 2024'
|
|
480
|
+
* @example 'Receipt - Order #789'
|
|
481
|
+
*/
|
|
482
|
+
name?: string;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Type alias for print web view options.
|
|
486
|
+
*
|
|
487
|
+
* @since 7.0.0
|
|
488
|
+
*/
|
|
489
|
+
export type PrintWebViewOptions = PrintOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface PrinterPlugin {\n /**\n * Presents the printing UI to print files encoded as base64 strings.\n *\n * **Platform Behavior:**\n * - **iOS**: Uses UIPrintInteractionController with base64 decoded data\n * - **Android**: Uses PrintManager with base64 decoded data\n * - **Web**: Creates a blob from base64 data and opens print dialog\n *\n * **Performance Warning:**\n * Large files can lead to app crashes due to memory constraints when decoding base64.\n * For files larger than 5MB, it's recommended to use printFile() instead.\n *\n * @param options - The base64 data and configuration for printing\n * @returns Promise that resolves when print dialog is dismissed\n * @throws Error if base64 data is invalid or printing fails\n * @since 7.0.0\n * @example\n * ```typescript\n * // Print a base64 encoded PDF\n * await Printer.printBase64({\n * name: 'Invoice #12345',\n * data: 'JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...',\n * mimeType: 'application/pdf',\n * });\n *\n * // Print a base64 encoded image\n * await Printer.printBase64({\n * name: 'Product Photo',\n * data: '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDA...',\n * mimeType: 'image/jpeg',\n * });\n * ```\n */\n printBase64(options: PrintBase64Options): Promise<void>;\n\n /**\n * Presents the printing UI to print device files.\n *\n * **Platform Behavior:**\n * - **iOS**: Uses UIPrintInteractionController with file URL. Supports file:// paths or paths relative to app's documents directory.\n * - **Android**: Uses PrintManager with file path. Supports both content:// URIs and file:// paths.\n * - **Web**: Reads file and opens print dialog\n *\n * **Supported File Types:**\n * - PDF documents (application/pdf)\n * - Images: JPEG, PNG, GIF, HEIC, HEIF\n *\n * @param options - The file path and configuration for printing\n * @returns Promise that resolves when print dialog is dismissed\n * @throws Error if file path is invalid, file not found, or unsupported file type\n * @since 7.0.0\n * @example\n * ```typescript\n * // iOS: Print from app documents directory\n * await Printer.printFile({\n * name: 'Contract',\n * path: 'file:///var/mobile/Containers/Data/Application/.../Documents/contract.pdf',\n * });\n *\n * // Android: Print from content URI\n * await Printer.printFile({\n * name: 'Receipt',\n * path: 'content://com.android.providers.downloads.documents/document/123',\n * mimeType: 'application/pdf',\n * });\n *\n * // Android: Print from file path\n * await Printer.printFile({\n * name: 'Photo',\n * path: 'file:///storage/emulated/0/Download/photo.jpg',\n * mimeType: 'image/jpeg',\n * });\n * ```\n */\n printFile(options: PrintFileOptions): Promise<void>;\n\n /**\n * Presents the printing UI to print HTML documents.\n *\n * **Platform Behavior:**\n * - **iOS**: Renders HTML in WKWebView, then prints using UIPrintInteractionController\n * - **Android**: Renders HTML in WebView, then prints using PrintManager\n * - **Web**: Creates iframe with HTML content and triggers print dialog\n *\n * **HTML Requirements:**\n * - Should be a complete HTML document with proper structure\n * - Can include inline CSS styles or style tags\n * - External resources (images, stylesheets) should use absolute URLs\n * - Print-specific CSS can be added using @media print rules\n *\n * **CSS Print Styling:**\n * Use CSS media queries to customize print output:\n * - Control page breaks: page-break-before, page-break-after, page-break-inside\n * - Hide elements: display: none for no-print classes\n * - Adjust font sizes and colors for print\n *\n * @param options - The HTML content and configuration for printing\n * @returns Promise that resolves when print dialog is dismissed\n * @throws Error if HTML is invalid or printing fails\n * @since 7.0.0\n * @example\n * ```typescript\n * // Simple HTML document\n * await Printer.printHtml({\n * name: 'Sales Report',\n * html: '<html><body><h1>Q4 Sales Report</h1><p>Revenue: $125,000</p></body></html>',\n * });\n *\n * // HTML with print-specific CSS\n * await Printer.printHtml({\n * name: 'Styled Invoice',\n * html: `\n * <html>\n * <head>\n * <style>\n * @media print {\n * body { font-size: 12pt; }\n * .no-print { display: none; }\n * h1 { page-break-before: always; }\n * }\n * </style>\n * </head>\n * <body>\n * <h1>Invoice #12345</h1>\n * <p>Amount due: $299.99</p>\n * <button class=\"no-print\">Don't print this button</button>\n * </body>\n * </html>\n * `,\n * });\n * ```\n */\n printHtml(options: PrintHtmlOptions): Promise<void>;\n\n /**\n * Presents the printing UI to print PDF documents.\n *\n * **Platform Behavior:**\n * - **iOS**: Uses UIPrintInteractionController with PDF file URL\n * - **Android**: Uses PrintManager with PdfDocument\n * - **Web**: Creates object URL and opens print dialog\n *\n * **File Path Requirements:**\n * - **iOS**: Must be file:// path or relative to app's documents directory\n * - **Android**: Supports content:// URIs (from downloads, media store) or file:// paths\n * - **Web**: Must be accessible file path\n *\n * @param options - The PDF file path and configuration for printing\n * @returns Promise that resolves when print dialog is dismissed\n * @throws Error if PDF path is invalid, file not found, or not a valid PDF\n * @since 7.0.0\n * @example\n * ```typescript\n * // Print PDF from app storage\n * await Printer.printPdf({\n * name: 'Annual Report 2024',\n * path: 'file:///var/mobile/Containers/Data/Application/.../Documents/report.pdf',\n * });\n *\n * // Print PDF from Android downloads\n * await Printer.printPdf({\n * name: 'Downloaded Document',\n * path: 'content://com.android.providers.downloads.documents/document/123',\n * });\n * ```\n */\n printPdf(options: PrintPdfOptions): Promise<void>;\n\n /**\n * Presents the printing UI to print web view content.\n *\n * Prints the current content displayed in your app's web view.\n *\n * **Platform Behavior:**\n * - **iOS**: Uses UIPrintInteractionController with WKWebView's view printable\n * - **Android**: Uses WebView.createPrintDocumentAdapter() with PrintManager\n * - **Web**: Triggers window.print() for current page\n *\n * **Print Styling:**\n * Supports CSS print media queries for customization. The web view's current\n * styles will be applied, including any @media print rules.\n *\n * **Use Cases:**\n * - Print the current app screen/page\n * - Print web-based reports or dashboards\n * - Print user-generated content displayed in web view\n *\n * @param options - Optional configuration for printing (name only)\n * @returns Promise that resolves when print dialog is dismissed\n * @throws Error if web view is not available or printing fails\n * @since 7.0.0\n * @example\n * ```typescript\n * // Print current web view with default name\n * await Printer.printWebView();\n *\n * // Print with custom job name\n * await Printer.printWebView({\n * name: 'Dashboard Screenshot',\n * });\n *\n * // Use with print-specific CSS in your HTML\n * // Add this to your app's CSS:\n * // @media print {\n * // .no-print { display: none; }\n * // body { font-size: 12pt; }\n * // }\n * await Printer.printWebView({\n * name: 'User Profile',\n * });\n * ```\n */\n printWebView(options?: PrintOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version.\n *\n * Returns the hardcoded plugin version from native code (iOS/Android) or\n * package version (Web). This is useful for debugging and ensuring plugin\n * compatibility.\n *\n * @returns Promise that resolves with the plugin version string\n * @throws Error if getting the version fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { version } = await Printer.getPluginVersion();\n * console.log('Printer plugin version:', version);\n * // Output: \"7.0.0\"\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\n/**\n * Options for printing base64 encoded data.\n *\n * @since 7.0.0\n */\nexport interface PrintBase64Options extends PrintOptions {\n /**\n * Valid base64 encoded string representing the file content.\n *\n * The base64 string should NOT include the data URL prefix (e.g., \"data:application/pdf;base64,\").\n * Only provide the raw base64 encoded content.\n *\n * **Performance Considerations:**\n * - Base64 encoding increases data size by approximately 33%\n * - Large files (>5MB) may cause memory issues when decoding\n * - Consider using printFile() for large documents\n *\n * **Platform Notes:**\n * - **iOS**: Decoded to NSData and passed to UIPrintInteractionController\n * - **Android**: Decoded to byte array and written to temporary file\n * - **Web**: Converted to Blob for printing\n *\n * @since 7.0.0\n * @example 'JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...'\n */\n data: string;\n\n /**\n * MIME type of the base64 encoded data.\n *\n * **Supported types:**\n * - `application/pdf` - PDF documents\n * - `image/jpeg` - JPEG images\n * - `image/png` - PNG images\n * - `image/gif` - GIF images (iOS/Android only)\n * - `image/heic` - HEIC images (iOS only)\n * - `image/heif` - HEIF images (iOS only)\n *\n * **Platform Support:**\n * - All platforms support PDF, JPEG, and PNG\n * - GIF support varies by platform\n * - HEIC/HEIF are iOS-specific formats\n *\n * @since 7.0.0\n * @example 'application/pdf'\n * @example 'image/jpeg'\n */\n mimeType: string;\n}\n\n/**\n * Options for printing files from device storage.\n *\n * @since 7.0.0\n */\nexport interface PrintFileOptions extends PrintOptions {\n /**\n * Path to the file to print.\n *\n * **iOS Path Formats:**\n * - `file://` URL: Full file URL path\n * - Relative path: Path relative to app's documents directory\n * - Must be within app's accessible directories (documents, temporary, cache)\n *\n * **Android Path Formats:**\n * - `content://` URI: Content provider URI (recommended for external files)\n * - `file://` path: Direct file system path\n * - Must have read permission for the file\n *\n * **Common Use Cases:**\n * - App documents: Files saved in app's document directory\n * - Downloads: Files from system downloads folder (use content:// on Android)\n * - Temporary files: Files in app's temporary/cache directory\n * - Shared storage: Files from external storage (Android, requires permissions)\n *\n * @since 7.0.0\n * @platform ios Supports file:// paths and relative paths\n * @platform android Supports content:// URIs and file:// paths\n * @example 'content://com.android.providers.downloads.documents/document/123'\n * @example 'file:///var/mobile/Containers/Data/Application/.../Documents/document.pdf'\n * @example 'file:///storage/emulated/0/Download/receipt.pdf'\n */\n path: string;\n\n /**\n * MIME type of the file.\n *\n * **Platform Behavior:**\n * - **Android**: REQUIRED for content:// URIs. Helps the system determine how to handle the file.\n * Optional for file:// paths (auto-detected from extension).\n * - **iOS**: Ignored. File type is auto-detected from file extension.\n * - **Web**: Optional. Auto-detected if not provided.\n *\n * **Common MIME Types:**\n * - `application/pdf` - PDF documents\n * - `image/jpeg` - JPEG images\n * - `image/png` - PNG images\n * - `image/gif` - GIF images\n *\n * @since 7.0.0\n * @default Undefined (auto-detected from file extension)\n * @platform android Used for content:// URIs and file type detection\n * @platform ios Ignored (auto-detected)\n * @example 'application/pdf'\n * @example 'image/jpeg'\n */\n mimeType?: string;\n}\n\n/**\n * Options for printing HTML content.\n *\n * @since 7.0.0\n */\nexport interface PrintHtmlOptions extends PrintOptions {\n /**\n * HTML content to print.\n *\n * **Content Requirements:**\n * - Should be a complete HTML document with `<html>`, `<head>`, and `<body>` tags\n * - Can include inline CSS styles or `<style>` tags\n * - External resources (images, fonts) should use absolute URLs\n * - JavaScript is not executed during print rendering\n *\n * **Print Optimization Tips:**\n * - Use `@media print` CSS rules for print-specific styling\n * - Control page breaks with `page-break-before`, `page-break-after`, `page-break-inside`\n * - Hide UI elements using `.no-print { display: none; }` class\n * - Adjust font sizes for readability (12pt is standard for print)\n * - Use print-friendly colors (avoid dark backgrounds)\n *\n * **Platform Rendering:**\n * - **iOS**: Rendered in WKWebView before printing\n * - **Android**: Rendered in WebView before printing\n * - **Web**: Rendered in hidden iframe before printing\n *\n * **Character Encoding:**\n * - UTF-8 is recommended and default\n * - Include charset in HTML: `<meta charset=\"UTF-8\">`\n *\n * @since 7.0.0\n * @example '<html><body><h1>Hello World</h1><p>This is a test document.</p></body></html>'\n * @example\n * ```typescript\n * const htmlWithStyles = `\n * <html>\n * <head>\n * <meta charset=\"UTF-8\">\n * <style>\n * @media print {\n * body { font-family: Arial, sans-serif; font-size: 12pt; }\n * .no-print { display: none; }\n * h1 { color: #333; page-break-before: always; }\n * }\n * </style>\n * </head>\n * <body>\n * <h1>Invoice #12345</h1>\n * <p>Amount: $299.99</p>\n * </body>\n * </html>\n * `;\n * ```\n */\n html: string;\n}\n\n/**\n * Options for printing PDF documents.\n *\n * @since 7.0.0\n */\nexport interface PrintPdfOptions extends PrintOptions {\n /**\n * Path to the PDF document.\n *\n * **iOS Path Formats:**\n * - `file://` URL: Full file URL path to PDF document\n * - Relative path: Path relative to app's documents directory\n * - Must be within app's accessible directories (documents, temporary, cache)\n * - PDF must be valid and not password-protected\n *\n * **Android Path Formats:**\n * - `content://` URI: Content provider URI (recommended for external PDFs)\n * - `file://` path: Direct file system path to PDF\n * - Must have read permission for the file\n * - Supports both single-page and multi-page PDFs\n *\n * **Web Path Formats:**\n * - Relative or absolute path accessible from web context\n * - Must be a valid PDF file\n *\n * **Validation:**\n * - File must exist at the specified path\n * - File must be a valid PDF (checked by magic number/header)\n * - File must be readable by the app\n *\n * **Common Sources:**\n * - App documents: PDFs saved in app's document directory\n * - Downloads: PDFs from system downloads (use content:// on Android)\n * - Generated PDFs: Temporary PDFs created by the app\n * - Network downloads: PDFs downloaded and saved locally\n *\n * @since 7.0.0\n * @platform ios Supports file:// paths and relative paths\n * @platform android Supports content:// URIs and file:// paths\n * @platform web Supports accessible file paths\n * @example 'content://com.android.providers.downloads.documents/document/123'\n * @example 'file:///var/mobile/Containers/Data/Application/.../Documents/document.pdf'\n * @example 'file:///storage/emulated/0/Download/report.pdf'\n * @example 'Documents/invoice-2024.pdf'\n */\n path: string;\n}\n\n/**\n * Base options for all print operations.\n *\n * @since 7.0.0\n */\nexport interface PrintOptions {\n /**\n * Name of the print job.\n *\n * **Usage:**\n * - Displayed in the system print queue\n * - Shown in print history/logs\n * - May appear in printer status displays\n * - Used as default filename for \"Save as PDF\" option\n *\n * **Platform Behavior:**\n * - **iOS**: Shown in print preview header and activity view\n * - **Android**: Displayed in print job notification and print queue\n * - **Web**: Used as document title in print dialog\n *\n * **Best Practices:**\n * - Use descriptive names (e.g., \"Invoice #12345\", \"Q4 Report\")\n * - Keep under 50 characters for better display\n * - Avoid special characters that may cause issues in filenames\n * - Include relevant identifiers (order numbers, dates, etc.)\n *\n * **Examples:**\n * - \"Invoice #12345\"\n * - \"Sales Report - 2024 Q4\"\n * - \"Customer Receipt - John Doe\"\n * - \"Product Photo - SKU-ABC123\"\n *\n * @since 7.0.0\n * @default 'Document'\n * @platform ios Shown in print preview and activity view\n * @platform android Shown in print queue and notifications\n * @platform web Used as document title in print dialog\n * @example 'Invoice #12345'\n * @example 'Annual Report 2024'\n * @example 'Receipt - Order #789'\n */\n name?: string;\n}\n\n/**\n * Type alias for print web view options.\n *\n * @since 7.0.0\n */\nexport type PrintWebViewOptions = PrintOptions;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,OAAO,GAAG,cAAc,CAAgB,SAAS,EAAE;IACvD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;CAC3D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { PrinterPlugin } from './definitions';\n\nconst Printer = registerPlugin<PrinterPlugin>('Printer', {\n web: () => import('./web').then((m) => new m.PrinterWeb()),\n});\n\nexport * from './definitions';\nexport { Printer };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PrintBase64Options, PrintFileOptions, PrintHtmlOptions, PrintOptions, PrintPdfOptions, PrinterPlugin } from './definitions';
|
|
3
|
+
export declare class PrinterWeb extends WebPlugin implements PrinterPlugin {
|
|
4
|
+
printBase64(options: PrintBase64Options): Promise<void>;
|
|
5
|
+
printFile(options: PrintFileOptions): Promise<void>;
|
|
6
|
+
printHtml(options: PrintHtmlOptions): Promise<void>;
|
|
7
|
+
printPdf(options: PrintPdfOptions): Promise<void>;
|
|
8
|
+
printWebView(options?: PrintOptions): Promise<void>;
|
|
9
|
+
getPluginVersion(): Promise<{
|
|
10
|
+
version: string;
|
|
11
|
+
}>;
|
|
12
|
+
private printFromUrl;
|
|
13
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class PrinterWeb extends WebPlugin {
|
|
3
|
+
async printBase64(options) {
|
|
4
|
+
const { data, mimeType, name } = options;
|
|
5
|
+
// Convert base64 to blob
|
|
6
|
+
const byteCharacters = atob(data);
|
|
7
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
8
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
9
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
10
|
+
}
|
|
11
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
12
|
+
const blob = new Blob([byteArray], { type: mimeType });
|
|
13
|
+
// Create object URL and print
|
|
14
|
+
const url = URL.createObjectURL(blob);
|
|
15
|
+
await this.printFromUrl(url, name);
|
|
16
|
+
URL.revokeObjectURL(url);
|
|
17
|
+
}
|
|
18
|
+
async printFile(options) {
|
|
19
|
+
const { path, name } = options;
|
|
20
|
+
// On web, we can only print URLs that are accessible
|
|
21
|
+
// This will work for file:// URLs in some browsers or HTTP(S) URLs
|
|
22
|
+
await this.printFromUrl(path, name);
|
|
23
|
+
}
|
|
24
|
+
async printHtml(options) {
|
|
25
|
+
const { html, name } = options;
|
|
26
|
+
// Create a blob URL from the HTML content
|
|
27
|
+
const blob = new Blob([html], { type: 'text/html' });
|
|
28
|
+
const url = URL.createObjectURL(blob);
|
|
29
|
+
await this.printFromUrl(url, name);
|
|
30
|
+
URL.revokeObjectURL(url);
|
|
31
|
+
}
|
|
32
|
+
async printPdf(options) {
|
|
33
|
+
const { path, name } = options;
|
|
34
|
+
// On web, print the PDF URL
|
|
35
|
+
await this.printFromUrl(path, name);
|
|
36
|
+
}
|
|
37
|
+
async printWebView(options) {
|
|
38
|
+
// Set document title for print job name
|
|
39
|
+
const originalTitle = document.title;
|
|
40
|
+
if (options === null || options === void 0 ? void 0 : options.name) {
|
|
41
|
+
document.title = options.name;
|
|
42
|
+
}
|
|
43
|
+
// Trigger browser print dialog
|
|
44
|
+
window.print();
|
|
45
|
+
// Restore original title
|
|
46
|
+
document.title = originalTitle;
|
|
47
|
+
}
|
|
48
|
+
async getPluginVersion() {
|
|
49
|
+
return { version: '7.0.0' };
|
|
50
|
+
}
|
|
51
|
+
async printFromUrl(url, name) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
// Create hidden iframe
|
|
54
|
+
const iframe = document.createElement('iframe');
|
|
55
|
+
iframe.style.position = 'fixed';
|
|
56
|
+
iframe.style.right = '0';
|
|
57
|
+
iframe.style.bottom = '0';
|
|
58
|
+
iframe.style.width = '0';
|
|
59
|
+
iframe.style.height = '0';
|
|
60
|
+
iframe.style.border = 'none';
|
|
61
|
+
// Set up load handler
|
|
62
|
+
iframe.onload = () => {
|
|
63
|
+
try {
|
|
64
|
+
// Set document title if name provided
|
|
65
|
+
if (name && iframe.contentDocument) {
|
|
66
|
+
iframe.contentDocument.title = name;
|
|
67
|
+
}
|
|
68
|
+
// Small delay to ensure content is loaded
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
try {
|
|
71
|
+
// Try to access the iframe's window
|
|
72
|
+
const iframeWindow = iframe.contentWindow;
|
|
73
|
+
if (!iframeWindow) {
|
|
74
|
+
throw new Error('Cannot access iframe window');
|
|
75
|
+
}
|
|
76
|
+
// Print the iframe content
|
|
77
|
+
iframeWindow.focus();
|
|
78
|
+
iframeWindow.print();
|
|
79
|
+
// Clean up after a delay
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
document.body.removeChild(iframe);
|
|
82
|
+
resolve();
|
|
83
|
+
}, 100);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
document.body.removeChild(iframe);
|
|
87
|
+
reject(error);
|
|
88
|
+
}
|
|
89
|
+
}, 100);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
document.body.removeChild(iframe);
|
|
93
|
+
reject(error);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
iframe.onerror = () => {
|
|
97
|
+
document.body.removeChild(iframe);
|
|
98
|
+
reject(new Error('Failed to load content for printing'));
|
|
99
|
+
};
|
|
100
|
+
// Add iframe to document and set source
|
|
101
|
+
document.body.appendChild(iframe);
|
|
102
|
+
iframe.src = url;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=web.js.map
|