forked from TrueCloudLab/dot-hugo
Add function to download pdf and download based the downloadBtn parameter
A new taxonomy for the download button should be added in the base configuration file. eg downloadable = "downloadBtn" When this downloadBtn is added in the front matter of any of the content files, it will be displayed. eg downloadBtn: "true" Adding it to the archetypes and setting it to false by default be awesome. Signed-off-by: Ida Delphine <mida@unicef.org>
This commit is contained in:
parent
e3ca0791cd
commit
0fb604c43a
2 changed files with 24 additions and 3 deletions
|
@ -127,4 +127,23 @@
|
||||||
$(this).removeClass('active')
|
$(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);
|
})(jQuery);
|
|
@ -13,9 +13,11 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .Content }}
|
{{ if .Content }}
|
||||||
<div>
|
{{ if eq .Params.downloadBtn "true" }}
|
||||||
<button class="btn btn-primary btn-block" id="generatePDF" > Get Pdf </button>
|
<div>
|
||||||
</div>
|
<button class="btn btn-primary btn-block" id="generatePDF" > Get Pdf </button>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue