Getting Started
Este contenido aún no está disponible en tu idioma.
-
Install the plugin
Ventana de terminal npm i @capgo/capacitor-pdf-generatorVentana de terminal pnpm add @capgo/capacitor-pdf-generatorVentana de terminal yarn add @capgo/capacitor-pdf-generatorVentana de terminal bun add @capgo/capacitor-pdf-generator -
Sync platforms
Ventana de terminal npx cap syncVentana de terminal pnpm cap syncVentana de terminal yarn cap syncVentana 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.