cap-printer
v1.2.0
Published
Capacitor plugin for printing pdf documents local and remote
Readme
Capacitor plugin for printing PDF documents - both local and remote.
📦 Installation
npm install cap-printer
npx cap sync🔌 API
Plugin interface for CapPrinter.
print(...)
print(options: PrintRequest) => Promise<void>Print a PDF document from a remote URL or local file path.
Either url or localPath must be provided.
| Param | Type |
| ------------- | ----------------------------------------------------- |
| options | PrintRequest |
isAvailable()
isAvailable() => Promise<{ available: boolean; }>Returns whether the plugin is available on the current platform.
Returns: Promise<{ available: boolean; }>
Interfaces
PrintRequest
Parameters for a print request.
| Prop | Type | Description |
| --------------- | ----------------------------------------------------- | ----------------------------------------------------------------- |
| url | string | Remote PDF file URL. Optional if localPath is provided. |
| localPath | string | Local file path to a PDF document. Optional if url is provided. |
| options | PrintOptions | Optional native print configuration. |
PrintOptions
Optional print configuration for native print dialogs.
| Prop | Type | Description |
| ----------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| outputType | 'general' | 'photo' | 'grayscale' | Defines the output quality or color mode. - general: Default system quality - photo: High-quality color/photo print - grayscale: Black & white / grayscale |
| orientation | 'portrait' | 'landscape' | Sets the page orientation. - portrait: Standard vertical layout - landscape: Horizontal layout |
| duplex | boolean | Enables duplex printing if the printer supports it. |
🧪 Usage
Basic usage
import { CapPrinter } from 'cap-printer';
await CapPrinter.print({
url: 'https://example.com/your.pdf',
options: {
outputType: 'photo',
orientation: 'landscape',
duplex: true,
},
});For local files
import { CapPrinter } from 'cap-printer';
await CapPrinter.print({
localPath: '/path/to/your/file.pdf',
});Plugin availability check (recommended for Web support)
import { CapPrinter } from 'cap-printer';
const { available } = await CapPrinter.isAvailable();
if (!available) {
console.warn('CapPrinter is not available on this platform.');
return;
}
await CapPrinter.print({ url: 'https://example.com/your.pdf' });ℹ️ On Web,
isAvailable()always returnsfalse.
📝 Changelog
For a detailed list of changes and version history, check out the CHANGELOG.md.
🤝 Contributing
Contributions are welcome!
If you'd like to improve the plugin, report an issue, or suggest a feature, feel free to open a pull request or create an issue.
🪪 License
This plugin is licensed under the MIT License.
