You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are really a lot of issues all about the same of not getting it right with converting html2pdf. So I just roundup what i've found out to move forward, i'm shure it will help others.
Future Fix
There is a new html2pdf command which should be overall better. But at the moment this only ever renders one single page. But I hope @MrRio will find again time to work on it.
Fix outside Repo
Go with deprecated function addHtml.
To enable automatic Page Break add this option: {pagesplit: true} as soon as you enabled this, it will look really worse. make it again better with setting: pdf.internal.scaleFactor = 3.75; Maybe you have to play a bit to find your perfect value.
Blurred & unsharp problems: you have to scale the canvas up example:
varelement=document.getElementById('bod');varpdf=newjsPDF('p','pt','a4');pdf.internal.scaleFactor=3.75;varw=element.clientWidth;varh=element.clientHeight;varnewCanvas=document.createElement('canvas');newCanvas.width=w*2;newCanvas.height=h*2;newCanvas.style.width=w+'px';newCanvas.style.height=h+'px';varcontext=newCanvas.getContext('2d');context.scale(2,2);pdf.addHTML(element,{pagesplit: true,canvas: newCanvas},function(){// var out = pdf.output('dataurlnewwindow'); // crashed if bigger filepdf.save('two-by-four.pdf')});
Fix in Repo
change addHtml function like so:
if(typeofhtml2canvas!=='undefined'&&!options.rstz){// find this lineif(options.retina){varw=element.clientWidth;varh=element.clientHeight;varnewCanvas=document.createElement('canvas');newCanvas.width=w*2;// make the canvas double bignewCanvas.height=h*2;// make the canvas double bignewCanvas.style.width=w+'px';newCanvas.style.height=h+'px';varcontext=newCanvas.getContext('2d');context.scale(2,2);// make it double as bigoptions.canvas=newCanvas;}returnhtml2canvas(element,options);
Usage after Fix in Repo
varpdf=newjsPDF('p','pt','a4');// basic create pdfpdf.internal.scaleFactor=3.75;// play with this valuepdf.addHTML(document.getElementById('bod'),{pagesplit: true,retina: true},function(){// addHtml with automatic pageSplitvarout=pdf.output('dataurlnewwindow');// output format of your pdf -> there are a lot blob, base64....});
Uh oh!
There was an error while loading. Please reload this page.
Problem
There are really a lot of issues all about the same of not getting it right with converting html2pdf. So I just roundup what i've found out to move forward, i'm shure it will help others.
Future Fix
There is a new
html2pdf
command which should be overall better. But at the moment this only ever renders one single page. But I hope @MrRio will find again time to work on it.Fix outside Repo
addHtml
.{pagesplit: true}
as soon as you enabled this, it will look really worse. make it again better with setting:pdf.internal.scaleFactor = 3.75;
Maybe you have to play a bit to find your perfect value.Fix in Repo
addHtml
function like so:Usage after Fix in Repo
More info on getting it sharper are in the html2canvas repo
Keeps beeing a problem (Images)
The image Plugin is really damn slow and stores everything forever. Will Maybe if I have bigger problems it, look into it.
The text was updated successfully, but these errors were encountered: