Skip to main content

cordova-pdf-generator Alternative for Capacitor

cordova-pdf-generator alternative for Capacitor: render HTML or URLs to PDF with @capgo/capacitor-pdf-generator, base64 or share output, and promise APIs.

Illustration of migrating a Cordova app to Capacitor, used for an HTML to PDF plugin guide

The practical cordova-pdf-generator alternative for a Capacitor app is @capgo/capacitor-pdf-generator. It keeps the same two entry points as the Cordova pdf global (fromURL and fromData), the same A3 or A4 sizing and portrait or landscape rendering, and the same base64 versus share style outputs, but swaps Cordova promises around cordova.exec for native Capacitor calls you can await. This guide lists verifiable npm facts, install steps, usage, and an API map for your Cordova to Capacitor move.

Why leave cordova-pdf-generator in Capacitor

cordova-pdf-generator on npm is version 2.1.1. The registry modified timestamp is 13 June 2022, and 2.1.1 was first published 16 April 2020. The source lives at cesarvr/pdf-generator. The README documents Android and iOS support, HTML or URL sources, and base64 or system share output.

The Cordova JavaScript layer in www/pdf.js exposes:

  • pdf.fromURL(url, options) returning a Promise
  • pdf.fromData(data, options) returning a Promise
  • legacy pdf.htmlToPDF(options, success, error) via cordova.exec on the PDFService channel

Default options include documentSize: "A4", landscape: "portrait", type: "base64", and fileName: "default.pdf". fromData accepts baseUrl for relative assets inside the HTML string.

In a Capacitor codebase the Cordova plugin still means:

  • cordova plugin add cordova-pdf-generator and waiting for deviceready
  • the global pdf namespace instead of a typed import
  • no maintained npm release since 2020 even though the registry modified field moved in 2022

@capgo/capacitor-pdf-generator latest on npm is 8.0.53 with a modified date of 13 November 2026. The Capacitor API in src/definitions.ts mirrors the Cordova options and adds a typed PdfGeneratorResult union for base64 and share responses. Capgo maintains the plugin on an open source cadence where a human still reviews, tests and merges 50+ pull requests daily.

Install

bun add @capgo/capacitor-pdf-generator
bunx cap sync

No extra iOS or Android setup is required beyond syncing native projects after install, as documented in getting started.

Usage example

import { PdfGenerator } from '@capgo/capacitor-pdf-generator';

const html = `
  <html><body><h1>Invoice #1024</h1><p>Total: $42.00</p></body></html>
`;

export async function exportInvoiceBase64() {
  const result = await PdfGenerator.fromData({
    data: html,
    documentSize: 'A4',
    orientation: 'portrait',
    type: 'base64',
    fileName: 'invoice-1024.pdf',
  });

  if (result.type === 'base64') {
    await uploadPdf(result.base64);
  }
}

Generate from a hosted receipt template:

const result = await PdfGenerator.fromURL({
  url: 'https://example.com/receipts/1024.html',
  type: 'share',
  fileName: 'receipt-1024.pdf',
});

Migrating from Cordova to Capacitor

Cordova code imports nothing and calls pdf.fromData after deviceready. Capacitor code imports PdfGenerator and passes a single options object.

// Before (Cordova)
document.addEventListener('deviceready', () => {
  pdf
    .fromData('<html>...</html>', {
      documentSize: 'A4',
      landscape: 'portrait',
      type: 'base64',
      fileName: 'report.pdf',
      baseUrl: 'https://example.com/',
    })
  .then((base64) => upload(base64))
  .catch(console.error);
});
// After (Capacitor)
import { PdfGenerator } from '@capgo/capacitor-pdf-generator';

const result = await PdfGenerator.fromData({
  data: '<html>...</html>',
  documentSize: 'A4',
  orientation: 'portrait',
  type: 'base64',
  fileName: 'report.pdf',
  baseUrl: 'https://example.com/',
});

if (result.type === 'base64') {
  await upload(result.base64);
}

API mapping table

cordova-pdf-generator (pdf) @capgo/capacitor-pdf-generator
pdf.fromURL(url, options) fromURL({ url, ...options })
pdf.fromData(data, options) fromData({ data, ...options })
pdf.htmlToPDF(options, success, error) fromURL or fromData with the same fields in one object
options.documentSize (A4 default) documentSize (A3 or A4)
options.landscape (portrait default) orientation (portrait or landscape), landscape kept for compatibility
options.type (base64 or share flow) type: 'base64' | 'share'
options.fileName fileName
options.baseUrl on fromData baseUrl on fromData
Promise resolves to base64 string result.type === 'base64' with result.base64
Share sheet flow type: 'share' with result.completed

After you generate a base64 PDF, write it with @capgo/capacitor-file or @capacitor/filesystem if the Cordova app previously kept everything in memory.

Native PDF rendering needs a store build when you first add the plugin. Use Capgo Build for binaries, then iterate on HTML templates with Capgo live updates. For related file workflows see the capacitor file handling guide and the Cordova to Capacitor migration guide.

Live updates for Capacitor apps

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

Latest from our Blog

Capgo gives you the best insights you need to create a truly professional mobile app.