HTML2PDF with JavaScript

A little bit of HTML and JavaScript is enough to create a „Download PDF“-button with HTML2PDF on every page of your website. Find an online example here:

At first this JavaScript function must be implemented:

function getPdf(inline,url){
	if(!url) url=document.location.href;
	var param={
		'url'		:	url,
		'plain'		:	'1',
		'filename'	:	(!inline)?url.replace(/[^a-z|0-9|-|_]/ig,'_').replace(/_{2,}/g,'_')+'.pdf':''
	var temp=[];
	for(var key in param)

Then you can use this function like this in HTML:

<a href="javascript:getPdf();">Download PDF</a>

To make it possible to download the PDF even if JavaScript is disabled, the link should be created with JavaScript and you should insert this NoScript-block:

<noscript><a href="">Download PDF</a></noscript>