Merge pull request #168 from Idadelveloper/add/pdf-export

Export an article to pdf
This commit is contained in:
Somrat Sorkar 2021-08-30 17:23:58 +06:00 committed by GitHub
commit 6f171c42be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View file

@ -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);

View file

@ -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 }}

View file

@ -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{