Introduction to mdpdf
MDPDF is a powerful and flexible library designed to seamlessly convert Markdown files into high-quality PDFs. With a wide array of APIs, developers can customize and enhance their PDFs with ease.
Key Features and APIs
Basic Conversion
The core functionality of MDPDF is converting Markdown to PDF.
const mdpdf = require('mdpdf'); const options = { source: 'example.md', destination: 'output.pdf' }; mdpdf.convert(options).then(() => { console.log('PDF Generated'); });
Custom Styles
Apply custom styles to your PDF documents using CSS.
const options = { source: 'example.md', destination: 'output.pdf', stylesheet: 'styles.css' }; mdpdf.convert(options).then(() => { console.log('Styled PDF Generated'); });
Header and Footer
Add headers and footers to your PDFs.
const options = { source: 'example.md', destination: 'output.pdf', header: 'Document Header
', footer: 'Page Footer
' }; mdpdf.convert(options).then(() => { console.log('PDF with Header and Footer Generated'); });
Table of Contents
Automatically generate a table of contents.
const options = { source: 'example.md', destination: 'output.pdf', toc: true }; mdpdf.convert(options).then(() => { console.log('PDF with TOC Generated'); });
App Example
Here is a simple example of a Node.js application using MDPDF to generate a PDF from a Markdown file with custom styles and a table of contents.
const mdpdf = require('mdpdf'); const fs = require('fs'); const options = { source: 'example.md', destination: 'output.pdf', stylesheet: 'styles.css', toc: true }; fs.readFile('example.md', 'utf8', (err, data) => { if (err) throw err; options.sourceContent = data; mdpdf.convert(options).then(() => { console.log('PDF successfully generated'); }).catch((error) => { console.error('Error generating PDF:', error); }); });
With mdpdf, generating customizable PDFs from Markdown has never been easier.
Hash: 9a4f853e5ce1f13baa8a6f0edecb6899a3d4673f8c93e35488899648378ee027