You need to sign in to do that
Don't have an account?
Maguy Fogaing 2
change my blob url to data url
Hello everyone,
l used the librairy Jspdf to download my html as a pdf in LWC component as below :
const {jsPDF} = window.jspdf;
let doc = new jsPDF('p', 'pt', 'A4');
doc.addFileToVFS('Muli-normal.ttf', helper.getFontCode());
doc.addFont('Muli-normal.ttf', 'Muli', 'bold');
doc.setFont('Muli','bold');
doc.text(210,25,'titleofdocument');
doc.autoTable({
margin: {top: 65},
styles: {font: "Muli"},
headStyles:{fillColor:'#E30613'},
head: [['title1', 'title2', 'title3','title4', 'title5']],
body: this.allelements,
}).save('titleofdocument.pdf');
The problem is when l download the pdf it's give me an url as Blob://htpps:Name_of_the_site which cause me some problems in my application mobile version. So please l need help to change this url Blob as data url like this data:application/pdf;base64.
Please propose me other ways to download my html as a pdf in LWC so that l can obtain a data url instead of a blob url.
It's urgent l am struggling with this for a week now.
Thank you in advance.
l used the librairy Jspdf to download my html as a pdf in LWC component as below :
const {jsPDF} = window.jspdf;
let doc = new jsPDF('p', 'pt', 'A4');
doc.addFileToVFS('Muli-normal.ttf', helper.getFontCode());
doc.addFont('Muli-normal.ttf', 'Muli', 'bold');
doc.setFont('Muli','bold');
doc.text(210,25,'titleofdocument');
doc.autoTable({
margin: {top: 65},
styles: {font: "Muli"},
headStyles:{fillColor:'#E30613'},
head: [['title1', 'title2', 'title3','title4', 'title5']],
body: this.allelements,
}).save('titleofdocument.pdf');
The problem is when l download the pdf it's give me an url as Blob://htpps:Name_of_the_site which cause me some problems in my application mobile version. So please l need help to change this url Blob as data url like this data:application/pdf;base64.
Please propose me other ways to download my html as a pdf in LWC so that l can obtain a data url instead of a blob url.
It's urgent l am struggling with this for a week now.
Thank you in advance.
Hi
You can use doc.output('datauristring') or doc.output('datauri') instead of doc.save.
All Answers
Hi
You can use doc.output('datauristring') or doc.output('datauri') instead of doc.save.
Your answer helps me to get the data url, but l am not able to download the pdf. l use your answer like this :
doc.autoTable({
margin: {top: 65},
styles: {font: "Muli"},
headStyles:{fillColor:'#E30613'},
head: [['title1', 'title2', 'title3','title4', 'title5']],
body: this.allelements,
}).output('datauristring');
But still don't download the pdf. Please can you propose me any solution to download pdf with doc.output('datauristring') ?
Thank you in advance.
Hi
can you try this code
doc.output('dataurlnewwindow');
mark this as best answer is it's help you.
Thanks
Please needs helps to fix this issue
Try this
window.open(URL.createObjectURL(doc.output("blob")))
var string = doc.output('datauristring');
var x = window.open();
x.document.open();
x.document.location=string;