expo-print 11.0.1 → 11.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,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 11.1.0 — 2021-12-03
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix page-breaks and margins not supported on iOS ([#14383](https://github.com/expo/expo/pull/14802) by [@cruzach](https://github.com/IjzerenHein))
18
+
13
19
  ## 11.0.1 — 2021-10-01
14
20
 
15
21
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '11.0.1'
6
+ version = '11.1.0'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -57,7 +57,7 @@ android {
57
57
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
58
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
59
  versionCode 27
60
- versionName "11.0.1"
60
+ versionName "11.1.0"
61
61
  }
62
62
  lintOptions {
63
63
  abortOnError false
package/build/Print.d.ts CHANGED
@@ -14,8 +14,9 @@ export declare const Orientation: OrientationType;
14
14
  */
15
15
  export declare function printAsync(options: PrintOptions): Promise<void>;
16
16
  /**
17
- * **Available on iOS only.** Chooses a printer that can be later used in `printAsync`
17
+ * Chooses a printer that can be later used in `printAsync`
18
18
  * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.
19
+ * @platform ios
19
20
  */
20
21
  export declare function selectPrinterAsync(): Promise<Printer>;
21
22
  /**
package/build/Print.js CHANGED
@@ -32,8 +32,9 @@ export async function printAsync(options) {
32
32
  }
33
33
  // @needsAudit
34
34
  /**
35
- * **Available on iOS only.** Chooses a printer that can be later used in `printAsync`
35
+ * Chooses a printer that can be later used in `printAsync`
36
36
  * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.
37
+ * @platform ios
37
38
  */
38
39
  export async function selectPrinterAsync() {
39
40
  if (ExponentPrint.selectPrinter) {
@@ -1 +1 @@
1
- {"version":3,"file":"Print.js","sourceRoot":"","sources":["../src/Print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAW5C,2BAA2B;AAC3B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAoB,aAAa,CAAC,WAAW,CAAC;AAEtE,cAAc;AACd;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAqB;IACpD,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC3C;IACD,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE;QACzF,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;KACjE;IACD,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;KACzF;IACD,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;KAC9F;IACD,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,cAAc;AACd;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,aAAa,CAAC,aAAa,EAAE;QAC/B,OAAO,MAAM,aAAa,CAAC,aAAa,EAAE,CAAC;KAC5C;IAED,MAAM,IAAI,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AAC/D,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAA4B,EAAE;IACnE,OAAO,MAAM,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport ExponentPrint from './ExponentPrint';\nimport {\n FilePrintOptions,\n FilePrintResult,\n OrientationType,\n PrintOptions,\n Printer,\n} from './Print.types';\n\nexport { FilePrintOptions, FilePrintResult, OrientationType, PrintOptions, Printer };\n\n// @needsAudit @docsMissing\n/**\n * The orientation of the printed content.\n */\nexport const Orientation: OrientationType = ExponentPrint.Orientation;\n\n// @needsAudit\n/**\n * Prints a document or HTML, on web this prints the HTML from the page.\n * > Note: On iOS, printing from HTML source doesn't support local asset URLs (due to `WKWebView`\n * > limitations). As a workaround you can use inlined base64-encoded strings.\n * > See [this comment](https://github.com/expo/expo/issues/7940#issuecomment-657111033) for more details.\n * @param options A map defining what should be printed.\n * @return Resolves to an empty `Promise` if printing started.\n */\nexport async function printAsync(options: PrintOptions): Promise<void> {\n if (Platform.OS === 'web') {\n return await ExponentPrint.print(options);\n }\n if (!options.uri && !options.html && Platform.OS === 'ios' && !options.markupFormatterIOS) {\n throw new Error('Must provide either `html` or `uri` to print');\n }\n if (options.uri && options.html) {\n throw new Error('Must provide exactly one of `html` and `uri` but both were specified');\n }\n if (options.markupFormatterIOS !== undefined) {\n console.warn('The markupFormatterIOS option is deprecated. Use useMarkupFormatter instead.');\n }\n return await ExponentPrint.print(options);\n}\n\n// @needsAudit\n/**\n * **Available on iOS only.** Chooses a printer that can be later used in `printAsync`\n * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.\n */\nexport async function selectPrinterAsync(): Promise<Printer> {\n if (ExponentPrint.selectPrinter) {\n return await ExponentPrint.selectPrinter();\n }\n\n throw new UnavailabilityError('Print', 'selectPrinterAsync');\n}\n\n// @needsAudit\n/**\n * Prints HTML to PDF file and saves it to [app's cache directory](./filesystem/#filesystemcachedirectory).\n * On Web this method opens the print dialog.\n * @param options A map of print options.\n */\nexport async function printToFileAsync(options: FilePrintOptions = {}): Promise<FilePrintResult> {\n return await ExponentPrint.printToFileAsync(options);\n}\n"]}
1
+ {"version":3,"file":"Print.js","sourceRoot":"","sources":["../src/Print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAW5C,2BAA2B;AAC3B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAoB,aAAa,CAAC,WAAW,CAAC;AAEtE,cAAc;AACd;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAqB;IACpD,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC3C;IACD,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE;QACzF,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;KACjE;IACD,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;KACzF;IACD,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;KAC9F;IACD,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,aAAa,CAAC,aAAa,EAAE;QAC/B,OAAO,MAAM,aAAa,CAAC,aAAa,EAAE,CAAC;KAC5C;IAED,MAAM,IAAI,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AAC/D,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAA4B,EAAE;IACnE,OAAO,MAAM,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport ExponentPrint from './ExponentPrint';\nimport {\n FilePrintOptions,\n FilePrintResult,\n OrientationType,\n PrintOptions,\n Printer,\n} from './Print.types';\n\nexport { FilePrintOptions, FilePrintResult, OrientationType, PrintOptions, Printer };\n\n// @needsAudit @docsMissing\n/**\n * The orientation of the printed content.\n */\nexport const Orientation: OrientationType = ExponentPrint.Orientation;\n\n// @needsAudit\n/**\n * Prints a document or HTML, on web this prints the HTML from the page.\n * > Note: On iOS, printing from HTML source doesn't support local asset URLs (due to `WKWebView`\n * > limitations). As a workaround you can use inlined base64-encoded strings.\n * > See [this comment](https://github.com/expo/expo/issues/7940#issuecomment-657111033) for more details.\n * @param options A map defining what should be printed.\n * @return Resolves to an empty `Promise` if printing started.\n */\nexport async function printAsync(options: PrintOptions): Promise<void> {\n if (Platform.OS === 'web') {\n return await ExponentPrint.print(options);\n }\n if (!options.uri && !options.html && Platform.OS === 'ios' && !options.markupFormatterIOS) {\n throw new Error('Must provide either `html` or `uri` to print');\n }\n if (options.uri && options.html) {\n throw new Error('Must provide exactly one of `html` and `uri` but both were specified');\n }\n if (options.markupFormatterIOS !== undefined) {\n console.warn('The markupFormatterIOS option is deprecated. Use useMarkupFormatter instead.');\n }\n return await ExponentPrint.print(options);\n}\n\n// @needsAudit\n/**\n * Chooses a printer that can be later used in `printAsync`\n * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.\n * @platform ios\n */\nexport async function selectPrinterAsync(): Promise<Printer> {\n if (ExponentPrint.selectPrinter) {\n return await ExponentPrint.selectPrinter();\n }\n\n throw new UnavailabilityError('Print', 'selectPrinterAsync');\n}\n\n// @needsAudit\n/**\n * Prints HTML to PDF file and saves it to [app's cache directory](./filesystem/#filesystemcachedirectory).\n * On Web this method opens the print dialog.\n * @param options A map of print options.\n */\nexport async function printToFileAsync(options: FilePrintOptions = {}): Promise<FilePrintResult> {\n return await ExponentPrint.printToFileAsync(options);\n}\n"]}
@@ -2,11 +2,14 @@ export declare 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
5
- * document (e.g. images). **Available on Android and iOS only.**
5
+ * document (e.g. images).
6
+ * @platform ios
6
7
  */
7
8
  uri?: string;
8
9
  /**
9
- * HTML string to print. **Available on Android and iOS only.**
10
+ * HTML string to print.
11
+ * @platform android
12
+ * @platform ios
10
13
  */
11
14
  html?: string;
12
15
  /**
@@ -20,25 +23,34 @@ export declare type PrintOptions = {
20
23
  */
21
24
  height?: number;
22
25
  /**
23
- * URL of the printer to use. Returned from `selectPrinterAsync`. **Available on iOS only.**
26
+ * URL of the printer to use. Returned from `selectPrinterAsync`.
27
+ * @platform ios
24
28
  */
25
29
  printerUrl?: string;
26
30
  /**
27
- * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
31
+ * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
28
32
  * instead of WebView, but it doesn't display images.
33
+ * @platform ios
29
34
  */
30
35
  useMarkupFormatter?: boolean;
31
36
  /**
32
37
  * @deprecated
33
- * **Available on iOS only.** This argument is deprecated, use `useMarkupFormatter` instead.
38
+ * This argument is deprecated, use `useMarkupFormatter` instead.
34
39
  * Might be removed in the future releases.
40
+ * @platform ios
35
41
  */
36
42
  markupFormatterIOS?: string;
37
43
  /**
38
- * **Available on iOS only.** The orientation of the printed content, `Print.Orientation.portrait`
44
+ * The orientation of the printed content, `Print.Orientation.portrait`
39
45
  * or `Print.Orientation.landscape`.
46
+ * @platform ios
40
47
  */
41
48
  orientation?: OrientationType['portrait'] | OrientationType['landscape'];
49
+ /**
50
+ * Page margins for the printed document.
51
+ * @platform ios
52
+ */
53
+ margins?: PageMargins;
42
54
  };
43
55
  export declare type Printer = {
44
56
  /**
@@ -57,14 +69,21 @@ export interface OrientationType {
57
69
  portrait: string;
58
70
  landscape: string;
59
71
  }
72
+ export declare type PageMargins = {
73
+ top: number;
74
+ right: number;
75
+ bottom: number;
76
+ left: number;
77
+ };
60
78
  export declare type FilePrintOptions = {
61
79
  /**
62
80
  * HTML string to print into PDF file.
63
81
  */
64
82
  html?: string;
65
83
  /**
66
- * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
84
+ * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
67
85
  * instead of WebView, but it doesn't display images.
86
+ * @platform ios
68
87
  */
69
88
  useMarkupFormatter?: boolean;
70
89
  /**
@@ -78,20 +97,15 @@ export declare type FilePrintOptions = {
78
97
  */
79
98
  height?: number;
80
99
  /**
81
- * Padding for the printed document.
100
+ * Page margins for the printed document.
101
+ * @platform ios
82
102
  */
83
- padding?: FilePrintPadding;
103
+ margins?: PageMargins;
84
104
  /**
85
105
  * Whether to include base64 encoded string of the file in the returned object.
86
106
  */
87
107
  base64?: boolean;
88
108
  };
89
- export declare type FilePrintPadding = {
90
- top: number;
91
- right: number;
92
- bottom: number;
93
- left: number;
94
- };
95
109
  export declare type FilePrintResult = {
96
110
  /**
97
111
  * A URI to the printed PDF file.
@@ -1 +1 @@
1
- {"version":3,"file":"Print.types.js","sourceRoot":"","sources":["../src/Print.types.ts"],"names":[],"mappings":"","sourcesContent":["// @needsAudit\nexport type PrintOptions = {\n /**\n * URI of a PDF file to print. Remote, local (ex. selected via `DocumentPicker`) or base64 data URI\n * starting with `data:application/pdf;base64,`. This only supports PDF, not other types of\n * document (e.g. images). **Available on Android and iOS only.**\n */\n uri?: string;\n /**\n * HTML string to print. **Available on Android and iOS only.**\n */\n html?: string;\n /**\n * Width of the single page in pixels. Defaults to `612` which is a width of US Letter paper\n * format with 72 PPI. **Available only with `html` option.**\n */\n width?: number;\n /**\n * Height of the single page in pixels. Defaults to `792` which is a height of US Letter paper\n * format with 72 PPI. **Available only with `html` option.**\n */\n height?: number;\n /**\n * URL of the printer to use. Returned from `selectPrinterAsync`. **Available on iOS only.**\n */\n printerUrl?: string;\n /**\n * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)\n * instead of WebView, but it doesn't display images.\n */\n useMarkupFormatter?: boolean;\n /**\n * @deprecated\n * **Available on iOS only.** This argument is deprecated, use `useMarkupFormatter` instead.\n * Might be removed in the future releases.\n */\n markupFormatterIOS?: string;\n /**\n * **Available on iOS only.** The orientation of the printed content, `Print.Orientation.portrait`\n * or `Print.Orientation.landscape`.\n */\n orientation?: OrientationType['portrait'] | OrientationType['landscape'];\n};\n\n// @needsAudit\nexport type Printer = {\n /**\n * Name of the printer.\n */\n name: string;\n /**\n * URL of the printer.\n */\n url: string;\n};\n\n// @needsAudit\n/**\n * The possible values of orientation for the printed content.\n */\nexport interface OrientationType {\n portrait: string;\n landscape: string;\n}\n\n// @docsMissing\nexport type FilePrintOptions = {\n /**\n * HTML string to print into PDF file.\n */\n html?: string;\n /**\n * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)\n * instead of WebView, but it doesn't display images.\n */\n useMarkupFormatter?: boolean;\n /**\n * Width of the single page in pixels. Defaults to `612` which is a width of US Letter paper\n * format with 72 PPI.\n */\n width?: number;\n /**\n * Height of the single page in pixels. Defaults to `792` which is a height of US Letter paper\n * format with 72 PPI.\n */\n height?: number;\n /**\n * Padding for the printed document.\n */\n padding?: FilePrintPadding;\n /**\n * Whether to include base64 encoded string of the file in the returned object.\n */\n base64?: boolean;\n};\n\n// @needsAudit\nexport type FilePrintPadding = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n// @needsAudit\nexport type FilePrintResult = {\n /**\n * A URI to the printed PDF file.\n */\n uri: string;\n /**\n * Number of pages that were needed to render given content.\n */\n numberOfPages: number;\n /**\n * Base64 encoded string containing the data of the PDF file. **Available only if `base64`\n * option is truthy**. It doesn't include data URI prefix `data:application/pdf;base64,`.\n */\n base64?: string;\n};\n"]}
1
+ {"version":3,"file":"Print.types.js","sourceRoot":"","sources":["../src/Print.types.ts"],"names":[],"mappings":"","sourcesContent":["// @needsAudit\nexport type PrintOptions = {\n /**\n * URI of a PDF file to print. Remote, local (ex. selected via `DocumentPicker`) or base64 data URI\n * starting with `data:application/pdf;base64,`. This only supports PDF, not other types of\n * document (e.g. images).\n * @platform ios\n */\n uri?: string;\n /**\n * HTML string to print.\n * @platform android\n * @platform ios\n */\n html?: string;\n /**\n * Width of the single page in pixels. Defaults to `612` which is a width of US Letter paper\n * format with 72 PPI. **Available only with `html` option.**\n */\n width?: number;\n /**\n * Height of the single page in pixels. Defaults to `792` which is a height of US Letter paper\n * format with 72 PPI. **Available only with `html` option.**\n */\n height?: number;\n /**\n * URL of the printer to use. Returned from `selectPrinterAsync`.\n * @platform ios\n */\n printerUrl?: string;\n /**\n * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)\n * instead of WebView, but it doesn't display images.\n * @platform ios\n */\n useMarkupFormatter?: boolean;\n /**\n * @deprecated\n * This argument is deprecated, use `useMarkupFormatter` instead.\n * Might be removed in the future releases.\n * @platform ios\n */\n markupFormatterIOS?: string;\n /**\n * The orientation of the printed content, `Print.Orientation.portrait`\n * or `Print.Orientation.landscape`.\n * @platform ios\n */\n orientation?: OrientationType['portrait'] | OrientationType['landscape'];\n /**\n * Page margins for the printed document.\n * @platform ios\n */\n margins?: PageMargins;\n};\n\n// @needsAudit\nexport type Printer = {\n /**\n * Name of the printer.\n */\n name: string;\n /**\n * URL of the printer.\n */\n url: string;\n};\n\n// @needsAudit\n/**\n * The possible values of orientation for the printed content.\n */\nexport interface OrientationType {\n portrait: string;\n landscape: string;\n}\n\n// @needsAudit\nexport type PageMargins = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n// @docsMissing\nexport type FilePrintOptions = {\n /**\n * HTML string to print into PDF file.\n */\n html?: string;\n /**\n * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)\n * instead of WebView, but it doesn't display images.\n * @platform ios\n */\n useMarkupFormatter?: boolean;\n /**\n * Width of the single page in pixels. Defaults to `612` which is a width of US Letter paper\n * format with 72 PPI.\n */\n width?: number;\n /**\n * Height of the single page in pixels. Defaults to `792` which is a height of US Letter paper\n * format with 72 PPI.\n */\n height?: number;\n /**\n * Page margins for the printed document.\n * @platform ios\n */\n margins?: PageMargins;\n /**\n * Whether to include base64 encoded string of the file in the returned object.\n */\n base64?: boolean;\n};\n\n// @needsAudit\nexport type FilePrintResult = {\n /**\n * A URI to the printed PDF file.\n */\n uri: string;\n /**\n * Number of pages that were needed to render given content.\n */\n numberOfPages: number;\n /**\n * Base64 encoded string containing the data of the PDF file. **Available only if `base64`\n * option is truthy**. It doesn't include data URI prefix `data:application/pdf;base64,`.\n */\n base64?: string;\n};\n"]}
@@ -178,6 +178,7 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
178
178
  __block EXWKPDFRenderer *renderTask;
179
179
  NSString *htmlString = options[@"html"] ?: @"";
180
180
  CGSize paperSize = [self _paperSizeFromOptions:options];
181
+ UIEdgeInsets pageMargins = [self _pageMarginsFromOptions:options];
181
182
 
182
183
  void (^completionHandler)(NSError * _Nullable, NSData * _Nullable, int) =
183
184
  ^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
@@ -221,7 +222,7 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
221
222
  [self pdfWithHtmlMarkupFormatter:htmlString pageSize:paperSize completionHandler:completionHandler];
222
223
  } else {
223
224
  renderTask = [EXWKPDFRenderer new];
224
- [renderTask PDFWithHtml:htmlString pageSize:paperSize completionHandler:completionHandler];
225
+ [renderTask PDFWithHtml:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:completionHandler];
225
226
  }
226
227
  }
227
228
 
@@ -307,7 +308,8 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
307
308
 
308
309
  NSString *htmlString = options[@"html"] ?: @"";
309
310
  CGSize paperSize = [self _paperSizeFromOptions:options];
310
- [renderTask PDFWithHtml:htmlString pageSize:paperSize completionHandler:^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
311
+ UIEdgeInsets pageMargins = [self _pageMarginsFromOptions:options];
312
+ [renderTask PDFWithHtml:htmlString pageSize:paperSize pageMargins:pageMargins completionHandler:^(NSError * _Nullable error, NSData * _Nullable pdfData, int pagesCount) {
311
313
  if (pdfData != nil) {
312
314
  callback(pdfData, nil);
313
315
  } else {
@@ -357,6 +359,21 @@ EX_EXPORT_METHOD_AS(printToFileAsync,
357
359
  return paperSize;
358
360
  }
359
361
 
362
+ - (UIEdgeInsets)_pageMarginsFromOptions:(NSDictionary *)options
363
+ {
364
+ UIEdgeInsets pageMargins = UIEdgeInsetsZero;
365
+
366
+ if (options[@"margins"]) {
367
+ NSDictionary* margins = options[@"margins"];
368
+ pageMargins.left = [margins[@"left"] floatValue];
369
+ pageMargins.top = [margins[@"top"] floatValue];
370
+ pageMargins.bottom = [margins[@"bottom"] floatValue];
371
+ pageMargins.right = [margins[@"right"] floatValue];
372
+ }
373
+
374
+ return pageMargins;
375
+ }
376
+
360
377
  - (NSString *)_generatePath
361
378
  {
362
379
  id<EXFileSystemInterface> fileSystem = [_moduleRegistry getModuleImplementingProtocol:@protocol(EXFileSystemInterface)];
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
13
13
 
14
14
  @interface EXWKPDFRenderer : NSObject
15
15
 
16
- - (void)PDFWithHtml:(NSString *)htmlString pageSize:(CGSize)pageSize completionHandler:(void(^_Nullable)(NSError * _Nullable, NSData * _Nullable, int))handler;
16
+ - (void)PDFWithHtml:(NSString *)htmlString pageSize:(CGSize)pageSize pageMargins:(UIEdgeInsets)pageMargins completionHandler:(void(^_Nullable)(NSError * _Nullable, NSData * _Nullable, int))handler;
17
17
 
18
18
  @end
19
19
 
@@ -2,11 +2,12 @@
2
2
 
3
3
  #import <EXPrint/EXWKPDFRenderer.h>
4
4
  #import <ExpoModulesCore/EXDefines.h>
5
- #import <EXPrint/EXWKSnapshotPDFRenderer.h>
5
+ #import <EXPrint/EXWKViewPrintPDFRenderer.h>
6
6
 
7
7
  @interface EXWKPDFRenderer () <WKNavigationDelegate>
8
8
 
9
9
  @property (nonatomic, assign) CGSize pageSize;
10
+ @property (nonatomic, assign) UIEdgeInsets pageMargins;
10
11
  @property (nonatomic, strong) WKWebView *webView;
11
12
  @property (nonatomic, strong) id<EXPDFRenderer> renderer;
12
13
  @property (nonatomic, strong) WKNavigation *htmlNavigation;
@@ -16,13 +17,14 @@
16
17
 
17
18
  @implementation EXWKPDFRenderer
18
19
 
19
- - (void)PDFWithHtml:(NSString *)htmlString pageSize:(CGSize)pageSize completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))handler
20
+ - (void)PDFWithHtml:(NSString *)htmlString pageSize:(CGSize)pageSize pageMargins:(UIEdgeInsets)pageMargins completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))handler
20
21
  {
21
22
  _pageSize = pageSize;
23
+ _pageMargins = pageMargins;
22
24
  _onRenderingFinished = handler;
23
25
  _webView = [self createWebView];
24
- _renderer = [[EXWKSnapshotPDFRenderer alloc] init];
25
- _htmlNavigation = [_webView loadHTMLString:htmlString baseURL:nil];
26
+ _renderer = [[EXWKViewPrintPDFRenderer alloc] initWithPageSize:pageSize pageMargins:pageMargins];
27
+ _htmlNavigation = [_webView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] resourceURL]];
26
28
  }
27
29
 
28
30
  #pragma mark - UIWebViewDelegate
@@ -1,4 +1,4 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <Foundation/Foundation.h>
4
4
  #import <WebKit/WebKit.h>
@@ -6,9 +6,11 @@
6
6
 
7
7
  NS_ASSUME_NONNULL_BEGIN
8
8
 
9
- @interface EXWKSnapshotPDFRenderer : NSObject <EXPDFRenderer>
9
+ @interface EXWKViewPrintPDFRenderer : NSObject <EXPDFRenderer>
10
10
 
11
- - (void)PDFFromWebView:(WKWebView *)webView completionHandler:(void(^_Nullable)(NSError * _Nullable, NSData * _Nullable, int))handler;
11
+ - (instancetype)initWithPageSize:(CGSize)pageSize pageMargins:(UIEdgeInsets)pageMargins;
12
+
13
+ - (void)PDFFromWebView:(WKWebView *)webView completionHandler:(void(^_Nullable)(NSError * _Nullable, NSData * _Nullable, int))handler API_AVAILABLE(ios(8.0));
12
14
 
13
15
  @end
14
16
 
@@ -0,0 +1,51 @@
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
+
3
+ #import <EXPrint/EXWKViewPrintPDFRenderer.h>
4
+ #import <ExpoModulesCore/EXDefines.h>
5
+
6
+ @interface EXWKViewPrintPDFRenderer ()
7
+
8
+ @property (nonatomic, assign) CGSize pageSize;
9
+ @property (nonatomic, assign) UIEdgeInsets pageMargins;
10
+
11
+ @end
12
+
13
+ @implementation EXWKViewPrintPDFRenderer
14
+
15
+ - (instancetype)initWithPageSize:(CGSize)pageSize pageMargins:(UIEdgeInsets)pageMargins
16
+ {
17
+ if (self = [super init]) {
18
+ _pageSize = pageSize;
19
+ _pageMargins = pageMargins;
20
+ }
21
+ return self;
22
+ }
23
+
24
+ - (void)PDFFromWebView:(WKWebView *)webView completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))handler
25
+ {
26
+ EX_WEAKIFY(self);
27
+ [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id jsValue, NSError * _Nullable error) {
28
+ EX_ENSURE_STRONGIFY(self);
29
+
30
+ UIPrintPageRenderer *renderer = [[UIPrintPageRenderer alloc] init];
31
+ [renderer addPrintFormatter:webView.viewPrintFormatter startingAtPageAtIndex:0];
32
+
33
+ CGRect paperRect = CGRectMake(0, 0, self.pageSize.width, self.pageSize.height);
34
+ [renderer setValue:[NSValue valueWithCGRect:paperRect] forKey:@"paperRect"];
35
+ 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
+ [renderer setValue:[NSValue valueWithCGRect:printableRect] forKey:@"printableRect"];
37
+
38
+ NSMutableData* data = [[NSMutableData alloc] init];
39
+ UIGraphicsBeginPDFContextToData(data, CGRectZero /* paperRect */, nil);
40
+ [renderer prepareForDrawingPages: NSMakeRange(0, renderer.numberOfPages)];
41
+ for (int i = 0; i < renderer.numberOfPages; i++) {
42
+ UIGraphicsBeginPDFPage();
43
+ [renderer drawPageAtIndex:i inRect: UIGraphicsGetPDFContextBounds()];
44
+ }
45
+ UIGraphicsEndPDFContext();
46
+
47
+ handler(nil, data, (int)renderer.numberOfPages);
48
+ }];
49
+ }
50
+
51
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-print",
3
- "version": "11.0.1",
3
+ "version": "11.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",
@@ -31,13 +31,14 @@
31
31
  "license": "MIT",
32
32
  "homepage": "https://docs.expo.dev/versions/latest/sdk/print/",
33
33
  "jest": {
34
- "preset": "expo-module-scripts/ios"
35
- },
36
- "dependencies": {
37
- "expo-modules-core": "~0.4.2"
34
+ "preset": "expo-module-scripts"
38
35
  },
36
+ "dependencies": {},
39
37
  "devDependencies": {
40
38
  "expo-module-scripts": "^2.0.0"
41
39
  },
42
- "gitHead": "2718b696f4a6919905b0f47ebb24ff65b42d8ff9"
40
+ "peerDependencies": {
41
+ "expo": "*"
42
+ },
43
+ "gitHead": "2e5c6983b86d5ecfca028ba64002897d8adc2cc4"
43
44
  }
package/src/Print.ts CHANGED
@@ -45,8 +45,9 @@ export async function printAsync(options: PrintOptions): Promise<void> {
45
45
 
46
46
  // @needsAudit
47
47
  /**
48
- * **Available on iOS only.** Chooses a printer that can be later used in `printAsync`
48
+ * Chooses a printer that can be later used in `printAsync`
49
49
  * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.
50
+ * @platform ios
50
51
  */
51
52
  export async function selectPrinterAsync(): Promise<Printer> {
52
53
  if (ExponentPrint.selectPrinter) {
@@ -3,11 +3,14 @@ export type PrintOptions = {
3
3
  /**
4
4
  * URI of a PDF file to print. Remote, local (ex. selected via `DocumentPicker`) or base64 data URI
5
5
  * starting with `data:application/pdf;base64,`. This only supports PDF, not other types of
6
- * document (e.g. images). **Available on Android and iOS only.**
6
+ * document (e.g. images).
7
+ * @platform ios
7
8
  */
8
9
  uri?: string;
9
10
  /**
10
- * HTML string to print. **Available on Android and iOS only.**
11
+ * HTML string to print.
12
+ * @platform android
13
+ * @platform ios
11
14
  */
12
15
  html?: string;
13
16
  /**
@@ -21,25 +24,34 @@ export type PrintOptions = {
21
24
  */
22
25
  height?: number;
23
26
  /**
24
- * URL of the printer to use. Returned from `selectPrinterAsync`. **Available on iOS only.**
27
+ * URL of the printer to use. Returned from `selectPrinterAsync`.
28
+ * @platform ios
25
29
  */
26
30
  printerUrl?: string;
27
31
  /**
28
- * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
32
+ * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
29
33
  * instead of WebView, but it doesn't display images.
34
+ * @platform ios
30
35
  */
31
36
  useMarkupFormatter?: boolean;
32
37
  /**
33
38
  * @deprecated
34
- * **Available on iOS only.** This argument is deprecated, use `useMarkupFormatter` instead.
39
+ * This argument is deprecated, use `useMarkupFormatter` instead.
35
40
  * Might be removed in the future releases.
41
+ * @platform ios
36
42
  */
37
43
  markupFormatterIOS?: string;
38
44
  /**
39
- * **Available on iOS only.** The orientation of the printed content, `Print.Orientation.portrait`
45
+ * The orientation of the printed content, `Print.Orientation.portrait`
40
46
  * or `Print.Orientation.landscape`.
47
+ * @platform ios
41
48
  */
42
49
  orientation?: OrientationType['portrait'] | OrientationType['landscape'];
50
+ /**
51
+ * Page margins for the printed document.
52
+ * @platform ios
53
+ */
54
+ margins?: PageMargins;
43
55
  };
44
56
 
45
57
  // @needsAudit
@@ -63,6 +75,14 @@ export interface OrientationType {
63
75
  landscape: string;
64
76
  }
65
77
 
78
+ // @needsAudit
79
+ export type PageMargins = {
80
+ top: number;
81
+ right: number;
82
+ bottom: number;
83
+ left: number;
84
+ };
85
+
66
86
  // @docsMissing
67
87
  export type FilePrintOptions = {
68
88
  /**
@@ -70,8 +90,9 @@ export type FilePrintOptions = {
70
90
  */
71
91
  html?: string;
72
92
  /**
73
- * **Available on iOS only.** Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
93
+ * Alternative to default option that uses [UIMarkupTextPrintFormatter](https://developer.apple.com/documentation/uikit/uimarkuptextprintformatter)
74
94
  * instead of WebView, but it doesn't display images.
95
+ * @platform ios
75
96
  */
76
97
  useMarkupFormatter?: boolean;
77
98
  /**
@@ -85,23 +106,16 @@ export type FilePrintOptions = {
85
106
  */
86
107
  height?: number;
87
108
  /**
88
- * Padding for the printed document.
109
+ * Page margins for the printed document.
110
+ * @platform ios
89
111
  */
90
- padding?: FilePrintPadding;
112
+ margins?: PageMargins;
91
113
  /**
92
114
  * Whether to include base64 encoded string of the file in the returned object.
93
115
  */
94
116
  base64?: boolean;
95
117
  };
96
118
 
97
- // @needsAudit
98
- export type FilePrintPadding = {
99
- top: number;
100
- right: number;
101
- bottom: number;
102
- left: number;
103
- };
104
-
105
119
  // @needsAudit
106
120
  export type FilePrintResult = {
107
121
  /**
@@ -1,61 +0,0 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
2
-
3
- #import <EXPrint/EXWKSnapshotPDFRenderer.h>
4
- #import <ExpoModulesCore/EXDefines.h>
5
-
6
- @interface EXWKSnapshotPDFRenderer ()
7
-
8
- @end
9
-
10
- @implementation EXWKSnapshotPDFRenderer
11
-
12
- - (void)PDFFromWebView:(WKWebView *)webView completionHandler:(void (^)(NSError * _Nullable, NSData * _Nullable, int))handler
13
- {
14
- EX_WEAKIFY(self);
15
- [webView evaluateJavaScript:@"window.innerHeight + ' ' + document.documentElement.scrollHeight" completionHandler:^(id jsResult, NSError * _Nullable error) {
16
- EX_ENSURE_STRONGIFY(self);
17
- NSString *jsResultString = jsResult;
18
- NSArray *items = [jsResultString componentsSeparatedByString:@" "];
19
- CGFloat pageHeight = [items[0] doubleValue];
20
- CGFloat scrollHeight = [items[1] doubleValue];
21
- int numberOfPages = ceil(scrollHeight / pageHeight);
22
-
23
- // Ensure all content is loaded by scrolling to the end of webpage
24
- [webView.scrollView setContentOffset:CGPointMake(0, scrollHeight - pageHeight) animated:NO];
25
-
26
- NSMutableData *pdfData = [NSMutableData data];
27
- UIGraphicsBeginPDFContextToData(pdfData, webView.bounds, nil);
28
- [self takeSnapshotForPage:0 ofPages:numberOfPages ofWebView:webView withCompletionHandler:^(NSError * _Nullable error) {
29
- UIGraphicsEndPDFContext();
30
- if (error) {
31
- handler(error, nil, 0);
32
- } else {
33
- handler(nil, pdfData, numberOfPages);
34
- }
35
- }];
36
- }];
37
- }
38
-
39
- - (void)takeSnapshotForPage:(int)pageIndex ofPages:(int)pagesCount ofWebView:(WKWebView *)webView withCompletionHandler:(void (^ _Nullable)(NSError * _Nullable error))completionHandler
40
- {
41
- if (pageIndex >= pagesCount) {
42
- completionHandler(nil);
43
- return;
44
- }
45
-
46
- CGFloat pageHeight = webView.bounds.size.height;
47
-
48
- [webView.scrollView setContentOffset:CGPointMake(0, pageHeight * pageIndex) animated:NO];
49
- [webView takeSnapshotWithConfiguration:nil completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) {
50
- if (snapshotImage) {
51
- CGRect printRect = UIGraphicsGetPDFContextBounds();
52
- UIGraphicsBeginPDFPage();
53
- [snapshotImage drawInRect:printRect];
54
- [self takeSnapshotForPage:(pageIndex + 1) ofPages:pagesCount ofWebView:webView withCompletionHandler:completionHandler];
55
- } else {
56
- completionHandler(error);
57
- }
58
- }];
59
- }
60
-
61
- @end