Reputation: 309
Here is my code:
<script type="text/javascript">
var url = 'localhost:8080/chartGenerator';
function myFunction() {
var docDef={ content: [
'This is an sample PDF printed with pdfMake',
{
image: getBinaryResource(url)
}
]
}
pdfMake.createPdf(docDef).download('optionalName.pdf');
}
function getBinaryResource(url){
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null);
if (req.status == 200) {
return req.responseText.replace(/^data:image\/(png|jpg);base64,/, "");
} else return null
}
</script>
I need to generate a pdf document with an image that I get from the server, but I have the following error :TypeError: r is undefined.
Could you help me to resolve this issue.
Upvotes: 2
Views: 3266
Reputation: 309
As @AndréKool pointed out removing ".replace(/^data:image/(png|jpg);base64,/, "");" solved it.
This part is needed so pdfmake can recognise it as a base64 image format.
Upvotes: 1