expo-print 11.3.0 → 12.1.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/CHANGELOG.md CHANGED
@@ -10,6 +10,22 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 12.1.0 — 2023-01-05
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix `printAsync` not reflecting custom width/ height, `useMarkupFormatter` option preventing custom width/ height/ margin from being reflected. ([#18873](https://github.com/expo/expo/pull/20046) by [@keith-kurak](https://github.com/keith-kurak))
18
+
19
+ ## 12.0.0 — 2022-10-25
20
+
21
+ ### 🛠 Breaking changes
22
+
23
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
24
+
25
+ ### 🐛 Bug fixes
26
+
27
+ - Fix crash on some Android devices when WebView returns an unknown error. ([#18911](https://github.com/expo/expo/pull/18911) by [@matkastner](https://github.com/matkastner))
28
+
13
29
  ## 11.3.0 — 2022-07-07
14
30
 
15
31
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -4,7 +4,7 @@ Provides an API for iOS (AirPrint) and Android printing functionality.
4
4
 
5
5
  # API documentation
6
6
 
7
- - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/print.md)
7
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/print.mdx)
8
8
  - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/print/)
9
9
 
10
10
  # Installation in managed Expo projects
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '11.3.0'
6
+ version = '12.1.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
76
76
  versionCode 27
77
- versionName "11.3.0"
77
+ versionName "12.1.0"
78
78
  }
79
79
  lintOptions {
80
80
  abortOnError false
@@ -110,7 +110,7 @@ class PrintPDFRenderTask(private val context: Context, private val options: Map<
110
110
  callbacks.onRenderFinished(document, outputFile, numberOfPages)
111
111
  }
112
112
 
113
- override fun onWriteFailed(error: CharSequence) {
113
+ override fun onWriteFailed(error: CharSequence?) {
114
114
  callbacks.onRenderError("E_PRINT_FAILED", "An error occurred while writing PDF data.", null)
115
115
  }
116
116
  }
@@ -1,4 +1,4 @@
1
- export declare type PrintOptions = {
1
+ export type PrintOptions = {
2
2
  /**
3
3
  * URI of a PDF file to print. Remote, local (ex. selected via `DocumentPicker`) or base64 data URI
4
4
  * starting with `data:application/pdf;base64,`. This only supports PDF, not other types of
@@ -52,7 +52,7 @@ export declare type PrintOptions = {
52
52
  */
53
53
  margins?: PageMargins;
54
54
  };
55
- export declare type Printer = {
55
+ export type Printer = {
56
56
  /**
57
57
  * Name of the printer.
58
58
  */
@@ -69,13 +69,13 @@ export interface OrientationType {
69
69
  portrait: string;
70
70
  landscape: string;
71
71
  }
72
- export declare type PageMargins = {
72
+ export type PageMargins = {
73
73
  top: number;
74
74
  right: number;
75
75
  bottom: number;
76
76
  left: number;
77
77
  };
78
- export declare type FilePrintOptions = {
78
+ export type FilePrintOptions = {
79
79
  /**
80
80
  * HTML string to print into PDF file.
81
81
  */
@@ -106,7 +106,7 @@ export declare type FilePrintOptions = {
106
106
  */
107
107
  base64?: boolean;
108
108
  };
109
- export declare type FilePrintResult = {
109
+ export type FilePrintResult = {
110
110
  /**
111
111
  * A URI to the printed PDF file.
112
112
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Print.types.d.ts","sourceRoot":"","sources":["../src/Print.types.ts"],"names":[],"mappings":"AACA,oBAAY,YAAY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IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -63,38 +63,14 @@ EX_EXPORT_METHOD_AS(print,
63
63
  reject(errorDetails[@"code"], errorDetails[@"message"], EXErrorWithMessage(errorDetails[@"message"]));
64
64
  return;
65
65
  }
66
-
66
+
67
67
  UIPrintInteractionController *printInteractionController = [self _makePrintInteractionControllerWithOptions:options];
68
-
69
- if (printingData == nil) {
70
- // Missing printing data.
71
- // Let's check if someone wanted to use previous implementation for `html` option
72
- // which uses print formatter instead of NSData instance.
73
-
74
- NSString *htmlString = nil;
75
- if ([options[@"useMarkupFormatter"] boolValue]) {
76
- htmlString = options[@"html"];
77
- } else if (options[@"markupFormatterIOS"] && [options[@"markupFormatterIOS"] isKindOfClass:[NSString class]]) {
78
- htmlString = options[@"markupFormatterIOS"];
79
- } else {
80
- reject(@"E_NOTHING_TO_PRINT", @"No data to print. You must specify `uri` or `html` option.", nil);
81
- return;
82
- }
83
- if (htmlString != nil) {
84
- UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString];
85
- printInteractionController.printFormatter = formatter;
86
- } else {
87
- NSString *message = [NSString stringWithFormat:@"The specified html string is not valid for printing."];
88
- reject(@"E_HTML_INVALID", message, EXErrorWithMessage(message));
89
- return;
90
- }
91
- }
92
-
68
+
93
69
  printInteractionController.printingItem = printingData;
94
-
70
+
95
71
  NSString *printerURL;
96
72
  UIPrinter *printer;
97
-
73
+
98
74
  if (options[@"printerUrl"] && [options[@"printerUrl"] isKindOfClass:[NSString class]]) {
99
75
  // @tsapeta: Printing to the printer created with given URL ([UIPrinter printerWithURL:]) doesn't work for me,
100
76
  // it seems to be a bug in iOS however I've found confirmation only on Xamarin forums.
@@ -102,29 +78,29 @@ EX_EXPORT_METHOD_AS(print,
102
78
  // The hacky solution is to save all UIPrinters that have been selected using `selectPrinter` method and reuse
103
79
  // them when printing to specific printer.
104
80
  // I guess it's also safe to fall back to this not working solution since it might be fixed in the future.
105
-
81
+
106
82
  printerURL = options[@"printerUrl"];
107
83
  printer = [self.printers objectForKey:printerURL];
108
-
84
+
109
85
  if (printer == nil) {
110
86
  printer = [UIPrinter printerWithURL:[NSURL URLWithString:printerURL]];
111
87
  }
112
88
  }
113
-
89
+
114
90
  void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
115
91
  ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
116
92
  if (error != nil) {
117
93
  reject(@"E_CANNOT_PRINT", @"Printing job encountered an error.", error);
118
94
  return;
119
95
  }
120
-
96
+
121
97
  if (completed) {
122
98
  resolve(nil);
123
99
  } else {
124
100
  reject(@"E_PRINT_INCOMPLETE", @"Printing did not complete.", nil);
125
101
  }
126
102
  };
127
-
103
+
128
104
  if (printer != nil) {
129
105
  [printInteractionController printToPrinter:printer completionHandler:completionHandler];
130
106
  } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad
@@ -140,9 +116,9 @@ EX_EXPORT_METHOD_AS(selectPrinter,selectPrinter:(EXPromiseResolveBlock)resolve
140
116
  rejecter:(EXPromiseRejectBlock)reject)
141
117
  {
142
118
  UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
143
-
119
+
144
120
  printPicker.delegate = self;
145
-
121
+
146
122
  void (^completionHandler)(UIPrinterPickerController *, BOOL, NSError *) = ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error) {
147
123
  if (!userDidSelect && error) {
148
124
  reject(@"E_PRINTER_SELECT_ERROR", @"There was a problem with the printer picker.", error);
@@ -151,7 +127,7 @@ EX_EXPORT_METHOD_AS(selectPrinter,selectPrinter:(EXPromiseResolveBlock)resolve
151
127
  if (userDidSelect) {
152
128
  UIPrinter *pickedPrinter = printerPicker.selectedPrinter;
153
129
  [self->_printers setObject:pickedPrinter forKey:pickedPrinter.URL.absoluteString];
154
-
130
+
155
131
  resolve(@{
156
132
  @"name" : pickedPrinter.displayName,
157
133
  @"url" : pickedPrinter.URL.absoluteString,
@@ -161,7 +137,7 @@ EX_EXPORT_METHOD_AS(selectPrinter,selectPrinter:(EXPromiseResolveBlock)resolve
161
137
  }
162
138
  }
163
139
  };
164
-
140
+
165
141
  if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad
166
142
  UIView *view = [[UIApplication sharedApplication] keyWindow].rootViewController.view;
167
143
  [printPicker presentFromRect:view.frame inView:view animated:YES completionHandler:completionHandler];
@@ -179,7 +155,7 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
179
155
  NSString *htmlString = options[@"html"] ?: @"";
180
156
  CGSize paperSize = [self _paperSizeFromOptions:options];
181
157
  UIEdgeInsets pageMargins = [self _pageMarginsFromOptions:options];
182
-
158
+
183
159
  void (^completionHandler)(NSError * _Nullable, NSData * _Nullable, int) =
184
160
  ^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
185
161
  renderTask = nil;
@@ -212,14 +188,14 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
212
188
  };
213
189
 
214
190
  NSString *format = options[@"format"];
215
-
191
+
216
192
  if (format != nil && ![format isEqualToString:@"pdf"]) {
217
193
  reject(@"E_PRINT_UNSUPPORTED_FORMAT", [NSString stringWithFormat:@"Given format '%@' is not supported.", format], nil);
218
194
  return;
219
195
  }
220
196
 
221
197
  if ([options[@"useMarkupFormatter"] boolValue]) {
222
- [self pdfWithHtmlMarkupFormatter:htmlString pageSize:paperSize completionHandler:completionHandler];
198
+ [self pdfWithHtmlMarkupFormatter:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:completionHandler];
223
199
  } else {
224
200
  renderTask = [EXWKPDFRenderer new];
225
201
  [renderTask PDFWithHtml:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:completionHandler];
@@ -247,11 +223,11 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
247
223
  - (NSData *)_dataFromUri:(NSString *)uri
248
224
  {
249
225
  NSURL *candidateURL = [NSURL URLWithString:uri];
250
-
226
+
251
227
  // iCloud url looks like: `file:///private/var/mobile/Containers/Data/Application/[...].pdf`
252
228
  // data url looks like: `data:application/pdf;base64,JVBERi0x...`
253
229
  BOOL isValidURL = (candidateURL && candidateURL.scheme);
254
-
230
+
255
231
  if (isValidURL) {
256
232
  // TODO: This needs updated to use NSURLSession dataTaskWithURL:completionHandler:
257
233
  return [NSData dataWithContentsOfURL:candidateURL];
@@ -264,14 +240,14 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
264
240
  NSString *uri = options[@"uri"];
265
241
  UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController];
266
242
  printInteractionController.delegate = self;
267
-
243
+
268
244
  UIPrintInfo *printInfo = [UIPrintInfo printInfo];
269
-
245
+
270
246
  printInfo.outputType = UIPrintInfoOutputGeneral;
271
247
  printInfo.jobName = [uri lastPathComponent];
272
248
  printInfo.duplex = UIPrintInfoDuplexLongEdge;
273
249
  printInfo.orientation = [self _getPrintOrientationFromOption:options[@"orientation"]];
274
-
250
+
275
251
  printInteractionController.printInfo = printInfo;
276
252
  #pragma clang diagnostic push
277
253
  #pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -280,18 +256,18 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
280
256
  #pragma clang diagnostic pop
281
257
  printInteractionController.showsNumberOfCopies = YES;
282
258
  printInteractionController.showsPaperSelectionForLoadedPapers = YES;
283
-
259
+
284
260
  return printInteractionController;
285
261
  }
286
262
 
287
263
  - (void)_getPrintingDataForOptions:(nonnull NSDictionary *)options callback:(void(^)(NSData *, NSDictionary *))callback
288
264
  {
289
265
  NSData *printData;
290
-
266
+
291
267
  if (options[@"uri"]) {
292
268
  NSString *uri = options[@"uri"];
293
269
  printData = [self _dataFromUri:uri];
294
-
270
+
295
271
  if (printData != nil) {
296
272
  callback(printData, nil);
297
273
  } else {
@@ -303,12 +279,13 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
303
279
  return;
304
280
  }
305
281
 
282
+ NSString *htmlString = options[@"html"] ?: @"";
283
+ CGSize paperSize = [self _paperSizeFromOptions:options];
284
+ UIEdgeInsets pageMargins = [self _pageMarginsFromOptions:options];
285
+
306
286
  if (options[@"html"] && ![options[@"useMarkupFormatter"] boolValue]) {
307
287
  __block EXWKPDFRenderer *renderTask = [EXWKPDFRenderer new];
308
288
 
309
- NSString *htmlString = options[@"html"] ?: @"";
310
- CGSize paperSize = [self _paperSizeFromOptions:options];
311
- UIEdgeInsets pageMargins = [self _pageMarginsFromOptions:options];
312
289
  [renderTask PDFWithHtml:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
313
290
  if (pdfData != nil) {
314
291
  callback(pdfData, nil);
@@ -320,10 +297,30 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
320
297
  }
321
298
  renderTask = nil;
322
299
  }];
323
- return;
300
+ } else {
301
+ if ([options[@"useMarkupFormatter"] boolValue]) {
302
+ htmlString = options[@"html"];
303
+ // check deprecated implementation
304
+ } else if (options[@"markupFormatterIOS"] && [options[@"markupFormatterIOS"] isKindOfClass:[NSString class]]) {
305
+ htmlString = options[@"markupFormatterIOS"];
306
+ } else {
307
+ callback(nil, @{
308
+ @"code": @"E_NOTHING_TO_PRINT",
309
+ @"message": @"No data to print. You must specify `uri` or `html` option.",
310
+ });
311
+ return;
312
+ }
313
+ [self pdfWithHtmlMarkupFormatter:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
314
+ if (pdfData != nil) {
315
+ callback(pdfData, nil);
316
+ } else {
317
+ callback(nil, @{
318
+ @"code": @"E_PRINT_PDF_NOT_RENDERED",
319
+ @"message": @"Error occurred while printing HTML to PDF format.",
320
+ });
321
+ }
322
+ }];
324
323
  }
325
-
326
- callback(nil, nil);
327
324
  }
328
325
 
329
326
  - (UIPrintInfoOrientation)_getPrintOrientationFromOption:(NSString *)orientation
@@ -383,24 +380,25 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
383
380
  NSString *directory = [fileSystem.cachesDirectory stringByAppendingPathComponent:@"Print"];
384
381
  NSString *fileName = [[[NSUUID UUID] UUIDString] stringByAppendingString:@".pdf"];
385
382
  [fileSystem ensureDirExistsWithPath:directory];
386
-
383
+
387
384
  return [directory stringByAppendingPathComponent:fileName];
388
385
  }
389
386
 
390
- - (void)pdfWithHtmlMarkupFormatter:(NSString *)html pageSize:(CGSize)pageSize completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))onFinished
387
+ - (void)pdfWithHtmlMarkupFormatter:(NSString *)html pageSize:(CGSize)pageSize pageMargins:(UIEdgeInsets)pageMargins completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))onFinished
391
388
  {
392
389
  UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:html];
393
390
  UIPrintPageRenderer *renderer = [[UIPrintPageRenderer alloc] init];
394
391
  [renderer addPrintFormatter:formatter startingAtPageAtIndex:0];
395
-
396
- CGRect frame = CGRectMake(0, 0, pageSize.width, pageSize.height);
397
- [renderer setValue:[NSValue valueWithCGRect:frame] forKey:@"paperRect"];
398
- [renderer setValue:[NSValue valueWithCGRect:frame] forKey:@"printableRect"];
392
+
393
+ CGRect paperRect = CGRectMake(0, 0, pageSize.width, pageSize.height);
394
+ [renderer setValue:[NSValue valueWithCGRect:paperRect] forKey:@"paperRect"];
395
+ CGRect printableRect = CGRectMake(pageMargins.left, pageMargins.top, paperRect.size.width - pageMargins.left - pageMargins.right, paperRect.size.height - pageMargins.top - pageMargins.bottom);
396
+ [renderer setValue:[NSValue valueWithCGRect:printableRect] forKey:@"printableRect"];
399
397
 
400
398
  NSMutableData* data = [[NSMutableData alloc] init];
401
399
  UIGraphicsBeginPDFContextToData(data, CGRectZero, NULL);
402
400
  for (int i = 0; i < renderer.numberOfPages; i++) {
403
- UIGraphicsBeginPDFPage();
401
+ UIGraphicsBeginPDFPageWithInfo(paperRect, nil);
404
402
  [renderer drawPageAtIndex:i inRect: UIGraphicsGetPDFContextBounds()];
405
403
  }
406
404
  UIGraphicsEndPDFContext();
@@ -31,6 +31,8 @@
31
31
  [renderer addPrintFormatter:webView.viewPrintFormatter startingAtPageAtIndex:0];
32
32
 
33
33
  CGRect paperRect = CGRectMake(0, 0, self.pageSize.width, self.pageSize.height);
34
+ // Setting paperRect has no effect on actual page size, but HTML will not render
35
+ // without both paperRect and printableRect.
34
36
  [renderer setValue:[NSValue valueWithCGRect:paperRect] forKey:@"paperRect"];
35
37
  CGRect printableRect = CGRectMake(self.pageMargins.left, self.pageMargins.top, paperRect.size.width - self.pageMargins.left - self.pageMargins.right, paperRect.size.height - self.pageMargins.top - self.pageMargins.bottom);
36
38
  [renderer setValue:[NSValue valueWithCGRect:printableRect] forKey:@"printableRect"];
@@ -39,7 +41,8 @@
39
41
  UIGraphicsBeginPDFContextToData(data, CGRectZero /* paperRect */, nil);
40
42
  [renderer prepareForDrawingPages: NSMakeRange(0, renderer.numberOfPages)];
41
43
  for (int i = 0; i < renderer.numberOfPages; i++) {
42
- UIGraphicsBeginPDFPage();
44
+ // this actually constrains the page to a particular size
45
+ UIGraphicsBeginPDFPageWithInfo(paperRect, nil);
43
46
  [renderer drawPageAtIndex:i inRect: UIGraphicsGetPDFContextBounds()];
44
47
  }
45
48
  UIGraphicsEndPDFContext();
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package['license']
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
- s.platform = :ios, '12.0'
13
+ s.platform = :ios, '13.0'
14
14
  s.source = { git: 'https://github.com/expo/expo.git' }
15
15
  s.static_framework = true
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-print",
3
- "version": "11.3.0",
3
+ "version": "12.1.0",
4
4
  "description": "Provides an API for iOS (AirPrint) and Android printing functionality.",
5
5
  "main": "build/Print.js",
6
6
  "types": "build/Print.d.ts",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {},
37
37
  "devDependencies": {
38
- "expo-module-scripts": "^2.0.0"
38
+ "expo-module-scripts": "^3.0.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "expo": "*"
42
42
  },
43
- "gitHead": "6e131f2da851a47c3a24eb3d6fc971a1a7822086"
43
+ "gitHead": "ec0a9fe233db484e98409bd610cf3a090a212a9a"
44
44
  }