For a project I'm working on I need to generate a pdf with the logo of the company. For this, I'm using the jspdf library in Angular 2.
The addImage()
requires a base64
string. I'm not quite sure if this is the way to go, but this is my code:
let imageURL = 'data:image/png;base64,' + btoa('../../public/img/logo2.png');
this.pdf.addImage(imageURL, 'PNG', 50, 50, 50, 50);
This would give the following error:
Incomplete or corrupt PNG file
When I add console.log(imageURL)
and I copy the result to the adres bar, instead of the image I'm trying to open a transparant image, like this example.
If I drag the image into this site and convert the image to a base64 string there, it does give me a working dataUrl
.
So my essential question is, how can I convert a image to a base64 string, preferably without having to install a library.