PDFMake.js Example to Insert Table of Contents With Subheadings in PDF Document Using Javascript Full Project For Beginners

 

 

index.html

 

 

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>PDFMake</title>
</head>

<body>

</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.70/pdfmake.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.70/vfs_fonts.js"></script>
<script>
  // playground requires you to assign document definition to a variable called dd

  var docDefinition = {
  content: [
    {
      toc: {
        id: 'mainToc',
        title: {text: 'INDEX', style: 'header'}
      },
      toc: {
        id: 'subToc',
        title: {text: 'SUB INDEX', style: 'header'}
      }
    },
    {
      text: 'This is a header',
      style: 'header',
      tocItem: ['mainToc', 'subToc']
    }
  ]
}
  pdfMake.createPdf(docDefinition).download();
</script>

</html>

Leave a Reply