Get started with pdfmake CDN

MIT licensed

Library: PDFMake creates PDFs from HTML or sources.

Tags:
  • pdf
  • javascript
  • printing
  • layout

Stable version

Copied!

How to start using pdfmake CDN


const pdfMake = { getDocument: () => {} }; // Create an empty PDFMake object

// Load the PDFMake library from the CDN
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/pdfmake/0.2.10/pdfmake.min.js';
document.head.appendChild(script);

script.onload = () => {
  // Once the library is loaded, replace the empty object with the actual PDFMake instance
  pdfMake = window.pdfMake;

  // Create a document with a single page and a text element
  const docDefinition = {
    content: [
      { text: 'Hello World!', alignment: 'center' },
    ],
    layout: {
      width: 210,
      height: 297,
    },
  };

  // Create a PDF from the document definition
  pdfMake.getDocument(docDefinition).then((doc) => {
    // Download the generated PDF
    doc.download('hello_world.pdf');
  });
};
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions