Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gethugothemes/dot-hugo-documentation-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSomrat Sorkar <37659754+somratpro@users.noreply.github.com>2021-08-30 14:23:58 +0300
committerGitHub <noreply@github.com>2021-08-30 14:23:58 +0300
commit6f171c42be6c480568c16f0f3235ed3fc7d2c296 (patch)
tree18fe44ad369e5bcd9a6ba236569ec631805a5eac
parentdead996a5319fcec07fa69880761e717c54446ad (diff)
parent0fb604c43aadd8a237848280a550103f823ff13e (diff)
Merge pull request #168 from Idadelveloper/add/pdf-export
Export an article to pdf
-rw-r--r--assets/js/script.js19
-rw-r--r--layouts/partials/default.html11
-rw-r--r--layouts/partials/head.html4
3 files changed, 32 insertions, 2 deletions
diff --git a/assets/js/script.js b/assets/js/script.js
index e8e111e..b53232d 100644
--- a/assets/js/script.js
+++ b/assets/js/script.js
@@ -127,4 +127,23 @@
$(this).removeClass('active')
})
+
+ // Download page to pdf format
+ window.onload = function() {
+ document.getElementById("generatePDF")
+ .addEventListener("click", () => {
+ const content = this.document.getElementById("content");
+ console.log(content);
+ console.log(window);
+ var opt = {
+ margin: 1,
+ filename: document.querySelector('#title').innerHTML,
+ image: { type: 'jpeg', quality: 0.98 },
+ html2canvas: { scale: 2 },
+ jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
+ };
+ html2pdf().from(content).set(opt).save();
+ })
+ }
+
})(jQuery); \ No newline at end of file
diff --git a/layouts/partials/default.html b/layouts/partials/default.html
index b60b3cb..7614269 100644
--- a/layouts/partials/default.html
+++ b/layouts/partials/default.html
@@ -12,12 +12,19 @@
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode}}
{{ end }}
{{ end }}
+ {{ if .Content }}
+ {{ if eq .Params.downloadBtn "true" }}
+ <div>
+ <button class="btn btn-primary btn-block" id="generatePDF" > Get Pdf </button>
+ </div>
+ {{ end }}
+ {{ end }}
</ul>
</div>
</div>
<div class="col-lg-9">
- <div class="p-lg-5 p-4 bg-white">
- <h2 class="mb-5">{{ .Title }}</h2>
+ <div class="p-lg-5 p-4 bg-white" id="content">
+ <h2 class="mb-5" id="title">{{ .Title }}</h2>
{{ if .Content }}
<div class="content">{{.Content}}</div>
{{ else }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index e3693d7..b808548 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -18,6 +18,10 @@
{{ "<!-- fonts -->" | safeHTML }}
<link href="https://fonts.googleapis.com/css?family={{replace .Site.Params.font_family ' ' '+' | title}}:300,400,700&display=swap" rel="stylesheet">
+
+ {{ "<!-- PDF.js -->" | safeHTML }}
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.9.359/pdf.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.3/html2pdf.bundle.js"></script>
<style>
:root{