npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@redon2inc/strapi-plugin-pdf-creator

v0.1.4

Published

Strapi Plugin to Generate PDF documents from the Admin panel.

Downloads

325

Readme

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:

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

Config

add the following to your config/plugin.ts

{
  'strapi-plugin-pdf-creator': {
    enabled: true,
    config: {
      beautifyDate:{
        fields: [ 'date' ], // name of fields that will be changed
        options: { // check JS toLocaleDateString options for details
          year: 'numeric',
          month: 'long',
          day: 'numeric'
        }
      }
    }
  },
}

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:

{
  //..

  try{
    const templateBytes = fs.readFileSync('locationOfYourTemplate');
    const docData = {
      name : 'Mario',
      enabled: true,
    }; // field names on the PDF template must match keys
    const templateName = 'Title of Document';
    const flattenDocument = true;
    const documentBytes = await strapi
      .plugin('strapi-plugin-pdf-creator')
      .service('service')
      .createPDF(
        templateBytes,
        docData,
        templateName ,
        flattenDocument,
      );
  } catch (err){
    strapi.log.debug('📺: ', err);
    // ..
  }
  // ..
}

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.