Memulai
-
Instal plugin
Terminal window npm i @capgo/capacitor-pdf-generatorTerminal window pnpm add @capgo/capacitor-pdf-generatorTerminal window yarn add @capgo/capacitor-pdf-generatorTerminal window bun add @capgo/capacitor-pdf-generator -
Sinkronkan platform
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync
Generate dari HTML
Section titled “Generate dari 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();}Tangkap URL remote
Section titled “Tangkap URL remote”await PdfGenerator.fromURL({ url: 'https://docs.capgo.app/invoice?id=123', orientation: 'landscape', documentSize: 'A4', type: 'share', // membuka dialog berbagi native fileName: 'invoice-123.pdf',});- Sertakan CSS inline di string HTML Anda atau berikan
baseUrlagar aset relatif dapat terselesaikan dengan benar. - Saat mengembalikan data base64 di mobile, pindahkan ke filesystem (misalnya, Capacitor Filesystem) sebelum berbagi.
- Orientasi landscape ideal untuk tabel lebar, sementara portrait cocok untuk sebagian besar dokumen.
- Pertimbangkan menggunakan font CSS scoped (misalnya, font sistem) untuk rendering yang konsisten di seluruh platform.