@salonhub/capacitor-printer
v0.1.0
Published
Capacitor plugin for printing a PDF through the operating system's own print dialog
Maintainers
Readme
Capacitor Printer
Print a PDF through the operating system's own print dialog, on iOS and Android.
import CapacitorPrinter from '@salonhub/capacitor-printer';
const printer = new CapacitorPrinter();
const result = await printer.print({
content: 'base64:JVBERi0xLjQK...', /* a `data:` URL or bare base64 works too */
name: 'Invoice 2026-0042',
orientation: 'portrait'
});
if (result.outcome === 'completed') {
/* the user sent it to a printer */
}Why it exists
UIPrintInteractionController and PrintManager are both perfectly good APIs;
what wrappers around them tend to get wrong is everything at the edges.
- The promise resolves when the print UI is done, not when it opens. A
cancelled print is reported as
cancelled, not as a success. This is the whole point: a caller that fires an "it printed" callback the moment the dialog appears is lying to the user. - iPad gets a popover.
present(from:in:animated:completionHandler:)anchored to the web view, which is what UIKit requires there — the iPhone variant does not work on iPad. - The document does not come back. The result carries an outcome, not a copy of the PDF that just crossed the bridge.
- The Android temp file is deleted, in
onFinish(), however the session ended. - The content type is checked, not sniffed.
%PDF-at offset zero, rather than decoding a bitmap to find out what something is not.
API
print({ content, name, orientation })
content is a base64 PDF, with or without a base64: prefix or a
data:application/pdf;base64, wrapper. name is the job name shown in the
print UI and the spooler. orientation is 'portrait' (default) or
'landscape'.
Resolves { outcome: 'completed' | 'cancelled' }. Rejects with
content_not_pdf, content_not_base64, no_content, no_print_service,
cache_write_failed or print_failed.
On Android, completed means the job reached a print service: the framework
only asks for the document once the user has confirmed, but it does not report
what the printer did with it afterwards. On iOS the completion handler is
authoritative.
getCapabilities()
Resolves { silent, default } — whether a job can print without showing the
system dialog, and whether a remembered printer is available. Both are false
on both platforms today.
Installation
npm install @salonhub/capacitor-printer
npx cap syncThe plugin registers as SheetPrinter — the device role it fills, which is not
the same word as the package name.
