I am trying to export the value of a textarea
let text = document.getElementById("textarea").value
as a PDF. I am using jsPDF. My first try was:
function createPDF(){
let text = document.getElementById("textarea").value;
var doc = new jsPDF();
doc.text(20, 20, text);
doc.save('document.pdf');
}
However, even though with this method a pdf is created, the pdf is not created with a “scroll bar view”, it only prints 1 line basically.
My second try was:
function createPdf() {
let text = document.getElementById("textarea").value;
// let titolo = document.getElementById("input-fileName").value;
var doc = new jsPDF();
var splitText = doc.splitTextToSize(text, 250);
var pageHight = doc.internal.pageSize.hight;
doc.setFontSize(11);
var y = 20;
for(var i = 0; i < splitText.length; i++){
if (y > 275){
y = 20;
doc.addPage();
}
doc.text(20, y, splitText[i]);
y = y + 5
}
doc.save(title + '.pdf');
}
However with this method a pdf is not even created 🙁
So I tried using html2pdf as following:
function createPdf(){
var element = document.getElementById('textarea');
element.style.width = '800px';
element.style.height = '1000px';
html2PDF().from(element).toPdf().save('ilmiopdf.pdf');
}
This method also produces no pdf.
Anyone have suggestions? Cause i’m going crazy.