How to generate a PDF in your Expo app, in short
Use expo-print. Install it with npx expo install expo-print, import it with import * as Print from 'expo-print', write your document as an HTML string, and call const { uri } = await Print.printToFileAsync({ html }). That renders the HTML to a PDF file and gives you its uri. To let the user send or save it, pass the uri to shareAsync from expo-sharing.
That covers the PDFs most indie apps need: a receipt, an invoice, a workout log, a trip itinerary, an exported report. The parts that decide whether the output looks professional are the rest: where the file ends up, page size and margins, images that go missing on iOS, and printing straight to a printer. That is what this guide covers.
Step 1: Install expo-print
- Install: npx expo install expo-print. Using expo install picks the version that matches your SDK.
- Import: import * as Print from 'expo-print'.
- Start testing in Expo Go. The expo-print reference lists it as included in Expo Go, on Android, iOS and web.
- If you want a share button, also run npx expo install expo-sharing. The expo-print reference's own example pairs the two.
There is no permission prompt for generating a PDF, because the file is written inside your own app's sandbox. Compare that with the camera or location, which need usage descriptions; see [how to request permissions in your Expo app](/blog/how-to-request-permissions-in-your-expo-app) for those.
Step 2: Build the document as HTML
expo-print does not have a drawing API. You describe the page in HTML and CSS, and the platform renders it. That is good news if you have built anything for the web, and it is also why AI tools are good at this task: an invoice is just a table with some headings.
A minimal builder: const buildReceiptHtml = (order) => `<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>@page { margin: 24px; } body { font-family: -apple-system, Helvetica, Arial, sans-serif; } table { width: 100%; border-collapse: collapse; } td { padding: 6px 0; border-bottom: 1px solid #ddd; }</style></head><body><h1>Receipt</h1><p>Order ${escapeHtml(order.id)}</p><table>${order.items.map((i) => `<tr><td>${escapeHtml(i.name)}</td><td>${escapeHtml(i.price)}</td></tr>`).join('')}</table></body></html>`.
- Start with <!DOCTYPE html>. The expo-print reference recommends a well-formed document when you use the iOS markup formatter with margins, to avoid a blank trailing page, and it is a safe default everywhere.
- Escape anything the user typed (names, notes, addresses) before putting it in the HTML. A stray < in a product name can break the layout of the whole page.
- Use web-safe or system fonts in CSS. Fonts you loaded with expo-font for your screens are not automatically available inside the print renderer.
- Keep the builder a pure function that takes data and returns a string. It is easy to test and easy for Claude Code to change later.
Step 3: Turn the HTML into a PDF file
Call const { uri, numberOfPages } = await Print.printToFileAsync({ html }). Per the reference, it prints the HTML to a PDF file, saves it to the app's cache directory, and resolves to an object with the file uri and the number of pages it needed. Pass base64: true if you also want the file contents as a base64 string, for example to upload it; the string does not include the data:application/pdf;base64, prefix.
printToFileAsync options from the expo-print reference
| Option | What it does | Platform |
|---|---|---|
| html | The HTML string to render into the PDF | All |
| width / height | Page size in pixels. Defaults are 612 by 792, US Letter at 72 PPI | All |
| margins | { top, right, bottom, left } page margins | iOS |
| base64 | Also return the PDF as a base64 string | All |
| textZoom | Text zoom percent, default 100 | Android |
| useMarkupFormatter | Uses UIMarkupTextPrintFormatter instead of a WebView, but does not display images | iOS |
Step 5: Print directly with AirPrint or the Android print dialog
If users want paper instead of a file, call await Print.printAsync({ html }). It opens the native print window, which on iOS is AirPrint. You can also print an existing PDF by passing uri instead of html; the reference says that accepts a remote or local PDF, or a base64 data URI, but only PDFs, not images or other document types.
- The promise behaves differently per platform. On iOS it resolves once printing starts and rejects if the user closes the window without printing. On Android it resolves as soon as the print window shows and does not reject if the user cancels. Wrap the call in try/catch and do not treat an iOS rejection as a crash.
- On iOS you can let users pick a printer once with const printer = await Print.selectPrinterAsync(), then pass printerUrl: printer.url to printAsync later. selectPrinterAsync is iOS only.
- orientation: Print.Orientation.landscape is iOS only. For wide tables on Android, set the page width and height in pixels instead.
Step 6: Get images, page size and margins right
Missing images are the most common surprise. The reference explains that on iOS, printing from HTML does not support local asset URLs because of WKWebView limitations. So a logo referenced as a file:// uri or a bundled asset path will render as a blank box. The fix is to convert the image to base64 and inline it as <img src="data:image/png;base64,..." />. The reference's example does this with expo-asset and expo-image-manipulator, saving with base64: true.
- Page size: the default is US Letter, 612 by 792 at 72 PPI. For A4, convert 210 by 297 millimeters at 72 per inch, which is about 595 by 842, and pass those as width and height.
- Margins on iOS: pass margins: { top, right, bottom, left }.
- Margins on Android: the reference says the WebView may add its own page margins, and you control them with an @page CSS rule in your HTML, such as @page { margin: 20px; }.
- Logos: keep them small. Every inlined image makes the HTML string, and the PDF, bigger.
- If you set useMarkupFormatter: true on iOS, images will not display at all. Only use it for text-only documents.
Mistakes that make generated PDFs look broken
- Referencing local images by file path, so they come out blank on iOS. Inline them as base64.
- Leaving the PDF in the cache and storing its uri as if it were permanent.
- Sharing a file with a generated name instead of a clear one like receipt-1042.pdf.
- Putting user-typed text into the HTML without escaping it.
- Assuming printAsync rejects on cancel everywhere. Only iOS does.
- Expecting printToFileAsync to return a file on web, where it opens the print dialog instead.
- Designing for A4 while leaving the default US Letter page size, or the reverse, so content gets cut off or floats in white space.
Have Claude Code set it up for you
Open your project in the Claude Code desktop app and be specific about the details above. Left to its own judgment, AI-written code tends to point an img tag at a local asset path, which looks fine in a quick web preview and comes out blank in the iOS PDF. A prompt that covers it:
Then add a line to your [CLAUDE.md](/blog/claude-md-for-expo-apps) such as "PDFs use expo-print from HTML builders in src/pdf; images are always inlined as base64; saved PDFs live in Paths.document" so a later session does not undo it. Test on a real iPhone: generate a PDF with your logo in it, open it from the share sheet, and check the logo actually appears.
The short version
To generate a PDF in your Expo app: install expo-print, build the page as an HTML string, call printToFileAsync to get a file uri, and share it with expo-sharing or move it into the document directory to keep it. Inline images as base64, set the page size you actually want, control margins with the margins option on iOS and @page CSS on Android, and use printAsync when users want paper.
If you are building your first iOS app with Claude Code and Expo and want a second pair of eyes on it before App Review, bring it to App Store Launch Club. Members share their builds for feedback, and the [curriculum](/curriculum) covers the full path from first build to first users. Join at applaunchclub.co for $9 a month.
Short, practical drops on app ideas, validating fast, store listings, and passing app review. No spam, unsubscribe anytime.
Frequently asked questions
How do I create a PDF in Expo?
Install expo-print, write the document as an HTML string, and call await Print.printToFileAsync({ html }). It resolves to an object with the PDF file uri and the number of pages.
Does expo-print work in Expo Go?
Yes. The expo-print reference lists it as included in Expo Go, and it works on Android, iOS and web, though on web printToFileAsync opens the print dialog instead of returning a file.
Where does printToFileAsync save the PDF?
In the app's cache directory. The system can clear the cache, so move the file into Paths.document with expo-file-system if the user needs to open it again later.
Why are images missing from my Expo PDF on iOS?
On iOS, printing from HTML does not support local asset URLs because of WKWebView limitations. Convert the image to base64 and inline it with a data:image URI.
How do I make an A4 PDF in Expo?
The default page is US Letter, 612 by 792 at 72 PPI. Pass width and height for A4, which at 72 per inch is about 595 by 842.
How do I share a generated PDF in Expo?
Install expo-sharing and call shareAsync(uri, { mimeType: 'application/pdf' }) with the uri from printToFileAsync. It opens the share sheet so the user can save, mail or AirDrop the file.
Can I print directly to a printer from an Expo app?
Yes. Print.printAsync({ html }) or Print.printAsync({ uri }) for an existing PDF opens the native print window, which is AirPrint on iOS. On iOS you can also pick a printer ahead of time with selectPrinterAsync.
Last reviewed by David on October 21, 2026

