---
title: Exploring the Capacitor Printer API
description: "Practical guide to the Capacitor Printer API: print PDFs, images, HTML, and web views from base64, files, or URLs in your apps."
date: 
  created: 2025-07-11
  updated: 2026-07-17
authors:
  - robingenz
categories:
  - Capacitor
  - Guides
  - SDKs
links:
  - Capacitor Printer: sdks/capacitor/printer.md
faq: true
---

# Exploring the Capacitor Printer API

Many mobile applications need to produce physical copies of documents, receipts, and reports directly from the device. The [Capacitor Printer plugin](../../sdks/capacitor/printer.md) from Capawesome adds printing to Ionic and Capacitor applications through a unified API that covers PDFs, images, HTML content, and web pages on both Android and iOS.

<!-- more -->

## Installation

To install the Capacitor Printer plugin, please refer to the [Installation](../../sdks/capacitor/printer.md/#installation) section in the plugin documentation.

## Usage

Let's look at the printing methods the Capacitor Printer API offers and how to use them.

### Printing Base64 Content

The [`printBase64(...)`](../../sdks/capacitor/printer.md#printbase64) method allows you to print content that has been encoded in Base64 format. This method is particularly useful when you have binary data that needs to be transmitted or stored as text:

```ts
import { Printer } from '@capawesome-team/capacitor-printer';

const printBase64Document = async () => {
  await Printer.printBase64({
    data: 'JVBERi0xLjQKJcOkw7zDtsKuCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0ZpbHRlci9GbGF0ZURlY29kZT4+CnN0cmVhbQ==',
    mimeType: 'application/pdf'
  });
};
```

However, printing Base64 content is not recommended for larger files, as it can lead to Out-of-Memory (OOM) errors. The Base64 encoding process increases the file size by approximately 33%, and keeping large encoded strings in memory can quickly exhaust available resources, especially on mobile devices with limited memory.

For better performance and reliability, consider using the [`printFile(...)`](../../sdks/capacitor/printer.md#printfile) method instead, which handles files more efficiently without the memory overhead of Base64 encoding.

### Printing Files

The [`printFile(...)`](../../sdks/capacitor/printer.md#printfile) method provides the most efficient way to print documents stored on the device. This method directly accesses the file system and handles the printing process without requiring additional memory for encoding:

```ts
import { Printer } from '@capawesome-team/capacitor-printer';

const printStoredDocument = async () => {
  await Printer.printFile({
    path: 'content://documents/my-document.pdf',
    mimeType: 'application/pdf'
  });
};
```

This approach is ideal for printing documents that are already stored on the device, such as downloaded files, generated reports, or cached content. The method supports various file formats including PDFs and images.

### Printing HTML Content

The [`printHtml(...)`](../../sdks/capacitor/printer.md#printhtml) method enables you to print dynamically generated HTML content, which is particularly useful for creating formatted documents, reports, or receipts directly from your application:

```ts
import { Printer } from '@capawesome-team/capacitor-printer';

const printHtmlReport = async () => {
  const htmlContent = `
    <html>
      <head>
        <style>
          body { font-family: Arial, sans-serif; margin: 20px; }
          .header { color: #333; border-bottom: 2px solid #333; padding-bottom: 10px; }
          .content { margin-top: 20px; line-height: 1.6; }
          .footer { margin-top: 30px; font-size: 12px; color: #666; }
        </style>
      </head>
      <body>
        <div class="header">
          <h1>Sales Report</h1>
        </div>
        <div class="content">
          <p>This is a dynamically generated sales report for the current month.</p>
          <p>Total Sales: $12,345.67</p>
          <p>Orders Processed: 156</p>
        </div>
        <div class="footer">
          <p>Generated on ${new Date().toLocaleDateString()}</p>
        </div>
      </body>
    </html>
  `;
  
  await Printer.printHtml({
    html: htmlContent
  });
};
```

This method gives you complete control over the document layout and styling.

### Printing Web Content

The [`printWebView(...)`](../../sdks/capacitor/printer.md#printwebview) method allows you to print the current content displayed in your application's web view. This is particularly useful for printing web pages, articles, or any content that users are currently viewing:

```ts
import { Printer } from '@capawesome-team/capacitor-printer';

const printCurrentPage = async () => {
  await Printer.printWebView({
    name: 'Current Page Print Job'
  });
};
```

This method captures the current state of the web view and sends it to the printer with the layout and formatting that users see on their screen. The optional `name` parameter allows you to specify a custom name for the print job, which helps users identify the document in their print queue.

## Best Practices

When implementing printing functionality with the Capacitor Printer API, consider these best practices:

1. **Optimize for performance**: Always use [`printFile(...)`](../../sdks/capacitor/printer.md#printfile) instead of [`printBase64(...)`](../../sdks/capacitor/printer.md#printbase64) for larger documents to avoid memory issues. The file-based approach is more efficient and reduces the risk of Out of Memory errors, especially when dealing with high-resolution images or large PDF documents.

2. **Handle errors gracefully**: Implement comprehensive error handling around all printing operations to manage scenarios such as printer unavailability, connectivity issues, or unsupported file formats. Provide clear feedback to users when printing fails and offer alternative solutions or retry mechanisms.

3. **Provide user feedback**: Display appropriate loading indicators and progress feedback during printing operations, as these processes can take time depending on document size and printer capabilities. Consider showing print preview options when possible to allow users to verify content before printing, and provide confirmation messages when print jobs are successfully submitted.

## FAQ

### Do `printFile()`, `printBase64()`, and `printHtml()` work on the web?

No — all three are Android and iOS only. If your app also targets the web, printing needs to go through a different path there (like the browser's own print dialog for HTML content), since these methods aren't available on that platform.

### What file types can I actually pass to `printBase64()` or `printFile()`?

Not every image or document type — the plugin's supported mime types are `application/pdf`, `image/gif`, `image/heic`, `image/heif`, `image/jpeg`, and `image/png`. The plugin cannot print an unsupported mime type, so check your content type against this list before attempting to print it.

### Is there a dedicated method for printing PDFs specifically, or do I always use `printFile()`?

There's a dedicated `printPdf()` method for PDFs stored on the device, separate from the more general `printFile()`. If you're specifically printing PDF documents, using `printPdf()` is the more direct option rather than routing through the generic file method.

### How large can a base64 string be before `printBase64()` becomes risky?

There's no hard documented limit, but the plugin's own guidance warns that large files can lead to app crashes, which is why `printFile()` is recommended whenever the content already exists as a file rather than an in-memory base64 string. If you're generating content dynamically (like a PDF from a server response), writing it to disk first and calling `printFile()` avoids the memory risk entirely.

### Can I customize what gets printed from `printWebView()`, like hiding navigation elements?

Yes, using a CSS print stylesheet (`@media print` rules) in your web content. `printWebView()` prints whatever the web view currently renders, so applying print-specific CSS to hide navigation bars, buttons, or other on-screen-only UI before printing is a standard web technique that works the same way here as it would in a desktop browser's print dialog.

## Conclusion

Start with [`printFile(...)`](../../sdks/capacitor/printer.md#printfile) for anything already stored on the device, because it avoids the memory overhead that makes Base64 risky for large documents. Use `printBase64(...)` only for small payloads that exist in memory, `printHtml(...)` when your application generates the layout itself, and `printWebView(...)` when you want to print what the user is already looking at.

A common source of printable PDFs is paper: the [Capacitor Document Scanner plugin](./announcing-the-capacitor-document-scanner-plugin.md) captures perspective-corrected pages with the native scanner UI and hands you a combined PDF ready for `printFile(...)`.

To stay updated with the latest updates, features, and news about the Capawesome, Capacitor, and Ionic ecosystem, subscribe to the [Capawesome newsletter](/newsletter/){:target="_blank"} and follow us on [X (formerly Twitter)](https://x.com/capawesomeio){:target="_blank"}.

If you have any questions or need assistance with the Capacitor Printer plugin, reach out to the Capawesome team.
