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

Icône d'impression

plugin Capacitor pour l'impression de documents, HTML, PDF, images et vues web

Guide

Tutoriel sur l'imprimante

Utilisation de @capgo/capacitor-imprimante

plugin Capacitor pour l'impression de documents, HTML, PDF, images et vues web.

Installation

bun add @capgo/capacitor-printer
bunx cap sync

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 de 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, Répertoire de plugin Capgo pour le flux de produit dans le répertoire de plugin Capgo Capacitor Plugins par Capgo pour le détail d'implémentation dans Capacitor Plugins par Capgo, et Ajouter ou Mettre à jour les plugins pour le détail d'implémentation dans Ajouter ou Mettre à jour les plugins.