By Redon2
Strapi Plugin to Generate PDF documents from the Admin panel.
released November 11, 2024
npm install @redon2inc/strapi-plugin-pdf-creatorEasily 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.
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.
To install the Strapi PDF Creator Plugin, simply run one of the following command:
npm install @redon2inc/strapi-plugin-pdf-creatoryarn add @redon2inc/strapi-plugin-pdf-creatoradd 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'
}
}
}
},
}The following must be enabled so a user can generate files:
template.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.
Check Examples for more details.
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 🎉
This plugin is licensed under the MIT License.
Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.
Submit
