Technical
How to Print Documents and Receipts from an Android TWA
October 14, 2026 · 8 min read
The Challenge of Printing in a Trusted Web Activity
In standard desktop and mobile browsers, printing a document is a straightforward task. Developers rely on the standard window.print() JavaScript method to launch the system print dialog. However, when running a Progressive Web App (PWA) inside a Trusted Web Activity (TWA) on Android, this standard printing behavior is often unsupported or highly inconsistent.
Because a TWA runs in a container powered by Custom Tabs, it lacks the full browser user interface, including the standard print preview screens. Calling window.print() in a TWA may fail silently, leaving users unable to print invoices, order receipts, or physical documents. To build an enterprise-ready mobile app, developers must implement reliable alternative strategies to handle document and receipt printing. This article explores the best technical paths to solve this problem.
Method 1: Generating PDFs and Utilizing System Handlers
The most robust way to handle document printing in a TWA is to generate a PDF on the client or server side, download the file, and pass the printing responsibility to the native Android operating system. This method ensures that the user can use any installed print service, such as Google Cloud Print replacements, Samsung Print Service, or HP Print Service.
To generate the PDF on the client side, you can use popular JavaScript libraries like jsPDF or pdfmake. Once the document is compiled into a Blob object, you can trigger a download within the TWA. Android will then prompt the user to open the file with an external viewer or print utility.
Consider the following JavaScript example of generating a simple receipt PDF and triggering a download helper:
function generateAndPrintReceipt(orderData) {
const doc = new jsPDF();
doc.text('Order Receipt', 10, 10);
doc.text('Total: ' + orderData.total, 10, 20);
const pdfBlob = doc.output('blob');
const blobUrl = URL.createObjectURL(pdfBlob);
const downloadLink = document.createElement('a');
downloadLink.href = blobUrl;
downloadLink.download = 'receipt-' + orderData.id + '.pdf';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
When the download triggers, the Android system handles the file association. To make the process smoother, you can configure your TWA to support file downloads directly, allowing users to tap the notification and open the document with their preferred local PDF printing utility.
Method 2: Leveraging Web Bluetooth for Thermal Receipt Printing
For point-of-sale (POS) systems, retail applications, and logistics apps, printing a full page PDF is often unnecessary. Instead, developers need to print receipts directly to a small thermal Bluetooth printer. This can be accomplished inside a TWA using the Web Bluetooth API.
Web Bluetooth allows your web application to scan for, connect to, and send ESC/POS printer commands directly to nearby Bluetooth devices. This bypasses the Android print manager completely, offering a faster and more customisable printing workflow.
The general workflow for Web Bluetooth printing in a TWA involves searching for the device service, pairing, and sending raw array buffers containing command characters:
async function printToThermalPrinter(receiptText) {
try {
const device = await navigator.bluetooth.requestDevice({
filters: [{ services: ['000018f0-0000-1000-8000-00805f9b34fb'] }]
});
const server = await device.gpt.connect();
const service = await server.getPrimaryService('000018f0-0000-1000-8000-00805f9b34fb');
const characteristic = await service.getCharacteristic('00002af1-0000-1000-8000-00805f9b34fb');
const encoder = new TextEncoder();
const data = encoder.encode(receiptText + '\n\n\n');
await characteristic.writeValue(data);
} catch (error) {
console.error('Bluetooth printing failed', error);
}
}
Before choosing this method, ensure that Web Bluetooth is enabled and that your target Android devices are running modern Google Chrome versions, as Chrome handles the Web Bluetooth permissions on behalf of the TWA wrapper.
Method 3: Directing Users to Custom Android Print Apps
If your users are operating in a structured corporate environment (such as warehouse workers or delivery drivers), you can use custom Android intents or deep links to route print jobs directly to dedicated hardware utility apps. Many printer manufacturers provide native apps that register custom URL schemes.
For example, if you are utilizing Zebra thermal printers, you can use the Link-OS SDK or the Zebra Print Connect app. By constructing a specific URI scheme, your TWA web app can redirect the browser to the native companion application, sending along the printing payload in ZPL (Zebra Programming Language) format.
Comparing Printing Implementations inside a TWA
| Printing Method | Target Hardware | Development Complexity | Best Use Case |
|---|---|---|---|
| PDF Download & System Handler | Standard Desktop/Office Printers | Low | Invoices, shipping labels, and multi-page reports. |
| Web Bluetooth API | Mobile Thermal Printers | High | Retail point of sale (POS) and on-the-go receipt printing. |
| Manufacturer Native Schemes | Enterprise Industrial Printers | Medium | Warehouse dispatch, manufacturing, and high-volume barcode printing. |
Ensuring Reliable Storage and Permissions
To implement these printing solutions successfully, you must ensure that your TWA has the correct Android permissions declared in its Android Manifest. If you are saving PDF files to local directories, you will need to verify that storage permissions are properly requested on older Android versions, or utilise the modern Scoped Storage guidelines for Android 10 and above.
Furthermore, if you are utilising Web Bluetooth, you must declare Bluetooth administrative permissions inside your native wrapper. This ensures that the user is prompted correctly for location and nearby device sharing when your web app initiates the communication sequence.
Summary and Best Practices
While the lack of direct window.print() support in TWAs introduces architectural hurdles, combining PDF downloads with native Android intent handlers or leveraging Web Bluetooth offers robust, production-ready alternatives. Choose the pattern that matches your hardware setup, test on real devices to ensure files download properly, and verify that all necessary Android permissions are handled gracefully by your TWA wrapper.
Ready to ship your Android app?
Paste your PWA URL, get a signed APK and a Google Play ready AAB in minutes.
Build my app