Skip to content

Cap-go/capacitor-pdf-generator

@capgo/capacitor-pdf-generator

Capgo - Instant updates for capacitor

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/

Install

npm install @capgo/capacitor-pdf-generator
npx cap sync

Usage

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; }

About

Capacitor plugin to generate PDF files from HTML strings or URLs on iOS and Android.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •