This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo Print iconExpo Print

A library that provides printing functionality for Android and iOS (AirPrint).

Android
iOS
Web
Included in Expo Go

expo-print provides an API for Android and iOS (AirPrint) printing functionality.

Installation

Terminal
- npx expo install expo-print
- yarn expo install expo-print
- pnpm expo install expo-print
- bun expo install expo-print

If you are installing this in an existing React Native app, make sure to install expo in your project.

Usage

Print usage
import { useState } from 'react'; import { View, StyleSheet, Button, Platform, Text } from 'react-native'; import * as Print from 'expo-print'; import { shareAsync } from 'expo-sharing'; const html = ` <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" /> </head> <body style="text-align: center;"> <h1 style="font-size: 50px; font-family: Helvetica Neue; font-weight: normal;"> Hello Expo! </h1> <img src="https://docs.expo.dev/static/images/expo-logo.svg" style="width: 90vw;" /> </body> </html> `; export default function App() { const [selectedPrinter, setSelectedPrinter] = useState(); const print = async () => { // On iOS/android prints the given html. On web prints the HTML from the current page. await Print.printAsync({ html, printerUrl: selectedPrinter?.url, // iOS only }); }; const printToFile = async () => { // On iOS/android prints the given html. On web prints the HTML from the current page. const { uri } = await Print.printToFileAsync({ html }); console.log('File has been saved to:', uri); await shareAsync(uri, { UTI: '.pdf', mimeType: 'application/pdf' }); }; const selectPrinter = async () => { const printer = await Print.selectPrinterAsync(); // iOS only setSelectedPrinter(printer); }; return ( <View style={styles.container}> <Button title="Print" onPress={print} /> <View style={styles.spacer} /> <Button title="Print to PDF file" onPress={printToFile} /> {Platform.OS === 'ios' && ( <> <View style={styles.spacer} /> <Button title="Select printer" onPress={selectPrinter} /> <View style={styles.spacer} /> {selectedPrinter ? ( <Text style={styles.printer}>{`Selected printer: ${selectedPrinter.name}`}</Text> ) : undefined} </> )} </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', backgroundColor: '#ecf0f1', flexDirection: 'column', padding: 8, }, spacer: { height: 8, }, printer: { textAlign: 'center', }, });

API

import * as Print from 'expo-print';

Constants

Print.Orientation

Android
iOS
Web

Type: OrientationType

The orientation of the printed content.

Methods

Print.printAsync(options)

Android
iOS
Web
ParameterTypeDescription
optionsPrintOptions

A map defining what should be printed.


Prints a document or HTML, on web this prints the HTML from the page.

Returns:
Promise<void>

Resolves to an empty Promise if printing started.

Print.printToFileAsync(options)

Android
iOS
Web
ParameterTypeDescription
options(optional)FilePrintOptions

A map of print options.

Default:{}

Prints HTML to PDF file and saves it to app's cache directory. On Web this method opens the print dialog.

Print.selectPrinterAsync()

iOS

Chooses a printer that can be later used in printAsync

Returns:
Promise<Printer>

A promise which fulfils with an object containing name and url of the selected printer.

Interfaces

OrientationType

Android
iOS
Web

The possible values of orientation for the printed content.

PropertyTypeDescription
landscapestring
-
portraitstring
-

Types

FilePrintOptions

Android
iOS
Web
PropertyTypeDescription
base64(optional)boolean

Whether to include base64 encoded string of the file in the returned object.

height(optional)number

Height of the single page in pixels. Defaults to 792 which is a height of US Letter paper format with 72 PPI.

html(optional)string

HTML string to print into PDF file.

margins(optional)PageMargins
Only for: 
iOS

Page margins for the printed document.

textZoom(optional)number
Only for: 
Android

The text zoom of the page in percent. The default is 100.

useMarkupFormatter(optional)boolean
Only for: 
iOS

Alternative to default option that uses UIMarkupTextPrintFormatter instead of WebView, but it doesn't display images.

width(optional)number

Width of the single page in pixels. Defaults to 612 which is a width of US Letter paper format with 72 PPI.

FilePrintResult

Android
iOS
Web
PropertyTypeDescription
base64(optional)string

Base64 encoded string containing the data of the PDF file. Available only if base64 option is truthy. It doesn't include data URI prefix data:application/pdf;base64,.

numberOfPagesnumber

Number of pages that were needed to render given content.

uristring

A URI to the printed PDF file.

PageMargins

Android
iOS
Web
PropertyTypeDescription
bottomnumber
-
leftnumber
-
rightnumber
-
topnumber
-

PaperSize

Android
iOS
Web
PropertyTypeDescription
heightnumber

Paper height in points (1/72 inch).

widthnumber

Paper width in points (1/72 inch).

Printer

Android
iOS
Web
PropertyTypeDescription
namestring

Name of the printer.

urlstring

URL of the printer.

PrintOptions

Android
iOS
Web
PropertyTypeDescription
height(optional)number

Height of the single page in pixels. Defaults to 792 which is a height of US Letter paper format with 72 PPI. Available only with html option.

html(optional)string
Only for: 
Android
iOS

HTML string to print.

margins(optional)PageMargins
Only for: 
iOS

Page margins for the printed document.

markupFormatterIOS(optional)string
iOS
orientation(optional)OrientationType[portrait] | OrientationType[landscape]
Only for: 
iOS

The orientation of the printed content, Print.Orientation.portrait or Print.Orientation.landscape.

preferredPaperSize(optional)PaperSize
Only for: 
Android
iOS

Paper size, in points (1/72 inch), that the print job prefers. For example, { width: 432, height: 288 } selects 4 x 6 inch paper on a printer that reports it. The order of width and height does not matter. The page still scales to fit the selected paper. The user can still select a different paper.

On iOS, the job selects the printer's paper that best fits this size, with UIPrintPaper.bestPaper(forPageSize:withPapersFrom:). In the print dialog, this happens when the user selects a printer. With printerUrl, the job prints on that paper without the dialog. The system selects the paper before the user selects a printer, after the user switches to another printer, or when this option is not set.

On Android, the option selects the standard paper size that best fits this size. That is the paper within one point of this size, such as A4 for { width: 595, height: 842 }, or else the smallest paper that contains this size. If the printer does not have that paper, the print dialog selects the printer's default paper.

printerUrl(optional)string
Only for: 
iOS

URL of the printer to use. Returned from selectPrinterAsync.

uri(optional)string
Only for: 
Android
iOS

URI of a PDF file to print. Remote, local (ex. selected via DocumentPicker) or base64 data URI starting with data:application/pdf;base64,. This only supports PDF, not other types of document (e.g. images).

useMarkupFormatter(optional)boolean
Only for: 
iOS

Alternative to default option that uses UIMarkupTextPrintFormatter instead of WebView, but it doesn't display images.

width(optional)number

Width of the single page in pixels. Defaults to 612 which is a width of US Letter paper format with 72 PPI. Available only with html option.

Local images

On iOS, printing from HTML source doesn't support local asset URLs (due to WKWebView limitations). Instead, images need to be converted to base64 and inlined into the HTML.

Example
import { Asset } from 'expo-asset'; import { useImageManipulator } from 'expo-image-manipulator'; import { printAsync } from 'expo-print'; import { useEffect } from 'react'; const IMAGE = Asset.fromModule(require('@/assets/images/icon.png')); export function ImageManipulatorExample() { const context = useImageManipulator(IMAGE.uri); useEffect(() => { async function generateAndPrint() { try { await IMAGE.downloadAsync(); const manipulatedImage = await context.renderAsync(); const result = await manipulatedImage.saveAsync({ base64: true }); const html = ` <html> <img src="data:image/png;base64,${result.base64}" style="width: 90vw;" /> </html> `; await printAsync({ html }); } catch (error) { console.error('Error:', error); } } generateAndPrint(); }, [context]); return <>{/* Render UI */}</>; }

Page margins

On iOS you can set the page margins using the margins option:

const { uri } = await Print.printToFileAsync({ html: 'This page is printed with margins', margins: { left: 20, top: 50, right: 20, bottom: 100, }, });

If useMarkupFormatter is set to true, setting margins may cause a blank page to appear at the end of your printout. To prevent this, make sure your HTML string is a well-formed document, including <!DOCTYPE html> at the beginning of the string.

On Android, if you're using html option in printAsync or printToFileAsync, the resulting print might contain page margins (it depends on the WebView engine). They are set by @page style block and you can override them in your HTML code:

<style> @page { margin: 20px; } </style>

See @page documentation on MDN for more details.

Paper size

On iOS, the print dialog starts on the printer's default paper, often US Letter or A4, and scales each page to fit it. To start on another paper, such as a 4 x 6 inch card, set preferredPaperSize to the paper size in points (1/72 inch). When the user selects a printer, the dialog selects that printer's paper that best fits the size. The user can still select a different paper. If the user switches to another printer, the dialog no longer uses preferredPaperSize.

Also set width and height to a page with the shape of the paper. Otherwise the HTML renders on a US Letter page, and that page shrinks to fit the paper.

await Print.printAsync({ html, width: 576, height: 384, margins: { top: 0, right: 0, bottom: 0, left: 0 }, preferredPaperSize: { width: 432, height: 288 }, });

Before the user selects a printer, the dialog offers a fixed list of standard papers and keeps its default paper.

With printerUrl, printAsync prints without the dialog. The job then prints on the printer's paper that best fits preferredPaperSize.

On Android, the print dialog also starts on the printer's default paper. With preferredPaperSize, the dialog starts on the standard paper size that best fits this size. That is the paper within one point of this size, or else the smallest paper that contains this size. For example, { width: 595, height: 842 } selects A4. An app cannot read the papers of a printer on Android. If the printer does not have the selected paper, the dialog keeps the printer's default paper.

Reference version