Socket
Book a DemoInstallSign in
Socket

capacitor-pdf-generator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-pdf-generator

A Capacitor plugin to generate PDF from HTML.

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
3
-95.65%
Maintainers
1
Weekly downloads
 
Created
Source

Capacitor PDF Generator

This Capacitor plugin enables you to easily generate PDF documents from HTML content directly within your mobile app. Designed for both Android and iOS platforms, it seamlessly converts your HTML strings or files into high-quality PDF files that can be saved, shared, or printed.

Installation

npm install capacitor-pdf-generator
npx cap sync

Usage

The generate method takes an options object with the following properties:

  • html: The HTML template to use.
  • data: The data to render in the template.
  • direction: The direction of the text (ltr or rtl).
  • locale: The locale to use for the text.
  • logo: The URL of the logo to use in the header.
  • headerLine1: The first line of the header.
  • headerLine2: The second line of the header.
  • footerLine1: The first line of the footer.
  • footerLine2: The second line of the footer.
  • filename: The name of the generated PDF file.
  • margin: The margin of the PDF file.

Example

import { Plugins } from '@capacitor/core';
const { PdfGenerator } = Plugins;

async function generatePdf() {
  const html = `
   USE HTML template with CSS. Attached DEMO file name dynamic-template.html
  `;

  const requestData = [
  { subHead: 'Invoice Number', subValue: 'INV-2025-00123' },
  { subHead: 'Invoice Date', subValue: '2025-08-11' },
  { subHead: 'Due Date', subValue: '2025-09-10' },
  { subHead: 'Bill To', subValue: 'John Doe' },
  { subHead: 'Billing Address', subValue: '1234 Elm Street, Springfield, IL' },
  { subHead: 'Shipping Address', subValue: '5678 Oak Avenue, Springfield, IL' },
  { subHead: 'Item Description', subValue: 'Laptop Model XYZ' },
  { subHead: 'Quantity', subValue: '2' },
  { subHead: 'Unit Price', subValue: '$1200.00' },
  { subHead: 'Subtotal', subValue: '$2400.00' },
  { subHead: 'Tax (10%)', subValue: '$240.00' },
  { subHead: 'Total Amount', subValue: '$2640.00' },
  { subHead: 'Payment Terms', subValue: 'Net 30 days' },
  { subHead: 'Notes', subValue: 'Thank you for your business!' },
]

 const options = {
    html: template,
    data: {
      logo: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2", 
      headerLine1: 'Your Company Name',
      headerLine2: 'Invoice',
      footerLine1: 'Thank you for your business!',
      footerLine2: 'www.yourcompany.com',
      title: 'Demo',
      items: requestData,
      isRtl: false // Set to true for Arabic, Hebrew.
    },
    locale: 'ar-SA', // Example for Arabic
    margin:10
  };

 PdfGenerator.generate(options).then(result => {
    console.log('PDF generated', result.base64);
      // Do something with the base64 string
  });

}

API

* [`generate(...)`](#generate)

generate(...)

generate(options: PdfGeneratorOptions) => Promise<{ base64: string; }>
ParamType
optionsPdfGeneratorOptions

Returns: Promise<{ base64: string; }>

Interfaces

PdfGeneratorOptions

PropTypeDescription
htmlstringThe HTML template to use.
dataanyThe data to render in the template.
direction'ltr' | 'rtl'The direction of the text (ltr or rtl).
localestringThe locale to use for the text.
logostringThe URL of the logo to use in the header.
headerLine1stringThe first line of the header.
headerLine2stringThe second line of the header.
footerLine1stringThe first line of the footer.
footerLine2stringThe second line of the footer.
filenamestringThe name of the generated PDF file.
marginnumberThe margin of the PDF file.

Keywords

capacitor

FAQs

Package last updated on 12 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.