UNPKG

2.23 kBJavaScriptView Raw
1import { UnavailabilityError } from 'expo-modules-core';
2import { Platform } from 'react-native';
3import ExponentPrint from './ExponentPrint';
4// @needsAudit @docsMissing
5/**
6 * The orientation of the printed content.
7 */
8export const Orientation = ExponentPrint.Orientation;
9// @needsAudit
10/**
11 * Prints a document or HTML, on web this prints the HTML from the page.
12 * > Note: On iOS, printing from HTML source doesn't support local asset URLs (due to `WKWebView`
13 * > limitations). As a workaround you can use inlined base64-encoded strings.
14 * > See [this comment](https://github.com/expo/expo/issues/7940#issuecomment-657111033) for more details.
15 * @param options A map defining what should be printed.
16 * @return Resolves to an empty `Promise` if printing started.
17 */
18export async function printAsync(options) {
19 if (Platform.OS === 'web') {
20 return await ExponentPrint.print(options);
21 }
22 if (!options.uri && !options.html && Platform.OS === 'ios' && !options.markupFormatterIOS) {
23 throw new Error('Must provide either `html` or `uri` to print');
24 }
25 if (options.uri && options.html) {
26 throw new Error('Must provide exactly one of `html` and `uri` but both were specified');
27 }
28 if (options.markupFormatterIOS !== undefined) {
29 console.warn('The markupFormatterIOS option is deprecated. Use useMarkupFormatter instead.');
30 }
31 return await ExponentPrint.print(options);
32}
33// @needsAudit
34/**
35 * **Available on iOS only.** Chooses a printer that can be later used in `printAsync`
36 * @return A promise which fulfils with an object containing `name` and `url` of the selected printer.
37 */
38export async function selectPrinterAsync() {
39 if (ExponentPrint.selectPrinter) {
40 return await ExponentPrint.selectPrinter();
41 }
42 throw new UnavailabilityError('Print', 'selectPrinterAsync');
43}
44// @needsAudit
45/**
46 * Prints HTML to PDF file and saves it to [app's cache directory](./filesystem/#filesystemcachedirectory).
47 * On Web this method opens the print dialog.
48 * @param options A map of print options.
49 */
50export async function printToFileAsync(options = {}) {
51 return await ExponentPrint.printToFileAsync(options);
52}
53//# sourceMappingURL=Print.js.map
\No newline at end of file