Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@ezpaarse-project/jspdf-md
Advanced tools
Generate Markdown pages with JavaScript
This jsPDF plugin adds the ability to render Markdown by using jsPDF functions and not using any HTML. So there's no dependency to Puppeteer or any headless browser.
npm i -S jspdf @ezpaarse-project/jspdf-md
Checkout examples in example folder.
import jsPDF from 'jspdf';
import '@ezpaarse-project/jspdf-md';
const doc = new jsPDF({
unit: 'px', // Currently not supporting other units
hotfixes: ['px_scaling'], // Needed if unit is "px", see https://github.com/parallax/jsPDF/blob/master/HOTFIX_README.md#px_scaling
});
doc.mdToPDF('# Hello world !')
.then(() => doc.save('markdown.pdf'));
// Or use returned value :
doc.mdToPDF('# Hello world !')
.then((pdf) => pdf.save('markdown.pdf'));
import jsPDF from 'jspdf';
import mdToPDF from '@ezpaarse-project/jspdf-md';
const doc = new jsPDF({
unit: 'px', // Currently not supporting other units
hotfixes: ['px_scaling'], // Needed if unit is "px", see https://github.com/parallax/jsPDF/blob/master/HOTFIX_README.md#px_scaling
});
mdToPDF(
doc,
'# Hello world !',
).then(() => doc.save('markdown.pdf'));
import jsPDF from 'jspdf';
import { Parser } from '@ezpaarse-project/jspdf-md';
const remoteRequestor = async (url, method) => {
const request = await fetch(url, { method });
return {
data: await request.arrayBuffer(),
headers: Object.fromEntries(request.headers.entries()),
};
};
const pdfDoc = new jsPDF({
unit: 'px', // Currently not supporting other units
hotfixes: ['px_scaling'], // Needed if unit is "px", see https://github.com/parallax/jsPDF/blob/master/HOTFIX_README.md#px_scaling
});
// Parse Markdown
const parser = new Parser(md);
parser.parse()
// Load images found during parse
.then((mdDoc) => pdfDoc.loadImages(remoteRequestor, 'assetsDir'))
// Render into PDF
.then(() => {
mdDoc.render(pdfDoc);
pdf.save('markdown.pdf')
})
Below is a list of all options supported in the plugin
These options are common to all the usages and are all optional.
pageBreak: boolean
- Should create a new page if an element is overflowingcodeFont: string
- Font used when rendering a code element. By default it's Monospace
(included in the lib)These options aren't available when using directly the parser, but these are all optional.
remoteRequestor: (...args) => object
- The function used to fetch images
url: args[0].string
- The url of the ressourcemethod: args[0].string
- The method used to get the ressourceresponse: object
response.data: ArrayBuffer
- The data of the ressourceresponse.headers: Record<string, string>
- Headers of the responsemargin: number | MarginOption
- Margin between markdown and limit of page. If a number is provided, it's apply to all directions
MarginOption
: { top?: number, left?: number, bottom?: number, right?: number}
Contributions are always welcome, especially on open issues. If you have something major you want to add or change, please post an issue about it first to discuss it further. The workflow for contributing would be something like this:
npm run dev
If you don't use ESLint auto-fix on save, please run npm run lint
before opening your PR
FAQs
jsPDF plugin for rendering MD into PDF in Node
We found that @ezpaarse-project/jspdf-md demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.