Getting Started
Ce contenu n'est pas encore disponible dans votre langue.
-
Install the plugin
Fenêtre de terminal npm i @capgo/capacitor-pdf-generatorFenêtre de terminal pnpm add @capgo/capacitor-pdf-generatorFenêtre de terminal yarn add @capgo/capacitor-pdf-generatorFenêtre de terminal bun add @capgo/capacitor-pdf-generator -
Sync platforms
Fenêtre de terminal npx cap syncFenêtre de terminal pnpm cap syncFenêtre de terminal yarn cap syncFenêtre de terminal bunx cap sync
Generate from HTML
Section titled “Generate from HTML”import { PdfGenerator } from '@capgo/capacitor-pdf-generator';
const receiptHtml = ` <html> <body> <h1>Capgo Store</h1> <p>Thank you for your purchase.</p> </body> </html>`;
const pdf = await PdfGenerator.fromData({ data: receiptHtml, documentSize: 'A4', orientation: 'portrait', type: 'base64', fileName: 'receipt.pdf',});
if (pdf.type === 'base64') { const link = document.createElement('a'); link.href = `data:application/pdf;base64,${pdf.base64}`; link.download = 'receipt.pdf'; link.click();}Capture a remote URL
Section titled “Capture a remote URL”await PdfGenerator.fromURL({ url: 'https://docs.capgo.app/invoice?id=123', orientation: 'landscape', documentSize: 'A4', type: 'share', // opens the native share dialog fileName: 'invoice-123.pdf',});- Include inline CSS in your HTML string or provide a
baseUrlso relative assets resolve correctly. - When returning base64 data on mobile, move it to the filesystem (e.g., Capacitor Filesystem) before sharing.
- landscape orientation is ideal for wide tables, while portrait fits most documents.
- Consider using scoped CSS fonts (e.g., system fonts) for consistent rendering across platforms.