Aller directement au contenu principal
Retour aux plugins
@capgo/capacitor-imprimante
Tutoriel
@capgo/capacitor-imprimante

Imprimante

Capacitor plugin pour imprimer des documents, HTML, PDF, images et vues web

Guide

Tutoriel sur l'imprimante

Tester sur appareil

Téléchargez l'application Capgo, puis scannez le code QR code.

Prévisualisation du lien QR du plugin d'impression code

Utilisation de @capgo/capacitor-imprimante

Capacitor : plugin d'impression pour les documents, les pages HTML, les PDF, les images et les 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 en chaînes de base64.
  • printFile - Présente l'interface d'impression pour imprimer des fichiers du périphérique.
  • 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 codé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

Continuez à partir de l'utilisation de @capgo/capacitor-imprimante

Si vous utilisez L'utilisation de @capgo/capacitor-imprimante pour planifier le travail de plugin natif, connectez-le avec @capgo/capacitor-imprimante pour les détails d'implémentation dans @capgo/capacitor-imprimante, Démarrage pour les détails d'implémentation dans Démarrage, Capgo Répertoire des plugins pour le flux de travail du produit dans Capgo Répertoire des plugins, Capacitor Plugins par Capgo pour les détails d'implémentation dans Capacitor Plugins par Capgo, et Ajouter ou Mettre à jour les plugins pour les détails d'implémentation dans Ajouter ou Mettre à jour les plugins.