@capgo/capacitor-pdf-generator
v8.0.53
Published
Generate PDF files from HTML strings or URLs on iOS and Android.
Readme
@capgo/capacitor-pdf-generator
Create PDF files from HTML strings or web pages in your Capacitor app, then return them as base64 or open the share sheet. A modern port of the Cordova pdf-generator plugin.
🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use
@capgo/capacitor-pdf-generatorin your Capacitor app:npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-pdf-generator to my Capacitor app and wire it up." Agent setup guides · Hosted MCP
Built and maintained with AI
We build, improve and fix our plugins with heavy use of AI, so issues usually get fixed in under a day and pull requests get feedback the same day. A human still reviews, tests and merges 50+ pull requests daily.
- Most plugin issues get a fix pull request the same day, often within a couple of hours, and are usually resolved in one to two days.
- Every pull request goes through our AI review system, usually within minutes.
- Our AI pre-checks tests, code review, conventions and security, then a human reviews, tests and merges.
- A human, Martin, reviews, tests and merges 50+ pull requests every day.
- In the last 90 days, 95% of plugin issues were resolved.
Learn more about how we build with AI
Key features
- From HTML:
fromData()renders an HTML string to PDF. - From a URL:
fromURL()renders a remote page to PDF. - Output: get
base64data or open the native share dialog with a file name. - Layout: A3 or A4 pages in portrait or landscape.
- Platforms: iOS and Android. Rendered with the native WebView on each platform. Not available on web.
Generate PDF files from HTML strings or remote URLs.
Port of the Cordova pdf-generator plugin for Capacitor with a modernized native implementation.
Documentation
The most complete doc is available here: https://capgo.app/docs/plugins/pdf-generator/
Compatibility
| Plugin version | Capacitor compatibility | Maintained | | -------------- | ----------------------- | ---------- | | v8.*.* | v8.*.* | ✅ | | v7.*.* | v7.*.* | On demand | | v6.*.* | v6.*.* | ❌ | | v5.*.* | v5.*.* | ❌ |
Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
Install
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-pdf-generator` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
npm install @capgo/capacitor-pdf-generator
npx cap syncUsage
import { PdfGenerator } from '@capgo/capacitor-pdf-generator';
const result = await PdfGenerator.fromData({
data: '<html><body><h1>Hello Capgo</h1></body></html>',
documentSize: 'A4',
orientation: 'portrait',
type: 'base64',
fileName: 'example.pdf',
});
if (result.type === 'base64') {
console.log(result.base64);
}API
fromURL(...)
fromURL(options: PdfGeneratorFromUrlOptions) => Promise<PdfGeneratorResult>Generates a PDF from the provided URL.
| Param | Type |
| ------------- | --------------------------------------------------------------------------------- |
| options | PdfGeneratorFromUrlOptions |
Returns: Promise<PdfGeneratorResult>
fromData(...)
fromData(options: PdfGeneratorFromDataOptions) => Promise<PdfGeneratorResult>Generates a PDF from a raw HTML string.
| Param | Type |
| ------------- | ----------------------------------------------------------------------------------- |
| options | PdfGeneratorFromDataOptions |
Returns: Promise<PdfGeneratorResult>
getPluginVersion()
getPluginVersion() => Promise<{ version: string; }>Get the native Capacitor plugin version
Returns: Promise<{ version: string; }>
Interfaces
PdfGeneratorFromUrlOptions
| Prop | Type |
| --------- | ------------------- |
| url | string |
PdfGeneratorFromDataOptions
| Prop | Type | Description |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------- |
| data | string | HTML document to render. |
| baseUrl | string | Base URL to use when resolving relative resources inside the HTML string. When omitted, about:blank is used. |
Type Aliases
PdfGeneratorResult
{ type: 'base64'; base64: string; } | { type: 'share'; completed: boolean; }
