@dimer47/capacitor-plugin-printer 2.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/CapacitorPluginPrinter.podspec +17 -0
- package/LICENSE +202 -0
- package/Package.swift +31 -0
- package/README.md +505 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintAdapter.kt +73 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintContent.kt +78 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintIO.kt +136 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintManager.kt +219 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintOptions.kt +260 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrintProxy.kt +44 -0
- package/android/src/main/kotlin/com/nichedev/capacitor/printer/PrinterPlugin.kt +267 -0
- package/dist/esm/definitions.d.ts +307 -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 +47 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +61 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +64 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PrinterPlugin/PrinterControllerHelper.swift +33 -0
- package/ios/Sources/PrinterPlugin/PrinterFont.swift +99 -0
- package/ios/Sources/PrinterPlugin/PrinterInfo.swift +64 -0
- package/ios/Sources/PrinterPlugin/PrinterItem.swift +104 -0
- package/ios/Sources/PrinterPlugin/PrinterLayout.swift +61 -0
- package/ios/Sources/PrinterPlugin/PrinterPaper.swift +71 -0
- package/ios/Sources/PrinterPlugin/PrinterPlugin.swift +327 -0
- package/ios/Sources/PrinterPlugin/PrinterRenderer.swift +135 -0
- package/ios/Sources/PrinterPlugin/PrinterUnit.swift +45 -0
- package/package.json +75 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.nichedev.capacitor.printer
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import android.os.CancellationSignal
|
|
5
|
+
import android.os.ParcelFileDescriptor
|
|
6
|
+
import android.print.PageRange
|
|
7
|
+
import android.print.PrintAttributes
|
|
8
|
+
import android.print.PrintDocumentAdapter
|
|
9
|
+
|
|
10
|
+
class PrintProxy(
|
|
11
|
+
private val delegate: PrintDocumentAdapter,
|
|
12
|
+
private val callback: () -> Unit
|
|
13
|
+
) : PrintDocumentAdapter() {
|
|
14
|
+
|
|
15
|
+
override fun onLayout(
|
|
16
|
+
oldAttributes: PrintAttributes?,
|
|
17
|
+
newAttributes: PrintAttributes,
|
|
18
|
+
cancellationSignal: CancellationSignal?,
|
|
19
|
+
callback: LayoutResultCallback,
|
|
20
|
+
extras: Bundle?
|
|
21
|
+
) {
|
|
22
|
+
delegate.onLayout(oldAttributes, newAttributes, cancellationSignal, callback, extras)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun onWrite(
|
|
26
|
+
pages: Array<out PageRange>,
|
|
27
|
+
destination: ParcelFileDescriptor,
|
|
28
|
+
cancellationSignal: CancellationSignal?,
|
|
29
|
+
callback: WriteResultCallback
|
|
30
|
+
) {
|
|
31
|
+
delegate.onWrite(pages, destination, cancellationSignal, callback)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun onStart() {
|
|
35
|
+
delegate.onStart()
|
|
36
|
+
super.onStart()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun onFinish() {
|
|
40
|
+
delegate.onFinish()
|
|
41
|
+
super.onFinish()
|
|
42
|
+
callback()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
package com.nichedev.capacitor.printer
|
|
2
|
+
|
|
3
|
+
import android.webkit.WebView
|
|
4
|
+
import com.getcapacitor.JSArray
|
|
5
|
+
import com.getcapacitor.JSObject
|
|
6
|
+
import com.getcapacitor.Plugin
|
|
7
|
+
import com.getcapacitor.PluginCall
|
|
8
|
+
import com.getcapacitor.PluginMethod
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
10
|
+
|
|
11
|
+
@CapacitorPlugin(name = "Printer")
|
|
12
|
+
class PrinterPlugin : Plugin() {
|
|
13
|
+
|
|
14
|
+
@PluginMethod
|
|
15
|
+
fun canPrintItem(call: PluginCall) {
|
|
16
|
+
val uri = call.getString("uri")
|
|
17
|
+
|
|
18
|
+
activity.let { ctx ->
|
|
19
|
+
val pm = PrintManager(ctx)
|
|
20
|
+
val available = pm.canPrintItem(uri)
|
|
21
|
+
|
|
22
|
+
val ret = JSObject()
|
|
23
|
+
ret.put("available", available)
|
|
24
|
+
call.resolve(ret)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@PluginMethod
|
|
29
|
+
fun getPrintableTypes(call: PluginCall) {
|
|
30
|
+
val types = PrintManager.getPrintableTypes()
|
|
31
|
+
val ret = JSObject()
|
|
32
|
+
val jsArray = JSArray()
|
|
33
|
+
for (i in 0 until types.length()) {
|
|
34
|
+
jsArray.put(types.getString(i))
|
|
35
|
+
}
|
|
36
|
+
ret.put("types", jsArray)
|
|
37
|
+
call.resolve(ret)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@PluginMethod
|
|
41
|
+
fun pick(call: PluginCall) {
|
|
42
|
+
call.reject("Printer picker is not supported on Android")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@PluginMethod
|
|
46
|
+
fun print(call: PluginCall) {
|
|
47
|
+
try {
|
|
48
|
+
val content = call.getString("content")
|
|
49
|
+
val settings = extractSettings(call)
|
|
50
|
+
|
|
51
|
+
val currentActivity = activity
|
|
52
|
+
if (currentActivity == null) {
|
|
53
|
+
call.reject("Activity not available")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
bridge.executeOnMainThread {
|
|
58
|
+
try {
|
|
59
|
+
val pm = PrintManager(currentActivity)
|
|
60
|
+
val webView = bridge.webView as? WebView
|
|
61
|
+
if (webView == null) {
|
|
62
|
+
call.reject("WebView not available")
|
|
63
|
+
return@executeOnMainThread
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pm.print(content, settings, webView) { completed ->
|
|
67
|
+
val ret = JSObject()
|
|
68
|
+
ret.put("success", completed)
|
|
69
|
+
call.resolve(ret)
|
|
70
|
+
}
|
|
71
|
+
} catch (e: Exception) {
|
|
72
|
+
call.reject("Print failed: ${e.message}", e)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch (e: Exception) {
|
|
76
|
+
call.reject("Print failed: ${e.message}", e)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@PluginMethod
|
|
81
|
+
fun printHtml(call: PluginCall) {
|
|
82
|
+
val html = call.getString("html")
|
|
83
|
+
if (html == null) {
|
|
84
|
+
call.reject("The 'html' parameter is required")
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
val currentActivity = activity
|
|
88
|
+
if (currentActivity == null) {
|
|
89
|
+
call.reject("Activity not available")
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
val settings = extractSettings(call)
|
|
93
|
+
|
|
94
|
+
bridge.executeOnMainThread {
|
|
95
|
+
try {
|
|
96
|
+
val pm = PrintManager(currentActivity)
|
|
97
|
+
val webView = bridge.webView as? WebView
|
|
98
|
+
if (webView == null) {
|
|
99
|
+
call.reject("WebView not available")
|
|
100
|
+
return@executeOnMainThread
|
|
101
|
+
}
|
|
102
|
+
pm.print(html, settings, webView) { completed ->
|
|
103
|
+
val ret = JSObject()
|
|
104
|
+
ret.put("success", completed)
|
|
105
|
+
call.resolve(ret)
|
|
106
|
+
}
|
|
107
|
+
} catch (e: Exception) {
|
|
108
|
+
call.reject("Print failed: ${e.message}", e)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@PluginMethod
|
|
114
|
+
fun printPdf(call: PluginCall) {
|
|
115
|
+
val path = call.getString("path")
|
|
116
|
+
if (path == null) {
|
|
117
|
+
call.reject("The 'path' parameter is required")
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
val currentActivity = activity
|
|
121
|
+
if (currentActivity == null) {
|
|
122
|
+
call.reject("Activity not available")
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
val settings = extractSettings(call)
|
|
126
|
+
|
|
127
|
+
bridge.executeOnMainThread {
|
|
128
|
+
try {
|
|
129
|
+
val pm = PrintManager(currentActivity)
|
|
130
|
+
val webView = bridge.webView as? WebView
|
|
131
|
+
if (webView == null) {
|
|
132
|
+
call.reject("WebView not available")
|
|
133
|
+
return@executeOnMainThread
|
|
134
|
+
}
|
|
135
|
+
pm.print(path, settings, webView) { completed ->
|
|
136
|
+
val ret = JSObject()
|
|
137
|
+
ret.put("success", completed)
|
|
138
|
+
call.resolve(ret)
|
|
139
|
+
}
|
|
140
|
+
} catch (e: Exception) {
|
|
141
|
+
call.reject("Print failed: ${e.message}", e)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@PluginMethod
|
|
147
|
+
fun printBase64(call: PluginCall) {
|
|
148
|
+
val data = call.getString("data")
|
|
149
|
+
if (data == null) {
|
|
150
|
+
call.reject("The 'data' parameter is required")
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
val mimeType = call.getString("mimeType")
|
|
154
|
+
if (mimeType == null) {
|
|
155
|
+
call.reject("The 'mimeType' parameter is required")
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
val currentActivity = activity
|
|
159
|
+
if (currentActivity == null) {
|
|
160
|
+
call.reject("Activity not available")
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
val content = "base64:$data"
|
|
164
|
+
val settings = extractSettings(call)
|
|
165
|
+
|
|
166
|
+
bridge.executeOnMainThread {
|
|
167
|
+
try {
|
|
168
|
+
val pm = PrintManager(currentActivity)
|
|
169
|
+
val webView = bridge.webView as? WebView
|
|
170
|
+
if (webView == null) {
|
|
171
|
+
call.reject("WebView not available")
|
|
172
|
+
return@executeOnMainThread
|
|
173
|
+
}
|
|
174
|
+
pm.print(content, settings, webView, forcedMimeType = mimeType) { completed ->
|
|
175
|
+
val ret = JSObject()
|
|
176
|
+
ret.put("success", completed)
|
|
177
|
+
call.resolve(ret)
|
|
178
|
+
}
|
|
179
|
+
} catch (e: Exception) {
|
|
180
|
+
call.reject("Print failed: ${e.message}", e)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@PluginMethod
|
|
186
|
+
fun printFile(call: PluginCall) {
|
|
187
|
+
val path = call.getString("path")
|
|
188
|
+
if (path == null) {
|
|
189
|
+
call.reject("The 'path' parameter is required")
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
val currentActivity = activity
|
|
193
|
+
if (currentActivity == null) {
|
|
194
|
+
call.reject("Activity not available")
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
val mimeType = call.getString("mimeType")
|
|
198
|
+
val settings = extractSettings(call)
|
|
199
|
+
|
|
200
|
+
bridge.executeOnMainThread {
|
|
201
|
+
try {
|
|
202
|
+
val pm = PrintManager(currentActivity)
|
|
203
|
+
val webView = bridge.webView as? WebView
|
|
204
|
+
if (webView == null) {
|
|
205
|
+
call.reject("WebView not available")
|
|
206
|
+
return@executeOnMainThread
|
|
207
|
+
}
|
|
208
|
+
pm.print(path, settings, webView, forcedMimeType = mimeType) { completed ->
|
|
209
|
+
val ret = JSObject()
|
|
210
|
+
ret.put("success", completed)
|
|
211
|
+
call.resolve(ret)
|
|
212
|
+
}
|
|
213
|
+
} catch (e: Exception) {
|
|
214
|
+
call.reject("Print failed: ${e.message}", e)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@PluginMethod
|
|
220
|
+
fun printWebView(call: PluginCall) {
|
|
221
|
+
val currentActivity = activity
|
|
222
|
+
if (currentActivity == null) {
|
|
223
|
+
call.reject("Activity not available")
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
val settings = extractSettings(call)
|
|
227
|
+
|
|
228
|
+
bridge.executeOnMainThread {
|
|
229
|
+
try {
|
|
230
|
+
val pm = PrintManager(currentActivity)
|
|
231
|
+
val webView = bridge.webView as? WebView
|
|
232
|
+
if (webView == null) {
|
|
233
|
+
call.reject("WebView not available")
|
|
234
|
+
return@executeOnMainThread
|
|
235
|
+
}
|
|
236
|
+
pm.print(null, settings, webView) { completed ->
|
|
237
|
+
val ret = JSObject()
|
|
238
|
+
ret.put("success", completed)
|
|
239
|
+
call.resolve(ret)
|
|
240
|
+
}
|
|
241
|
+
} catch (e: Exception) {
|
|
242
|
+
call.reject("Print failed: ${e.message}", e)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private fun extractSettings(call: PluginCall): JSObject {
|
|
248
|
+
val settings = JSObject()
|
|
249
|
+
|
|
250
|
+
call.getString("name")?.let { settings.put("name", it) }
|
|
251
|
+
call.getString("orientation")?.let { settings.put("orientation", it) }
|
|
252
|
+
call.getString("duplex")?.let { settings.put("duplex", it) }
|
|
253
|
+
call.getBoolean("monochrome")?.let { settings.put("monochrome", it) }
|
|
254
|
+
call.getBoolean("photo")?.let { settings.put("photo", it) }
|
|
255
|
+
call.getInt("copies")?.let { settings.put("copies", it) }
|
|
256
|
+
call.getInt("pageCount")?.let { settings.put("pageCount", it) }
|
|
257
|
+
call.getBoolean("autoFit")?.let { settings.put("autoFit", it) }
|
|
258
|
+
call.getBoolean("javascript")?.let { settings.put("javascript", it) }
|
|
259
|
+
|
|
260
|
+
call.getObject("font")?.let { settings.put("font", it) }
|
|
261
|
+
call.getObject("paper")?.let { settings.put("paper", it) }
|
|
262
|
+
val margin = call.data.opt("margin")
|
|
263
|
+
if (margin != null) { settings.put("margin", margin) }
|
|
264
|
+
|
|
265
|
+
return settings
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
export interface PrinterPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Sends content to the printer.
|
|
4
|
+
*
|
|
5
|
+
* @param options - Print options including content and settings.
|
|
6
|
+
* @returns A promise resolving with the print result.
|
|
7
|
+
*/
|
|
8
|
+
print(options: PrintOptions): Promise<PrintResult>;
|
|
9
|
+
/**
|
|
10
|
+
* Prints an HTML string.
|
|
11
|
+
*
|
|
12
|
+
* Shorthand for `print()` with HTML content.
|
|
13
|
+
*
|
|
14
|
+
* @param options - HTML content and print settings.
|
|
15
|
+
* @returns A promise resolving with the print result.
|
|
16
|
+
*/
|
|
17
|
+
printHtml(options: PrintHtmlOptions): Promise<PrintResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Prints a PDF file from a file path or URI.
|
|
20
|
+
*
|
|
21
|
+
* @param options - PDF file path and print settings.
|
|
22
|
+
* @returns A promise resolving with the print result.
|
|
23
|
+
*/
|
|
24
|
+
printPdf(options: PrintPdfOptions): Promise<PrintResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Prints base64-encoded data with an explicit MIME type.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Base64 data, MIME type, and print settings.
|
|
29
|
+
* @returns A promise resolving with the print result.
|
|
30
|
+
*/
|
|
31
|
+
printBase64(options: PrintBase64Options): Promise<PrintResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Prints a file from a file path or URI, with optional MIME type.
|
|
34
|
+
*
|
|
35
|
+
* @param options - File path, optional MIME type, and print settings.
|
|
36
|
+
* @returns A promise resolving with the print result.
|
|
37
|
+
*/
|
|
38
|
+
printFile(options: PrintFileOptions): Promise<PrintResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Prints the current web view content.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Optional print settings (no content field).
|
|
43
|
+
* @returns A promise resolving with the print result.
|
|
44
|
+
*/
|
|
45
|
+
printWebView(options?: PrintWebViewOptions): Promise<PrintResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the device can print, optionally checking a specific item.
|
|
48
|
+
*
|
|
49
|
+
* @param options - Optional URI to check.
|
|
50
|
+
* @returns A promise resolving with availability info.
|
|
51
|
+
*/
|
|
52
|
+
canPrintItem(options?: CanPrintOptions): Promise<CanPrintResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a list of all printable document types (UTIs).
|
|
55
|
+
*
|
|
56
|
+
* @returns A promise resolving with printable types.
|
|
57
|
+
*/
|
|
58
|
+
getPrintableTypes(): Promise<PrintableTypesResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Displays system interface for selecting a printer (iOS only).
|
|
61
|
+
*
|
|
62
|
+
* @param options - Optional UI positioning options.
|
|
63
|
+
* @returns A promise resolving with the selected printer info.
|
|
64
|
+
*/
|
|
65
|
+
pick(options?: PickOptions): Promise<PickResult>;
|
|
66
|
+
}
|
|
67
|
+
export interface PrintOptions {
|
|
68
|
+
/**
|
|
69
|
+
* The content to print: HTML string, plain text, or file URI.
|
|
70
|
+
* If not provided, prints the current web view content.
|
|
71
|
+
*/
|
|
72
|
+
content?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The name of the print job.
|
|
75
|
+
*/
|
|
76
|
+
name?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The orientation of the printed content.
|
|
79
|
+
* @default 'portrait'
|
|
80
|
+
*/
|
|
81
|
+
orientation?: 'portrait' | 'landscape';
|
|
82
|
+
/**
|
|
83
|
+
* Whether to print in monochrome (grayscale).
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
monochrome?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to use photo quality printing.
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
photo?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Number of copies to print.
|
|
94
|
+
* @default 1
|
|
95
|
+
*/
|
|
96
|
+
copies?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Maximum number of pages to print.
|
|
99
|
+
*/
|
|
100
|
+
pageCount?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Duplex mode for double-sided printing.
|
|
103
|
+
* @default 'none'
|
|
104
|
+
*/
|
|
105
|
+
duplex?: 'none' | 'long' | 'short';
|
|
106
|
+
/**
|
|
107
|
+
* Margin settings. Set to false to remove margins,
|
|
108
|
+
* or provide an object with top/left/bottom/right values.
|
|
109
|
+
*
|
|
110
|
+
* iOS: values are in points. Strings with units ('1cm', '10mm', '0.5in') are supported.
|
|
111
|
+
* Android: values are converted to mils (thousandths of inch). Same unit strings are supported.
|
|
112
|
+
*/
|
|
113
|
+
margin?: boolean | MarginOptions;
|
|
114
|
+
/**
|
|
115
|
+
* Font settings for plain text printing.
|
|
116
|
+
*/
|
|
117
|
+
font?: FontOptions;
|
|
118
|
+
/**
|
|
119
|
+
* Maximum content width (e.g. '10cm', '4in').
|
|
120
|
+
*/
|
|
121
|
+
maxWidth?: string | number;
|
|
122
|
+
/**
|
|
123
|
+
* Maximum content height (e.g. '10cm', '4in').
|
|
124
|
+
*/
|
|
125
|
+
maxHeight?: string | number;
|
|
126
|
+
/**
|
|
127
|
+
* Header configuration (iOS only).
|
|
128
|
+
*/
|
|
129
|
+
header?: HeaderFooterOptions;
|
|
130
|
+
/**
|
|
131
|
+
* Footer configuration (iOS only).
|
|
132
|
+
*/
|
|
133
|
+
footer?: HeaderFooterOptions;
|
|
134
|
+
/**
|
|
135
|
+
* Paper size configuration (iOS + Android).
|
|
136
|
+
*
|
|
137
|
+
* Use `name` for standard sizes or `width`/`height` for custom dimensions.
|
|
138
|
+
* On Android, this sets the default media size in the print dialog
|
|
139
|
+
* (user can still change it). On iOS, the system selects the best
|
|
140
|
+
* matching paper from the printer's available stock.
|
|
141
|
+
*/
|
|
142
|
+
paper?: PaperOptions;
|
|
143
|
+
/**
|
|
144
|
+
* Printer URL to print directly without showing the picker dialog (iOS only).
|
|
145
|
+
*/
|
|
146
|
+
printer?: string;
|
|
147
|
+
/**
|
|
148
|
+
* UI positioning options for iPad popover.
|
|
149
|
+
*/
|
|
150
|
+
ui?: UIOptions;
|
|
151
|
+
/**
|
|
152
|
+
* Whether to auto-fit the image to the printable area (Android images only).
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
autoFit?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Whether to enable JavaScript in the print WebView (Android only).
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
javascript?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Common print settings shared by all dedicated print methods.
|
|
164
|
+
* Same as PrintOptions but without the generic `content` field.
|
|
165
|
+
*/
|
|
166
|
+
export type BasePrintOptions = Omit<PrintOptions, 'content'>;
|
|
167
|
+
/**
|
|
168
|
+
* Options for `printHtml()`.
|
|
169
|
+
*/
|
|
170
|
+
export interface PrintHtmlOptions extends BasePrintOptions {
|
|
171
|
+
/** The HTML string to print. */
|
|
172
|
+
html: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Options for `printPdf()`.
|
|
176
|
+
*/
|
|
177
|
+
export interface PrintPdfOptions extends BasePrintOptions {
|
|
178
|
+
/** The file path or URI of the PDF to print. */
|
|
179
|
+
path: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Options for `printBase64()`.
|
|
183
|
+
*/
|
|
184
|
+
export interface PrintBase64Options extends BasePrintOptions {
|
|
185
|
+
/** The base64-encoded data to print. */
|
|
186
|
+
data: string;
|
|
187
|
+
/** The MIME type of the data (e.g. 'application/pdf', 'image/png'). */
|
|
188
|
+
mimeType: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Options for `printFile()`.
|
|
192
|
+
*/
|
|
193
|
+
export interface PrintFileOptions extends BasePrintOptions {
|
|
194
|
+
/** The file path or URI of the file to print. */
|
|
195
|
+
path: string;
|
|
196
|
+
/** Optional MIME type. If not provided, the type is guessed from the file extension. */
|
|
197
|
+
mimeType?: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Options for `printWebView()`.
|
|
201
|
+
* No content field — prints the current web view.
|
|
202
|
+
*/
|
|
203
|
+
export type PrintWebViewOptions = BasePrintOptions;
|
|
204
|
+
export interface MarginOptions {
|
|
205
|
+
top?: string | number;
|
|
206
|
+
left?: string | number;
|
|
207
|
+
bottom?: string | number;
|
|
208
|
+
right?: string | number;
|
|
209
|
+
}
|
|
210
|
+
export interface FontOptions {
|
|
211
|
+
/** Font family name. */
|
|
212
|
+
name?: string;
|
|
213
|
+
/** Font size in points. */
|
|
214
|
+
size?: number;
|
|
215
|
+
/** Text color as hex string (e.g. '#FF0000'). */
|
|
216
|
+
color?: string;
|
|
217
|
+
/** Text alignment. */
|
|
218
|
+
align?: 'left' | 'right' | 'center' | 'justified';
|
|
219
|
+
/** Whether to use bold font. */
|
|
220
|
+
bold?: boolean;
|
|
221
|
+
/** Whether to use italic font. */
|
|
222
|
+
italic?: boolean;
|
|
223
|
+
}
|
|
224
|
+
export interface HeaderFooterOptions {
|
|
225
|
+
/** Height of the header/footer area (e.g. '1cm', '0.5in'). */
|
|
226
|
+
height?: string | number;
|
|
227
|
+
/** Text content for simple header/footer. */
|
|
228
|
+
text?: string;
|
|
229
|
+
/** Single label configuration. */
|
|
230
|
+
label?: LabelOptions;
|
|
231
|
+
/** Multiple label configurations. */
|
|
232
|
+
labels?: LabelOptions[];
|
|
233
|
+
}
|
|
234
|
+
export interface LabelOptions {
|
|
235
|
+
/** The text to display. */
|
|
236
|
+
text?: string;
|
|
237
|
+
/** Whether to show the page index. */
|
|
238
|
+
showPageIndex?: boolean;
|
|
239
|
+
/** Font settings for this label. */
|
|
240
|
+
font?: FontOptions;
|
|
241
|
+
/** Position offsets (e.g. '5mm', '1cm'). */
|
|
242
|
+
top?: string | number;
|
|
243
|
+
left?: string | number;
|
|
244
|
+
right?: string | number;
|
|
245
|
+
bottom?: string | number;
|
|
246
|
+
}
|
|
247
|
+
export interface PaperOptions {
|
|
248
|
+
/** Paper width (e.g. '210mm' for A4). */
|
|
249
|
+
width?: string | number;
|
|
250
|
+
/** Paper height (e.g. '297mm' for A4). */
|
|
251
|
+
height?: string | number;
|
|
252
|
+
/** Cut length for roll-fed printers (iOS only). */
|
|
253
|
+
length?: string | number;
|
|
254
|
+
/**
|
|
255
|
+
* Named paper size. Takes precedence over width/height.
|
|
256
|
+
*
|
|
257
|
+
* ISO sizes: 'A0'-'A10', 'B0'-'B10', 'C0'-'C10'
|
|
258
|
+
* North America: 'LETTER', 'LEGAL', 'TABLOID', 'LEDGER', 'JUNIOR_LEGAL',
|
|
259
|
+
* 'GOVT_LETTER', 'INDEX_3X5', '4X6', 'INDEX_5X8', 'QUARTO', 'FOOLSCAP'
|
|
260
|
+
* JIS: 'JIS_B0'-'JIS_B10', 'JIS_EXEC'
|
|
261
|
+
* Japanese: 'JPN_HAGAKI', 'JPN_OUFUKU', 'JPN_CHOU2'-'JPN_CHOU4',
|
|
262
|
+
* 'JPN_KAHU', 'JPN_KAKU2', 'JPN_YOU4'
|
|
263
|
+
* Chinese: 'ROC_8K', 'ROC_16K', 'PRC_1'-'PRC_10', 'PRC_16K',
|
|
264
|
+
* 'OM_PA_KAI', 'OM_DAI_PA_KAI', 'OM_JUURO_KU_KAI'
|
|
265
|
+
*
|
|
266
|
+
* Case-insensitive.
|
|
267
|
+
*/
|
|
268
|
+
name?: string;
|
|
269
|
+
}
|
|
270
|
+
export interface UIOptions {
|
|
271
|
+
/** Hide the number of copies selector (iOS only). */
|
|
272
|
+
hideNumberOfCopies?: boolean;
|
|
273
|
+
/** Hide the paper format selector (iOS only). */
|
|
274
|
+
hidePaperFormat?: boolean;
|
|
275
|
+
/** Top position for iPad popover. */
|
|
276
|
+
top?: number;
|
|
277
|
+
/** Left position for iPad popover. */
|
|
278
|
+
left?: number;
|
|
279
|
+
/** Width of the iPad popover anchor. */
|
|
280
|
+
width?: number;
|
|
281
|
+
/** Height of the iPad popover anchor. */
|
|
282
|
+
height?: number;
|
|
283
|
+
}
|
|
284
|
+
export interface PrintResult {
|
|
285
|
+
/** Whether the print job was successfully submitted. */
|
|
286
|
+
success: boolean;
|
|
287
|
+
}
|
|
288
|
+
export interface CanPrintOptions {
|
|
289
|
+
/** URI of the item to check (file://, res://, base64://). */
|
|
290
|
+
uri?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface CanPrintResult {
|
|
293
|
+
/** Whether the device can print (the specified item). */
|
|
294
|
+
available: boolean;
|
|
295
|
+
}
|
|
296
|
+
export interface PrintableTypesResult {
|
|
297
|
+
/** List of printable UTI types. */
|
|
298
|
+
types: string[];
|
|
299
|
+
}
|
|
300
|
+
export interface PickOptions {
|
|
301
|
+
/** UI positioning options for iPad popover. */
|
|
302
|
+
ui?: UIOptions;
|
|
303
|
+
}
|
|
304
|
+
export interface PickResult {
|
|
305
|
+
/** The URL of the selected printer, or undefined if cancelled. */
|
|
306
|
+
url?: string;
|
|
307
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
|
|
@@ -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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PrinterPlugin, PrintOptions, PrintResult, PrintHtmlOptions, PrintPdfOptions, PrintBase64Options, PrintFileOptions, PrintWebViewOptions, CanPrintOptions, CanPrintResult, PrintableTypesResult, PickOptions, PickResult } from './definitions';
|
|
3
|
+
export declare class PrinterWeb extends WebPlugin implements PrinterPlugin {
|
|
4
|
+
print(options: PrintOptions): Promise<PrintResult>;
|
|
5
|
+
printHtml({ html, ...opts }: PrintHtmlOptions): Promise<PrintResult>;
|
|
6
|
+
printPdf(_options: PrintPdfOptions): Promise<PrintResult>;
|
|
7
|
+
printBase64(_options: PrintBase64Options): Promise<PrintResult>;
|
|
8
|
+
printFile(_options: PrintFileOptions): Promise<PrintResult>;
|
|
9
|
+
printWebView(options?: PrintWebViewOptions): Promise<PrintResult>;
|
|
10
|
+
canPrintItem(_options?: CanPrintOptions): Promise<CanPrintResult>;
|
|
11
|
+
getPrintableTypes(): Promise<PrintableTypesResult>;
|
|
12
|
+
pick(_options?: PickOptions): Promise<PickResult>;
|
|
13
|
+
}
|