{"id":3095,"date":"2022-09-12T03:03:27","date_gmt":"2022-09-11T22:03:27","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=3095"},"modified":"2022-09-12T03:03:29","modified_gmt":"2022-09-11T22:03:29","slug":"javascript-html2pdf-js-add-header-footer-to-all-pdf-pages","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/","title":{"rendered":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages"},"content":{"rendered":"\n<p>In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript <code>HTML2PDF.js<\/code> library. The full source code of this project is given below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add Header\/Footer to PDF Pages Using JavaScript HTML2PDF.js<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">index.html<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;Document&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;style&gt;\n    div {\n  outline: red solid 1px;\n  page-break-inside: avoid;\n}\n#nextpage1 {\n  page-break-before: always;\n}\n&lt;\/style&gt;\n&lt;script src=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/html2pdf.js\/0.10.1\/html2pdf.bundle.min.js&quot; integrity=&quot;sha512-GsLlZN\/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA\/HdeKFVgA5v3S\/cIrLF7QnIg==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;\/script&gt;\n\n&lt;body&gt;\n    \n\n&lt;!-- Button to generate PDF. --&gt;\n&lt;button id=&quot;btnTest&quot;&gt;Generate PDF&lt;\/button&gt;\n&lt;div id =&quot;root&quot;&gt;\n\n&lt;div&gt;\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n&lt;\/div&gt;\n&lt;div id=&quot;nextpage1&quot;&gt;\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n&lt;\/div&gt;\n&lt;br&gt;\n\n&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;script&gt;\nhtml2pdf(document.getElementById('root'), {\n    margin: 10,\n    filename: &quot;my.pdf&quot;,\n    image: {type: 'jpeg', quality: 1},\n    html2canvas: {dpi: 72, letterRendering: true},\n    jsPDF: {unit: 'mm', format: 'a4', orientation: 'landscape'},\n    pdfCallback: pdfCallback\n})\n\nfunction pdfCallback(pdfObject) {\n    var number_of_pages = pdfObject.internal.getNumberOfPages()\n    var pdf_pages = pdfObject.internal.pages\n    var myFooter = &quot;Footer info&quot;\n    for (var i = 1; i &lt; pdf_pages.length; i++) {\n        \/\/ We are telling our pdfObject that we are now working on this page\n        pdfObject.setPage(i)\n\n        pdfObject.text(&quot;my header text&quot;, 10, 10)\n\n        \/\/ The 10,200 value is only for A4 landscape. You need to define your own for other page sizes\n        pdfObject.text(myFooter, 10, 200)\n    }\n}\n&lt;\/script&gt;\n&lt;\/html&gt;<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The full source code of this project is given below. Add Header\/Footer to PDF Pages Using JavaScript HTML2PDF.js index.html<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-3095","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages<\/title>\n<meta name=\"description\" content=\"In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-11T22:03:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-11T22:03:29+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages","description":"In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages","og_description":"In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The","og_url":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-09-11T22:03:27+00:00","article_modified_time":"2022-09-11T22:03:29+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages","datePublished":"2022-09-11T22:03:27+00:00","dateModified":"2022-09-11T22:03:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/"},"wordCount":61,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/","url":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/","name":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-09-11T22:03:27+00:00","dateModified":"2022-09-11T22:03:29+00:00","description":"In this tutorial, I will show you how to add a header and footer to each and every page of the PDF document using the JavaScript HTML2PDF.js library. The","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/javascript-html2pdf-js-add-header-footer-to-all-pdf-pages\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript HTML2PDF.js Add Header\/Footer to All PDF Pages"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=3095"}],"version-history":[{"count":1,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3095\/revisions"}],"predecessor-version":[{"id":3096,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3095\/revisions\/3096"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=3095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=3095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=3095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}