How to Generate a PDF in Your Expo App

DavidDavid October 21, 2026 7 min read

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

  1. Install: npx expo install expo-print. Using expo install picks the version that matches your SDK.
  2. Import: import * as Print from 'expo-print'.
  3. Start testing in Expo Go. The expo-print reference lists it as included in Expo Go, on Android, iOS and web.
  4. 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

OptionWhat it doesPlatform
htmlThe HTML string to render into the PDFAll
width / heightPage size in pixels. Defaults are 612 by 792, US Letter at 72 PPIAll
margins{ top, right, bottom, left } page marginsiOS
base64Also return the PDF as a base64 stringAll
textZoomText zoom percent, default 100Android
useMarkupFormatterUses UIMarkupTextPrintFormatter instead of a WebView, but does not display imagesiOS

Step 4: Share or save the PDF

The file lives in the cache directory, which the system can clear. For a one-off export, that is fine: share it right away with await shareAsync(uri, { mimeType: 'application/pdf' }) from expo-sharing, which opens the share sheet so the user can save it to Files, mail it, or AirDrop it. For more on the share sheet itself, see [how to add a share sheet to your Expo app](/blog/how-to-add-a-share-sheet-to-your-expo-app).

  • Check await Sharing.isAvailableAsync() before calling shareAsync, which the expo-sharing reference recommends for web.
  • Give the file a real name before sharing. The generated name is not something a user wants to see in their Files app. With the File class from expo-file-system you can move it: const pdf = new File(uri); pdf.move(new File(Paths.document, `receipt-${orderId}.pdf`)); then share pdf.uri.
  • If the user needs to find the PDF again inside your app, keep it in Paths.document rather than the cache, and store its uri alongside the record it belongs to. For the record itself, see [how to add a local database to your Expo app](/blog/how-to-add-a-local-database-to-your-expo-app).
  • To let users attach an existing PDF instead of generating one, that is a different module; see [how to add a file picker to your Expo app](/blog/how-to-add-a-file-picker-to-your-expo-app).

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.

Free app-building tips, straight to your inbox

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

David

Written by

David

Founder and app builder

Keep reading

ExpoClaude Code

How to Add Notification Actions to Your Expo App

To add notification actions to an Expo app, register a category with Notifications.setNotificationCategoryAsync, give it action buttons (and optionally a text reply), set categoryIdentifier on the notification, then read response.actionIdentifier in a response listener. Here is every action option, how to handle taps when the app was closed, the Android and iOS differences, and a Claude Code prompt that wires it all up.

David 8 min
Read article
ExpoClaude Code

How to Schedule Local Notifications in Your Expo App

To schedule local notifications in an Expo app, install expo-notifications, set a notification handler, ask for permission, create an Android channel, then call scheduleNotificationAsync with your content and a trigger like DAILY, WEEKLY or DATE. Here is every trigger type, how to cancel and list what is scheduled, why Android reminders arrive late, and a Claude Code prompt that builds the whole reminder flow.

David 8 min
Read article

Ready to build it yourself?

Join App Store Launch Club, the #1 community for building and launching apps, for $9/month.

← Back to the blog