Error when trying to display Image
See original GitHub issueI want to display a Logo at the start of the PDF-File but it’s not working. I get this Error:
Uncaught TypeError: Cannot read property ‘nodeType’ of null at jspdf.min.js:1245.
function tbl1ToPDF() {
var base64Img = null;
imgToBase64('[PATH]', function (base64) {
base64Img = base64;
});
var pageContent = function (data) {
doc.setFontSize(10);
doc.addImage(base64Img, 'PNG', data.settings.margin.left, 15, 10, 10);
var str = "[TEXT] " + data.pageCount;
doc.setFontSize(10);
doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10);
};
var currentdate = new Date();
var datetime = currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + "/" + currentdate.getFullYear();
var doc = new jsPDF();
doc.setFontSize(8);
doc.text("[TEXT] " + datetime, 135, 16);
doc.setFontSize(20);
doc.text("[TEXT]", 10, 26);
var elem = document.getElementById("tbl1");
var res = doc.autoTableHtmlToJson(elem);
doc.autoTable(res.columns, res.data, {
addPageContent: pageContent,
startY: 30
});
doc.save("[NAME].pdf");
return doc;
}
This is the imgToBase64 function:
function imgToBase64(url, callback) {
if (!window.FileReader) {
callback(null);
return;
}
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result.replace('text/xml', 'image/jpeg'));
};
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.send();
}
Please help me fix this error. Huge Thanks for this awesome Plugin btw!
EDIT: I also tried to change the line
callback(reader.result.replace('text/xml', 'image/jpeg))'
to
callback(reader.result.replace('text/xml', 'image/png))'
but it’s not working too…
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Error when trying to display an image - Stack Overflow
I have a jQuery code that is supposed to display an image on a button click and to make it disappear on ajax-complete...
Read more >Solved: Error when trying to display user photo and sample...
I have created a company directory using the office365 connector. The app works as expected - lists all active user within my domain...
Read more >401 Unauthorized error when trying to display images on my ...
Hello I'm trying to make a gallery with the images that I have in cloudinary using React. I have checked out the Admin...
Read more >Error 404 in trying to display an image (final project)
Alright I found an answer. The problem is that Flask needs you to place any images you want to display in a specific...
Read more >Unable to display image error - PentaxForums.com
The reason is that Windows can write 'hidden' files to the card, which the camera cannot read. If you are sure all images...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
👍You too!
Your Example looks cool.!!But, How to deal with multiple URLs??