PHPackages                             kennethormandy/craft-api2pdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. kennethormandy/craft-api2pdf

ActiveCraft-plugin[PDF &amp; Document Generation](/categories/documents)

kennethormandy/craft-api2pdf
============================

Generate PDFs using api2pdf.com

4.0.0(1y ago)11.3k↓100%2MITPHP

Since Jan 5Pushed 1y ago2 watchersCompare

[ Source](https://github.com/kennethormandy/craft-api2pdf)[ Packagist](https://packagist.org/packages/kennethormandy/craft-api2pdf)[ RSS](/packages/kennethormandy-craft-api2pdf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

[![Craft Api2Pdf icon](./src/icon.svg)](./src/icon.svg)

Api2Pdf plugin for Craft CMS
============================

[](#api2pdf-plugin-for-craft-cms)

Generate PDFs easily, using [Api2Pdf.com](https://www.api2pdf.com)

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.1.x or later, or Craft 4.0.0 or later.

Installation
------------

[](#installation)

The Craft 4 version of the plugin is [currently tagged as a beta release](https://github.com/kennethormandy/craft-api2pdf/pull/5). You can install it with:

```
composer require kennethormandy/craft-api2pdf:^1.0.0-beta.1
```

Otherwise, require the plugin using Composer like normal:

```
composer require kennethormandy/craft-api2pdf
```

Then, in the Craft CMS Control Panel, go to Settings → Plugins, and click the “Install” button for Craft Api2Pdf. Or run:

```
./craft install/plugin api2pdf
```

Settings
--------

[](#settings)

The only setting required to run the plugin is an API key from Api2Pdf, which can (and probably should) be set to an [environment variable](https://docs.craftcms.com/v3/config/environments.html):

[![Craft Api2Pdf settings panel in the Craft CMS admin area](https://user-images.githubusercontent.com/1581276/72213557-ebe31f00-34a5-11ea-8d49-c8b2f0327828.png)](https://user-images.githubusercontent.com/1581276/72213557-ebe31f00-34a5-11ea-8d49-c8b2f0327828.png)

Actions
-------

[](#actions)

- [`api2pdf/pdf/generate-from-url`](#action-generate-from-url)
- [`api2pdf/pdf/generate-from-html`](#action-generate-from-html)
- [`api2pdf/pdf/merge`](#action-merge)

Twig
----

[](#twig)

- [`craft.api2pdf.generateFromUrl`](#twig-generatefromurl-function)
- [`craft.api2pdf.generateFromHtml`](#twig-generatefromhtml-function)
- [`craft.api2pdf.merge`](#twig-merge-function)

Options
-------

[](#options)

  Option Type Description   `filename` String    `redirect` Boolean Redirect directly to the PDF URL - `filename`
- `redirect`

All [advanced options for Headless Chrome](https://www.api2pdf.com/documentation/advanced-options-headless-chrome/) to pass along to Api2Pdf are also supported.

Examples
--------

[](#examples)

### Action `generate-from-url`

[](#action-generate-from-url)

Get the JSON response from Api2Pdf:

```

  {{ csrfInput() }}

```

Redirect directly to the PDF url:

```

  {{ csrfInput() }}

```

### Action `generate-from-html`

[](#action-generate-from-html)

Redirect directly to the PDF made using an HTML string:

```

  {{ csrfInput() }}

```

Offer an editable filename:

```

  {{ csrfInput() }}

```

### Action `merge`

[](#action-merge)

Merge two hosted PDFs (generated by this plugin or otherwise), into one:

These URLs passed to this function need to be hosted PDFs. Whether or not they were previously generated via this plugin previously, or whether they are on your server doesn’t matter, as long as they are accessible at the URL.

```
{% set urls = [
  'https://example.com/one.pdf',
  'https://example.com/two.pdf'
] %}

  {% for url in urls %}

  {% endfor %}
  {{ csrfInput() }}

```

### Twig `generateFromUrl` function

[](#twig-generatefromurl-function)

```
{% set result = craft.api2pdf.generateFromUrl('https://example.com') %}

{% if result and result.success %}
  {{ result.pdf }}
{% endif %}
```

### Twig `generateFromHtml` function

[](#twig-generatefromhtml-function)

```
{% set result = craft.api2pdf.generateFromHtml('Hello') %}

{% if result and result.success %}
  {{ result.pdf }}
{% endif %}
```

Slightly more detailed example:

```
{% set options = {
  redirect: true,
  filename: "test.pdf"
} %}
{% set result = craft.api2pdf.generateFromHtml('Hello', options) %}

{% if result and result.success %}

  {# Display the URL #}
  {{ result.pdf }}

  {# The other pieces of metadata available #}

    {{ result.mbIn|round }}mb
    {{ result.mbOut|round }}mb
    US${{ result.cost|round }}
    {{ result.responseId }}

{% else %}
  {{ result.error }}
{% endif %}
```

### Twig `merge` function

[](#twig-merge-function)

```
{% set urls = [
  'https://example.com/one.pdf',
  'https://example.com/two.pdf'
] %}
{% set result = craft.api2pdf.merge(urls) %}

{% if result and result.success %}
  {{ result.pdf }}
{% else %}
  {{ result.error }}
{% endif %}
```

Notes
-----

[](#notes)

- This plugin is build for v1 of the Api2Pdf API, but support for the [v2 endpoint](https://www.api2pdf.com/api2pdf-launches-v2-in-beta/) may be added when it’s out of beta, the Api2Pdf client libraries are also updated
- This plugin only supports Headless Chrome for PDF generation. If you are interested in adding support for another endpoint, I’d be open to discussing a Pull Request (but note the v2 API also only supports Headless Chrome).

License
-------

[](#license)

[The MIT License (MIT)](./LICENSE.md)

Copyright © 2019–2020 [Kenneth Ormandy Inc.](https://kennethormandy.com)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance40

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 98.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~362 days

Recently: every ~450 days

Total

6

Last Release

505d ago

Major Versions

0.5.0 → 1.0.0-beta.12023-01-12

1.0.0-beta.1 → 4.0.02024-12-20

4.0.0 → 5.0.0-beta.12024-12-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/69f6d7651737e5c728af6c5189a24489057d63381a6a49b3050d38fe713824ae?d=identicon)[kennethormandy](/maintainers/kennethormandy)

---

Top Contributors

[![kennethormandy](https://avatars.githubusercontent.com/u/1581276?v=4)](https://github.com/kennethormandy "kennethormandy (73 commits)")[![chadcrowell](https://avatars.githubusercontent.com/u/48151?v=4)](https://github.com/chadcrowell "chadcrowell (1 commits)")

---

Tags

craft-plugincraftcms-pluginpdfpdf-generationpdfcmsCraftcraftcmscraft-pluginapi2pdf

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/kennethormandy-craft-api2pdf/health.svg)

```
[![Health](https://phpackages.com/badges/kennethormandy-craft-api2pdf/health.svg)](https://phpackages.com/packages/kennethormandy-craft-api2pdf)
```

###  Alternatives

[nystudio107/craft-seomatic

SEOmatic facilitates modern SEO best practices &amp; implementation for Craft CMS 5. It is a turnkey SEO system that is comprehensive, powerful, and flexible.

1741.4M46](/packages/nystudio107-craft-seomatic)[enupal/snapshot

PDF or Image generation from a Url or HTML page

1137.9k](/packages/enupal-snapshot)[verbb/image-resizer

Resize assets when they are uploaded.

127269.1k7](/packages/verbb-image-resizer)[verbb/tablemaker

Create customizable and user-defined table fields.

40168.8k1](/packages/verbb-tablemaker)[acclaro/translations

Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.

1229.5k](/packages/acclaro-translations)[verbb/footnotes

Adds a footnotes feature to CKEditor fields and Twig templates.

213.3k](/packages/verbb-footnotes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
