Strapi plugin logo for PDF Creator

PDF Creator

Strapi Plugin to Generate PDF documents from the Admin panel.

thumbnail for PDF Creator

Strapi PDF Creator Plugin

Easily generate PDF documents from your Strapi CMS content. This plugin will allow you to download a generated PDF file from the Admin panel, or to generate a PDF file programmatically using your own logic.

PDF generation using PDF-Lib.

FYI:

  • Generate PDF buttons only appears on edit views.
  • Single types content and plugin content are not supported.
  • Currently only Super Admin role users can use the logic using the UI.

⚠️ Compatibility with Strapi versions

This plugin was developed for the 5.X Strapi version. It has not been tested with the 4.X version. Use it at your own risk.

⚙️ Installation

To install the Strapi PDF Creator Plugin, simply run one of the following command:

1npm install @redon2inc/strapi-plugin-pdf-creator
1yarn add @redon2inc/strapi-plugin-pdf-creator

Config

add the following to your config/plugin.ts

1{
2  'strapi-plugin-pdf-creator': {
3    enabled: true,
4    config: {
5      beautifyDate:{
6        fields: [ 'date' ], // name of fields that will be changed
7        options: { // check JS toLocaleDateString options for details
8          year: 'numeric',
9          month: 'long',
10          day: 'numeric'
11        }
12      }
13    }
14  },
15}

Template requirements

  • The PDF template's form field names must match the names as the collection type. Only matching names will be used to populate the files.
  • PDF TextFields use Text type fields.
  • PDF Buttons will be replaced with Media type fields. This only when PDFs are flattened.
  • PDF Checkboxes use Boolean type fields.
  • RadioGroups, OptionLists, Dropdowns fields use Enumeration type fields.

Usage

Admin panel

  • The following must be enabled so a user can generate files:

    • Inside Role editor, find the pdf plugin and allow role to generate document.
    • The users' role must have access to view content template.
    • By default super admins will be able to generate files.
  • Once the first template is created and assigned to a collection type, the admin can navigate to an entry and a PDF button should appear on the right side menu. strapi pdf creator Check Examples for more details.

Create PDF programmatically

You can call the PDF template service from within your code:

1{
2  //..
3
4  try{
5    const templateBytes = fs.readFileSync('locationOfYourTemplate');
6    const docData = {
7      name : 'Mario',
8      enabled: true,
9    }; // field names on the PDF template must match keys
10    const templateName = 'Title of Document';
11    const flattenDocument = true;
12    const documentBytes = await strapi
13      .plugin('strapi-plugin-pdf-creator')
14      .service('service')
15      .createPDF(
16        templateBytes,
17        docData,
18        templateName ,
19        flattenDocument,
20      );
21  } catch (err){
22    strapi.log.debug('📺: ', err);
23    // ..
24  }
25  // ..
26}

Enjoy 🎉

TODO:

  • Allow other fonts
  • Beautify date fields.
  • Settings function to validate template against schema.

👍 Contribute

  1. Add a GitHub Star to the project.

🧾 License

This plugin is licensed under the MIT License.

Install now

npm install @redon2inc/strapi-plugin-pdf-creator

STATS

3 GitHub stars9 weekly downloads

Last updated

103 days ago

Strapi Version

5.2.0 and above

Author

github profile image for Redon2 Solutions
Redon2 Solutions

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.