question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSPDF doesn't add images with online src

See original GitHub issue

In a web application I’m using JSPDF to convert the html to pdf. All works fine, except for the images. After a while, I noticed that it adds images that point to a local resource; instead, it does not add images that point to an online resource, and leaves in the place of the image an empty space, as if he expected it but could not load it.

For example: <img src="img/house.jpg"/> is correctly added. <img src="https://myurl.com/house.jpg"/> is not correctly added; there is an empty space instead of the image.

P.S. I’m using doc.addHTML().

How can I solve it? Maybe store the image temporarily in local? I tried using addImage() but it is very hard to use, not only because I change the scale factor of pdf, but primarily because the content of the pdf is dynamic, and I do not know what size the images will have or their exact position.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
panagulis72commented, Jan 6, 2018

No it isn’t. Or however I don’t guess so, because I can see the image in the html code and in the browser.

But, maybe, I found a solution or a workaround though. I used this online service (https://www.askapache.com/online-tools/base64-image-converter/) just for test. I converted the url of the image to base64 and I overwritten the src=“https://…” with src=“base64…” and it works!

0reactions
gauravsoftuvocommented, Nov 2, 2022

@Uzlopak Base64 solution works fine for static images, but, I becomes a problem while dealing with dynamic data. Can you please open this ticket as we would love to have a sustainable solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSPDF doesn't add images with online src #1578 - GitHub
In a web application I'm using JSPDF to convert the html to pdf. All works fine, except for the images. After a while,...
Read more >
JSPDF doesn't add images with online src - Stack Overflow
All works fine, except for the images. After a while, I noticed that it adds images that point to a local resource; instead,...
Read more >
HTML : JSPDF doesn't add images with online src - YouTube
HTML : JSPDF doesn't add images with online src [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] HTML : JSPDF doesn't ...
Read more >
html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF. :warning: There have been several issues ...
Read more >
CanvasRenderingContext2D.drawImage() - Web APIs | MDN
An element to draw into the context. The specification permits any canvas image source, specifically, an HTMLImageElement , an SVGImageElement , ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found