This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 58).
Expo Print
A library that provides printing functionality for Android and iOS (AirPrint).
expo-print provides an API for Android and iOS (AirPrint) printing functionality.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
API
import * as Print from 'expo-print';
Constants
Methods
Prints a document or HTML, on web this prints the HTML from the page.
Note: On iOS, printing from HTML source doesn't support local asset URLs (due to
WKWebViewlimitations). As a workaround you can use inlined base64-encoded strings. See this comment for more details.
Note: on iOS, when printing without providing a
PrintOptions.printerUrlthePromisewill be resolved once printing is started in the native print window and rejected if the window is closed without starting the print. On Android thePromisewill be resolved immediately after displaying the native print window and won't be rejected if the window is closed without starting the print.
Promise<void>Resolves to an empty Promise if printing started.
Prints HTML to PDF file and saves it to app's cache directory. On Web this method opens the print dialog.
Promise<FilePrintResult>Interfaces
Types
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.
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.