Guide
Tutoriel sur l'Imprimante
Utilisation de @capgo/capacitor-imprimante
Capacitor plugin pour l'impression de documents, de HTML, de PDF, d'images et de vues web.
Installer
bun add @capgo/capacitor-printer
bunx cap sync
Ce que ce Plugin Expose
printBase64- Présente l'interface d'impression pour imprimer des fichiers codés sous forme de chaînes base64.printFile- Présente l'interface d'impression pour imprimer des fichiers de l'appareil.printHtml- Présente l'interface d'impression pour imprimer des documents HTML.printPdf- Présente l'interface d'impression pour imprimer des documents PDF.
Exemple d'utilisation
printBase64
Présente l'interface d'impression pour imprimer des fichiers encodés en chaînes de base64.
import { Printer } from '@capgo/capacitor-printer';
// Print a base64 encoded PDF
await Printer.printBase64({
name: 'Invoice #12345',
data: 'base64-encoded-pdf-data',
mimeType: 'application/pdf',
});
// Print a base64 encoded image
await Printer.printBase64({
name: 'Product Photo',
data: '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDA...',
mimeType: 'image/jpeg',
});
printFile
Présente l'interface d'impression pour imprimer des fichiers de périphérique.
import { Printer } from '@capgo/capacitor-printer';
// iOS: Print from app documents directory
await Printer.printFile({
name: 'Contract',
path: 'file:///var/mobile/Containers/Data/Application/.../Documents/contract.pdf',
});
// Android: Print from content URI
await Printer.printFile({
name: 'Receipt',
path: 'content://com.android.providers.downloads.documents/document/123',
mimeType: 'application/pdf',
});
// Android: Print from file path
await Printer.printFile({
name: 'Photo',
path: 'file:///storage/emulated/0/Download/photo.jpg',
mimeType: 'image/jpeg',
});
printHtml
Présente l'interface d'impression pour imprimer des documents HTML.
import { Printer } from '@capgo/capacitor-printer';
// Simple HTML document
await Printer.printHtml({
name: 'Sales Report',
html: '<html><body><h1>Q4 Sales Report</h1><p>Revenue: $125,000</p></body></html>',
});
// HTML with print-specific CSS
await Printer.printHtml({
name: 'Styled Invoice',
html: `
<html>
<head>
<style>
printPdf
Présente l'interface d'impression pour imprimer des documents PDF.
import { Printer } from '@capgo/capacitor-printer';
// Print PDF from app storage
await Printer.printPdf({
name: 'Annual Report 2024',
path: 'file:///var/mobile/Containers/Data/Application/.../Documents/report.pdf',
});
// Print PDF from Android downloads
await Printer.printPdf({
name: 'Downloaded Document',
path: 'content://com.android.providers.downloads.documents/document/123',
});
Référence complète
- GitHub: https://github.com/Cap-go/capacitor-imprimante/
- Documentation : /docs/plugins/imprimante/