@capgo/capacitor-pdf-generator 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/CapgoCapacitorPdfGenerator.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +112 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/android/print/CapgoPdfPrintUtils.java +210 -0
- package/android/src/main/java/app/capgo/pdfgenerator/PdfGeneratorPlugin.java +381 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/android/src/main/res/xml/capgo_pdf_generator_paths.xml +6 -0
- package/dist/docs.json +109 -0
- package/dist/esm/definitions.d.ts +56 -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 +6 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +24 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +27 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PdfGeneratorPlugin/PdfGeneratorPlugin.swift +292 -0
- package/ios/Tests/PdfGeneratorPluginTests/PdfGeneratorPluginTests.swift +7 -0
- package/package.json +86 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
package app.capgo.pdfgenerator;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.ActivityNotFoundException;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.net.Uri;
|
|
7
|
+
import android.os.Handler;
|
|
8
|
+
import android.os.Looper;
|
|
9
|
+
import android.print.CapgoPdfPrintUtils;
|
|
10
|
+
import android.print.PrintAttributes;
|
|
11
|
+
import android.print.PrintDocumentAdapter;
|
|
12
|
+
import android.webkit.WebResourceError;
|
|
13
|
+
import android.webkit.WebResourceRequest;
|
|
14
|
+
import android.webkit.WebSettings;
|
|
15
|
+
import android.webkit.WebView;
|
|
16
|
+
import android.webkit.WebViewClient;
|
|
17
|
+
import androidx.annotation.NonNull;
|
|
18
|
+
import androidx.core.content.FileProvider;
|
|
19
|
+
import com.getcapacitor.JSObject;
|
|
20
|
+
import com.getcapacitor.Plugin;
|
|
21
|
+
import com.getcapacitor.PluginCall;
|
|
22
|
+
import com.getcapacitor.PluginMethod;
|
|
23
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
24
|
+
import java.io.File;
|
|
25
|
+
import java.util.ArrayList;
|
|
26
|
+
import java.util.List;
|
|
27
|
+
import java.util.Locale;
|
|
28
|
+
|
|
29
|
+
@CapacitorPlugin(name = "PdfGenerator")
|
|
30
|
+
public class PdfGeneratorPlugin extends Plugin {
|
|
31
|
+
|
|
32
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
33
|
+
private final List<PdfGenerationTask> tasks = new ArrayList<>();
|
|
34
|
+
|
|
35
|
+
@PluginMethod
|
|
36
|
+
public void fromURL(PluginCall call) {
|
|
37
|
+
String url = call.getString("url");
|
|
38
|
+
if (url == null || url.trim().isEmpty()) {
|
|
39
|
+
call.reject("A valid 'url' is required.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
PdfGeneratorOptions options = PdfGeneratorOptions.from(call);
|
|
44
|
+
PdfSource source = new UrlSource(url);
|
|
45
|
+
enqueueTask(new PdfGenerationTask(this, call, source, options));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@PluginMethod
|
|
49
|
+
public void fromData(PluginCall call) {
|
|
50
|
+
String data = call.getString("data");
|
|
51
|
+
if (data == null || data.trim().isEmpty()) {
|
|
52
|
+
call.reject("The 'data' option is required.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
PdfGeneratorOptions options = PdfGeneratorOptions.from(call);
|
|
57
|
+
PdfSource source = new HtmlSource(data, options.baseUrl);
|
|
58
|
+
enqueueTask(new PdfGenerationTask(this, call, source, options));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private void enqueueTask(PdfGenerationTask task) {
|
|
62
|
+
synchronized (tasks) {
|
|
63
|
+
tasks.add(task);
|
|
64
|
+
}
|
|
65
|
+
task.start();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void removeTask(PdfGenerationTask task) {
|
|
69
|
+
synchronized (tasks) {
|
|
70
|
+
tasks.remove(task);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void generatePdf(PdfGenerationTask task, WebView webView) {
|
|
75
|
+
PrintAttributes attributes = createPrintAttributes(task.options);
|
|
76
|
+
String jobName = task.options.printJobName();
|
|
77
|
+
PrintDocumentAdapter adapter = webView.createPrintDocumentAdapter(jobName);
|
|
78
|
+
|
|
79
|
+
if (task.options.outputType == PdfGeneratorOptions.OutputType.BASE64) {
|
|
80
|
+
CapgoPdfPrintUtils.createBase64(
|
|
81
|
+
getContext(),
|
|
82
|
+
adapter,
|
|
83
|
+
attributes,
|
|
84
|
+
new CapgoPdfPrintUtils.Base64Callback() {
|
|
85
|
+
@Override
|
|
86
|
+
public void onSuccess(@NonNull String base64) {
|
|
87
|
+
mainHandler.post(
|
|
88
|
+
() -> {
|
|
89
|
+
JSObject result = new JSObject();
|
|
90
|
+
result.put("type", "base64");
|
|
91
|
+
result.put("base64", base64);
|
|
92
|
+
task.call.resolve(result);
|
|
93
|
+
task.finish();
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Override
|
|
99
|
+
public void onError(@NonNull String message) {
|
|
100
|
+
mainHandler.post(
|
|
101
|
+
() -> {
|
|
102
|
+
task.call.reject(message);
|
|
103
|
+
task.finish();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
File output = new File(getContext().getCacheDir(), task.options.fileName);
|
|
111
|
+
CapgoPdfPrintUtils.writeToFile(
|
|
112
|
+
getContext(),
|
|
113
|
+
adapter,
|
|
114
|
+
attributes,
|
|
115
|
+
output,
|
|
116
|
+
new CapgoPdfPrintUtils.FileCallback() {
|
|
117
|
+
@Override
|
|
118
|
+
public void onSuccess(@NonNull File file) {
|
|
119
|
+
mainHandler.post(() -> sharePdf(task, file));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Override
|
|
123
|
+
public void onError(@NonNull String message) {
|
|
124
|
+
mainHandler.post(
|
|
125
|
+
() -> {
|
|
126
|
+
task.call.reject(message);
|
|
127
|
+
task.finish();
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private void sharePdf(PdfGenerationTask task, File file) {
|
|
137
|
+
Activity activity = getActivity();
|
|
138
|
+
if (activity == null) {
|
|
139
|
+
task.call.reject("Unable to open share dialog: no active activity.");
|
|
140
|
+
task.finish();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Uri uri = FileProvider.getUriForFile(
|
|
145
|
+
getContext(),
|
|
146
|
+
getContext().getPackageName() + ".capgo.pdfgenerator.fileprovider",
|
|
147
|
+
file
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
|
151
|
+
shareIntent.setType("application/pdf");
|
|
152
|
+
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
|
153
|
+
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
154
|
+
|
|
155
|
+
file.deleteOnExit();
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
Intent chooser = Intent.createChooser(shareIntent, task.options.fileName);
|
|
159
|
+
activity.startActivity(chooser);
|
|
160
|
+
JSObject result = new JSObject();
|
|
161
|
+
result.put("type", "share");
|
|
162
|
+
result.put("completed", true);
|
|
163
|
+
task.call.resolve(result);
|
|
164
|
+
} catch (ActivityNotFoundException ex) {
|
|
165
|
+
task.call.reject("No compatible application found to share the PDF.");
|
|
166
|
+
} finally {
|
|
167
|
+
task.finish();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private PrintAttributes createPrintAttributes(PdfGeneratorOptions options) {
|
|
172
|
+
PrintAttributes.Builder builder = new PrintAttributes.Builder();
|
|
173
|
+
PrintAttributes.MediaSize mediaSize = options.mediaSize();
|
|
174
|
+
builder.setMediaSize(mediaSize);
|
|
175
|
+
builder.setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600));
|
|
176
|
+
builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS);
|
|
177
|
+
return builder.build();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface PdfSource {
|
|
182
|
+
void load(WebView webView);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
final class UrlSource implements PdfSource {
|
|
186
|
+
|
|
187
|
+
private final String url;
|
|
188
|
+
|
|
189
|
+
UrlSource(String url) {
|
|
190
|
+
this.url = url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Override
|
|
194
|
+
public void load(WebView webView) {
|
|
195
|
+
webView.loadUrl(url);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
final class HtmlSource implements PdfSource {
|
|
200
|
+
|
|
201
|
+
private final String html;
|
|
202
|
+
private final String baseUrl;
|
|
203
|
+
|
|
204
|
+
HtmlSource(String html, String baseUrl) {
|
|
205
|
+
this.html = html;
|
|
206
|
+
this.baseUrl = baseUrl;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@Override
|
|
210
|
+
public void load(WebView webView) {
|
|
211
|
+
webView.loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
final class PdfGenerationTask extends WebViewClient {
|
|
216
|
+
|
|
217
|
+
final PluginCall call;
|
|
218
|
+
final PdfGeneratorOptions options;
|
|
219
|
+
|
|
220
|
+
private final PdfGeneratorPlugin plugin;
|
|
221
|
+
private WebView webView;
|
|
222
|
+
private boolean finished;
|
|
223
|
+
|
|
224
|
+
PdfGenerationTask(PdfGeneratorPlugin plugin, PluginCall call, PdfSource source, PdfGeneratorOptions options) {
|
|
225
|
+
this.plugin = plugin;
|
|
226
|
+
this.call = call;
|
|
227
|
+
this.options = options;
|
|
228
|
+
this.source = source;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private final PdfSource source;
|
|
232
|
+
|
|
233
|
+
void start() {
|
|
234
|
+
Activity activity = plugin.getActivity();
|
|
235
|
+
if (activity == null) {
|
|
236
|
+
call.reject("No activity available.");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
activity.runOnUiThread(
|
|
241
|
+
() -> {
|
|
242
|
+
webView = new WebView(plugin.getContext());
|
|
243
|
+
WebSettings settings = webView.getSettings();
|
|
244
|
+
settings.setJavaScriptEnabled(true);
|
|
245
|
+
settings.setDatabaseEnabled(true);
|
|
246
|
+
webView.setWebViewClient(this);
|
|
247
|
+
source.load(webView);
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
void finish() {
|
|
253
|
+
if (finished) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
finished = true;
|
|
257
|
+
Activity activity = plugin.getActivity();
|
|
258
|
+
if (activity != null) {
|
|
259
|
+
activity.runOnUiThread(
|
|
260
|
+
() -> {
|
|
261
|
+
if (webView != null) {
|
|
262
|
+
webView.stopLoading();
|
|
263
|
+
webView.setWebViewClient(null);
|
|
264
|
+
webView.destroy();
|
|
265
|
+
webView = null;
|
|
266
|
+
}
|
|
267
|
+
plugin.removeTask(this);
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
} else {
|
|
271
|
+
plugin.removeTask(this);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@Override
|
|
276
|
+
public void onPageFinished(WebView view, String url) {
|
|
277
|
+
plugin.generatePdf(this, view);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@Override
|
|
281
|
+
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
|
282
|
+
call.reject("Failed to load content: " + error.getDescription());
|
|
283
|
+
finish();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
final class PdfGeneratorOptions {
|
|
288
|
+
|
|
289
|
+
enum OutputType {
|
|
290
|
+
BASE64,
|
|
291
|
+
SHARE;
|
|
292
|
+
|
|
293
|
+
static OutputType from(String value) {
|
|
294
|
+
return "share".equalsIgnoreCase(value) ? SHARE : BASE64;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
final OutputType outputType;
|
|
299
|
+
final String documentSize;
|
|
300
|
+
final boolean landscape;
|
|
301
|
+
final String fileName;
|
|
302
|
+
final String baseUrl;
|
|
303
|
+
|
|
304
|
+
private PdfGeneratorOptions(OutputType outputType, String documentSize, boolean landscape, String fileName, String baseUrl) {
|
|
305
|
+
this.outputType = outputType;
|
|
306
|
+
this.documentSize = documentSize;
|
|
307
|
+
this.landscape = landscape;
|
|
308
|
+
this.fileName = ensurePdfExtension(fileName);
|
|
309
|
+
this.baseUrl = baseUrl;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static PdfGeneratorOptions from(PluginCall call) {
|
|
313
|
+
String docSize = call.getString("documentSize", "A4");
|
|
314
|
+
boolean landscape = resolveLandscape(call);
|
|
315
|
+
String type = call.getString("type", "base64");
|
|
316
|
+
String fileName = call.getString("fileName", "default.pdf");
|
|
317
|
+
String baseUrl = normalizeBaseUrl(call.getString("baseUrl"));
|
|
318
|
+
return new PdfGeneratorOptions(OutputType.from(type), docSize, landscape, fileName, baseUrl);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private static boolean resolveLandscape(PluginCall call) {
|
|
322
|
+
JSObject data = call.getData();
|
|
323
|
+
if (data != null && data.has("landscape")) {
|
|
324
|
+
Object landscapeOption = data.opt("landscape");
|
|
325
|
+
if (landscapeOption instanceof Boolean) {
|
|
326
|
+
return (Boolean) landscapeOption;
|
|
327
|
+
}
|
|
328
|
+
if (landscapeOption instanceof String) {
|
|
329
|
+
return ((String) landscapeOption).equalsIgnoreCase("landscape");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
String orientation = call.getString("orientation");
|
|
334
|
+
if (orientation != null) {
|
|
335
|
+
return orientation.equalsIgnoreCase("landscape");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
String landscapeString = call.getString("landscape", "portrait");
|
|
339
|
+
return landscapeString.equalsIgnoreCase("landscape");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private static String ensurePdfExtension(String value) {
|
|
343
|
+
String trimmed = value == null ? "" : value.trim();
|
|
344
|
+
if (trimmed.isEmpty()) {
|
|
345
|
+
trimmed = "default.pdf";
|
|
346
|
+
}
|
|
347
|
+
String sanitized = trimmed.replaceAll("[\\\\/:]", "_");
|
|
348
|
+
if (!sanitized.toLowerCase(Locale.ROOT).endsWith(".pdf")) {
|
|
349
|
+
sanitized = sanitized + ".pdf";
|
|
350
|
+
}
|
|
351
|
+
return sanitized;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private static String normalizeBaseUrl(String baseUrl) {
|
|
355
|
+
if (baseUrl == null) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
String trimmed = baseUrl.trim();
|
|
359
|
+
if (trimmed.isEmpty()) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
if ("BUNDLE".equalsIgnoreCase(trimmed)) {
|
|
363
|
+
return "file:///android_asset/";
|
|
364
|
+
}
|
|
365
|
+
return trimmed;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
PrintAttributes.MediaSize mediaSize() {
|
|
369
|
+
PrintAttributes.MediaSize mediaSize = PrintAttributes.MediaSize.ISO_A4;
|
|
370
|
+
if ("A3".equalsIgnoreCase(documentSize)) {
|
|
371
|
+
mediaSize = PrintAttributes.MediaSize.ISO_A3;
|
|
372
|
+
}
|
|
373
|
+
return landscape ? mediaSize.asLandscape() : mediaSize.asPortrait();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
String printJobName() {
|
|
377
|
+
String name = fileName;
|
|
378
|
+
int dotIndex = name.lastIndexOf('.');
|
|
379
|
+
return dotIndex > 0 ? name.substring(0, dotIndex) : name;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "PdfGeneratorPlugin",
|
|
4
|
+
"slug": "pdfgeneratorplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "fromURL",
|
|
10
|
+
"signature": "(options: PdfGeneratorFromUrlOptions) => Promise<PdfGeneratorResult>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "PdfGeneratorFromUrlOptions"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<PdfGeneratorResult>",
|
|
19
|
+
"tags": [],
|
|
20
|
+
"docs": "Generates a PDF from the provided URL.",
|
|
21
|
+
"complexTypes": [
|
|
22
|
+
"PdfGeneratorResult",
|
|
23
|
+
"PdfGeneratorFromUrlOptions"
|
|
24
|
+
],
|
|
25
|
+
"slug": "fromurl"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "fromData",
|
|
29
|
+
"signature": "(options: PdfGeneratorFromDataOptions) => Promise<PdfGeneratorResult>",
|
|
30
|
+
"parameters": [
|
|
31
|
+
{
|
|
32
|
+
"name": "options",
|
|
33
|
+
"docs": "",
|
|
34
|
+
"type": "PdfGeneratorFromDataOptions"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"returns": "Promise<PdfGeneratorResult>",
|
|
38
|
+
"tags": [],
|
|
39
|
+
"docs": "Generates a PDF from a raw HTML string.",
|
|
40
|
+
"complexTypes": [
|
|
41
|
+
"PdfGeneratorResult",
|
|
42
|
+
"PdfGeneratorFromDataOptions"
|
|
43
|
+
],
|
|
44
|
+
"slug": "fromdata"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"properties": []
|
|
48
|
+
},
|
|
49
|
+
"interfaces": [
|
|
50
|
+
{
|
|
51
|
+
"name": "PdfGeneratorFromUrlOptions",
|
|
52
|
+
"slug": "pdfgeneratorfromurloptions",
|
|
53
|
+
"docs": "",
|
|
54
|
+
"tags": [],
|
|
55
|
+
"methods": [],
|
|
56
|
+
"properties": [
|
|
57
|
+
{
|
|
58
|
+
"name": "url",
|
|
59
|
+
"tags": [],
|
|
60
|
+
"docs": "",
|
|
61
|
+
"complexTypes": [],
|
|
62
|
+
"type": "string"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "PdfGeneratorFromDataOptions",
|
|
68
|
+
"slug": "pdfgeneratorfromdataoptions",
|
|
69
|
+
"docs": "",
|
|
70
|
+
"tags": [],
|
|
71
|
+
"methods": [],
|
|
72
|
+
"properties": [
|
|
73
|
+
{
|
|
74
|
+
"name": "data",
|
|
75
|
+
"tags": [],
|
|
76
|
+
"docs": "HTML document to render.",
|
|
77
|
+
"complexTypes": [],
|
|
78
|
+
"type": "string"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "baseUrl",
|
|
82
|
+
"tags": [],
|
|
83
|
+
"docs": "Base URL to use when resolving relative resources inside the HTML string.\nWhen omitted, `about:blank` is used.",
|
|
84
|
+
"complexTypes": [],
|
|
85
|
+
"type": "string | undefined"
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"enums": [],
|
|
91
|
+
"typeAliases": [
|
|
92
|
+
{
|
|
93
|
+
"name": "PdfGeneratorResult",
|
|
94
|
+
"slug": "pdfgeneratorresult",
|
|
95
|
+
"docs": "",
|
|
96
|
+
"types": [
|
|
97
|
+
{
|
|
98
|
+
"text": "{\n type: 'base64';\n base64: string;\n }",
|
|
99
|
+
"complexTypes": []
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"text": "{\n type: 'share';\n completed: boolean;\n }",
|
|
103
|
+
"complexTypes": []
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"pluginConfigs": []
|
|
109
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type PdfGeneratorDocumentSize = 'A3' | 'A4';
|
|
2
|
+
export type PdfGeneratorOutputType = 'base64' | 'share';
|
|
3
|
+
export interface PdfGeneratorCommonOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Document size used when rendering the PDF.
|
|
6
|
+
* Only `A3` and `A4` are supported right now and default to `A4`.
|
|
7
|
+
*/
|
|
8
|
+
documentSize?: PdfGeneratorDocumentSize;
|
|
9
|
+
/**
|
|
10
|
+
* Page orientation. Defaults to `portrait`.
|
|
11
|
+
*/
|
|
12
|
+
orientation?: 'portrait' | 'landscape';
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `orientation` instead. Kept for backward compatibility with the Cordova plugin.
|
|
15
|
+
*/
|
|
16
|
+
landscape?: 'portrait' | 'landscape' | boolean;
|
|
17
|
+
/**
|
|
18
|
+
* How the result should be returned. Defaults to `base64`.
|
|
19
|
+
*/
|
|
20
|
+
type?: PdfGeneratorOutputType;
|
|
21
|
+
/**
|
|
22
|
+
* File name used when the PDF is exported to disk (share mode).
|
|
23
|
+
*/
|
|
24
|
+
fileName?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PdfGeneratorFromUrlOptions extends PdfGeneratorCommonOptions {
|
|
27
|
+
url: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PdfGeneratorFromDataOptions extends PdfGeneratorCommonOptions {
|
|
30
|
+
/**
|
|
31
|
+
* HTML document to render.
|
|
32
|
+
*/
|
|
33
|
+
data: string;
|
|
34
|
+
/**
|
|
35
|
+
* Base URL to use when resolving relative resources inside the HTML string.
|
|
36
|
+
* When omitted, `about:blank` is used.
|
|
37
|
+
*/
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
}
|
|
40
|
+
export type PdfGeneratorResult = {
|
|
41
|
+
type: 'base64';
|
|
42
|
+
base64: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'share';
|
|
45
|
+
completed: boolean;
|
|
46
|
+
};
|
|
47
|
+
export interface PdfGeneratorPlugin {
|
|
48
|
+
/**
|
|
49
|
+
* Generates a PDF from the provided URL.
|
|
50
|
+
*/
|
|
51
|
+
fromURL(options: PdfGeneratorFromUrlOptions): Promise<PdfGeneratorResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Generates a PDF from a raw HTML string.
|
|
54
|
+
*/
|
|
55
|
+
fromData(options: PdfGeneratorFromDataOptions): Promise<PdfGeneratorResult>;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type PdfGeneratorDocumentSize = 'A3' | 'A4';\n\nexport type PdfGeneratorOutputType = 'base64' | 'share';\n\nexport interface PdfGeneratorCommonOptions {\n /**\n * Document size used when rendering the PDF.\n * Only `A3` and `A4` are supported right now and default to `A4`.\n */\n documentSize?: PdfGeneratorDocumentSize;\n /**\n * Page orientation. Defaults to `portrait`.\n */\n orientation?: 'portrait' | 'landscape';\n /**\n * @deprecated Use `orientation` instead. Kept for backward compatibility with the Cordova plugin.\n */\n landscape?: 'portrait' | 'landscape' | boolean;\n /**\n * How the result should be returned. Defaults to `base64`.\n */\n type?: PdfGeneratorOutputType;\n /**\n * File name used when the PDF is exported to disk (share mode).\n */\n fileName?: string;\n}\n\nexport interface PdfGeneratorFromUrlOptions extends PdfGeneratorCommonOptions {\n url: string;\n}\n\nexport interface PdfGeneratorFromDataOptions extends PdfGeneratorCommonOptions {\n /**\n * HTML document to render.\n */\n data: string;\n /**\n * Base URL to use when resolving relative resources inside the HTML string.\n * When omitted, `about:blank` is used.\n */\n baseUrl?: string;\n}\n\nexport type PdfGeneratorResult =\n | {\n type: 'base64';\n base64: string;\n }\n | {\n type: 'share';\n completed: boolean;\n };\n\nexport interface PdfGeneratorPlugin {\n /**\n * Generates a PDF from the provided URL.\n */\n fromURL(options: PdfGeneratorFromUrlOptions): Promise<PdfGeneratorResult>;\n /**\n * Generates a PDF from a raw HTML string.\n */\n fromData(options: PdfGeneratorFromDataOptions): Promise<PdfGeneratorResult>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const PdfGenerator = registerPlugin('PdfGenerator', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.PdfGeneratorWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { PdfGenerator };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { PdfGeneratorPlugin } from './definitions';\n\nconst PdfGenerator = registerPlugin<PdfGeneratorPlugin>('PdfGenerator', {\n web: () => import('./web').then((m) => new m.PdfGeneratorWeb()),\n});\n\nexport * from './definitions';\nexport { PdfGenerator };\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PdfGeneratorFromDataOptions, PdfGeneratorFromUrlOptions, PdfGeneratorPlugin, PdfGeneratorResult } from './definitions';
|
|
3
|
+
export declare class PdfGeneratorWeb extends WebPlugin implements PdfGeneratorPlugin {
|
|
4
|
+
fromURL(_options: PdfGeneratorFromUrlOptions): Promise<PdfGeneratorResult>;
|
|
5
|
+
fromData(_options: PdfGeneratorFromDataOptions): Promise<PdfGeneratorResult>;
|
|
6
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class PdfGeneratorWeb extends WebPlugin {
|
|
3
|
+
async fromURL(_options) {
|
|
4
|
+
throw this.unimplemented('fromURL is not available in the web implementation.');
|
|
5
|
+
}
|
|
6
|
+
async fromData(_options) {
|
|
7
|
+
throw this.unimplemented('fromData is not available in the web implementation.');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,OAAO,CAAC,QAAoC;QAChD,MAAM,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC;IAClF,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAqC;QAClD,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC,CAAC;IACnF,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n PdfGeneratorFromDataOptions,\n PdfGeneratorFromUrlOptions,\n PdfGeneratorPlugin,\n PdfGeneratorResult,\n} from './definitions';\n\nexport class PdfGeneratorWeb extends WebPlugin implements PdfGeneratorPlugin {\n async fromURL(_options: PdfGeneratorFromUrlOptions): Promise<PdfGeneratorResult> {\n throw this.unimplemented('fromURL is not available in the web implementation.');\n }\n\n async fromData(_options: PdfGeneratorFromDataOptions): Promise<PdfGeneratorResult> {\n throw this.unimplemented('fromData is not available in the web implementation.');\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const PdfGenerator = core.registerPlugin('PdfGenerator', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PdfGeneratorWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class PdfGeneratorWeb extends core.WebPlugin {
|
|
10
|
+
async fromURL(_options) {
|
|
11
|
+
throw this.unimplemented('fromURL is not available in the web implementation.');
|
|
12
|
+
}
|
|
13
|
+
async fromData(_options) {
|
|
14
|
+
throw this.unimplemented('fromData is not available in the web implementation.');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
19
|
+
__proto__: null,
|
|
20
|
+
PdfGeneratorWeb: PdfGeneratorWeb
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
exports.PdfGenerator = PdfGenerator;
|
|
24
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PdfGenerator = registerPlugin('PdfGenerator', {\n web: () => import('./web').then((m) => new m.PdfGeneratorWeb()),\n});\nexport * from './definitions';\nexport { PdfGenerator };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PdfGeneratorWeb extends WebPlugin {\n async fromURL(_options) {\n throw this.unimplemented('fromURL is not available in the web implementation.');\n }\n async fromData(_options) {\n throw this.unimplemented('fromData is not available in the web implementation.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,OAAO,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC;AACvF,IAAI;AACJ,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAE;AAC7B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC;AACxF,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var capacitorCapacitorPdfGenerator = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const PdfGenerator = core.registerPlugin('PdfGenerator', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PdfGeneratorWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class PdfGeneratorWeb extends core.WebPlugin {
|
|
9
|
+
async fromURL(_options) {
|
|
10
|
+
throw this.unimplemented('fromURL is not available in the web implementation.');
|
|
11
|
+
}
|
|
12
|
+
async fromData(_options) {
|
|
13
|
+
throw this.unimplemented('fromData is not available in the web implementation.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
18
|
+
__proto__: null,
|
|
19
|
+
PdfGeneratorWeb: PdfGeneratorWeb
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.PdfGenerator = PdfGenerator;
|
|
23
|
+
|
|
24
|
+
return exports;
|
|
25
|
+
|
|
26
|
+
})({}, capacitorExports);
|
|
27
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PdfGenerator = registerPlugin('PdfGenerator', {\n web: () => import('./web').then((m) => new m.PdfGeneratorWeb()),\n});\nexport * from './definitions';\nexport { PdfGenerator };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PdfGeneratorWeb extends WebPlugin {\n async fromURL(_options) {\n throw this.unimplemented('fromURL is not available in the web implementation.');\n }\n async fromData(_options) {\n throw this.unimplemented('fromData is not available in the web implementation.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,OAAO,CAAC,QAAQ,EAAE;IAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC;IACvF,IAAI;IACJ,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAE;IAC7B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC;IACxF,IAAI;IACJ;;;;;;;;;;;;;;;"}
|