{"id":2086,"date":"2022-07-06T13:32:43","date_gmt":"2022-07-06T08:32:43","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2086"},"modified":"2022-07-06T13:32:46","modified_gmt":"2022-07-06T08:32:46","slug":"jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/","title":{"rendered":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">index.html<\/h2>\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;body&gt;\n  &lt;div id=&quot;total&quot; class=&quot;demo-container&quot;&gt;\n    &lt;div id=&quot;placeholder&quot; style=&quot;height: 300px; width: 900px;&quot;&gt;&lt;\/div&gt;\n    &lt;div id=&quot;placeholder_2&quot; style=&quot;height: 300px; width: 900px;&quot;&gt;&lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;a id=&quot;generate&quot;&gt;Generate&lt;\/a&gt;\n&lt;\/body&gt;\n&lt;script src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js&quot;&gt;&lt;\/script&gt;\n\n&lt;script&gt;\n    $(function() {\n    flot1();\n    flot2();\n  });\n\n  function flot1() {\n    var plot;\n    plot = $.plot($(&quot;#placeholder&quot;), [{\n      label: 'Test',\n      data: [\n        [0, 0],\n        [1, 1]\n      ]\n    }], {\n      yaxis: {\n        max: 1\n      }\n    });\n  }\n\n  function flot2() {\n    var oilPrices = [\n      [1167692400000, 61.05],\n      [1167778800000, 58.32],\n      [1167865200000, 57.35],\n      [1167951600000, 56.31],\n      [1168210800000, 55.55],\n      [1168297200000, 55.64],\n      [1168383600000, 54.02],\n      [1168470000000, 51.88],\n      [1168556400000, 52.99],\n      [1168815600000, 52.99],\n      [1168902000000, 51.21],\n      [1168988400000, 52.24],\n      [1169074800000, 50.48]\n    ];\n\n    var exchangeRates = [\n      [1167606000000, 0.7580],\n      [1167692400000, 0.7580],\n      [1167778800000, 0.75470],\n      [1167865200000, 0.75490],\n      [1167951600000, 0.76130],\n      [1168038000000, 0.76550],\n      [1168124400000, 0.76930],\n      [1168210800000, 0.76940],\n      [1168297200000, 0.76880],\n      [1168383600000, 0.76780],\n      [1168470000000, 0.77080],\n      [1168556400000, 0.77270],\n      [1168642800000, 0.77490],\n      [1168729200000, 0.77410],\n      [1168815600000, 0.77410],\n      [1168902000000, 0.77320],\n      [1168988400000, 0.77270],\n      [1169074800000, 0.77370],\n      [1169161200000, 0.77240],\n      [1169247600000, 0.77120]\n    ];\n    var data = [{\n      data: oilPrices,\n      label: &quot;Oil price ($)&quot;\n    }, {\n      data: exchangeRates,\n      label: &quot;USD\/EUR exchange rate&quot;,\n      yaxis: 2\n    }];\n\n    var options = {\n      canvas: true,\n      xaxes: [{\n        mode: &quot;time&quot;\n      }],\n      yaxes: [{\n        min: 0\n      }, {\n        position: &quot;right&quot;,\n        alignTicksWithAxis: 1,\n        tickFormatter: function(value, axis) {\n          return value.toFixed(axis.tickDecimals) + &quot;\u20ac&quot;;\n        }\n      }],\n      legend: {\n        position: &quot;sw&quot;\n      }\n    }\n\n    plot = $.plot(&quot;#placeholder_2&quot;, data, options);\n  }\n  \/\/----------------------------------------------------\n  $(&quot;#generate&quot;).on(&quot;click&quot;, function(e) {\n\n    e.preventDefault();\n\n    var p1 = new Promise(function(resolve, reject) {\n      var element = $(&quot;#placeholder&quot;).get(0);\n      html2canvas(element, {\n        onrendered: function(canvas) {\n          resolve(canvas.toDataURL('image\/png'));\n        }\n      });\n    });\n\n\n    var p2 = new Promise(function(resolve, reject) {\n      var element = $(&quot;#placeholder_2&quot;).get(0);\n      html2canvas(element, {\n        onrendered: function(canvas) {\n          resolve(canvas.toDataURL('image\/png'));\n        }\n      });\n    });\n\n    Promise.all([p1, p2]).then(function(screens) {\n      var doc = new jsPDF();\n      doc.addImage(screens[0], 'PNG', 10, 10, 180, 115);\n      doc.addPage();\n      doc.addImage(screens[1], 'PNG', 10, 10, 180, 60);\n      doc.save('sample-file.pdf');\n\n    });\n  });\n\n&lt;\/script&gt;\n&lt;\/html&gt;<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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-2086","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript<\/title>\n<meta name=\"description\" content=\"index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta\" \/>\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\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript\" \/>\n<meta property=\"og:description\" content=\"index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-06T08:32:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-06T08:32:46+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":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript","description":"index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta","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\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript","og_description":"index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta","og_url":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-06T08:32:43+00:00","article_modified_time":"2022-07-06T08:32:46+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\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript","datePublished":"2022-07-06T08:32:43+00:00","dateModified":"2022-07-06T08:32:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/"},"wordCount":17,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#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\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/","url":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/","name":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-07-06T08:32:43+00:00","dateModified":"2022-07-06T08:32:46+00:00","description":"index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#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\/jspdf-html2canvas-project-export-html-with-multiple-graphs-plotted-to-pdf-document-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"jsPDF Html2Canvas Project: Export HTML With Multiple Graphs Plotted to PDF Document in JavaScript"}]},{"@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:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","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\/2086","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=2086"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2086\/revisions"}],"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=2086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}