I’m using React-quill as a text editor. I want to convert the content from it that includes images into a pdf. Below is the string, I’m getting from editor.
<p>sdfghj<img src="data:image/jpeg;base64,/9j/4AAQ…r5izLn+Jucfh7Vo6p/r7j6j+VZl595P97/CgD//2Q=="></p>
I’ve used jsPDF but it’s only converting plain text into a pdf. If I put an image into the text editor, pdf is showing blank. How do I convert text with more than one images into a pdf?
Note: In the image src, the image is in base64 format.
2
Answers
You can use html2canvas library
hope this helps
Here is an approach you can follow using
html2canvas
andjspdf
. I am using the element reference (useRef, the react way) instead of document.getElementById.For some reason, it was having some issues using third-party images even after setting the CORS flag in html2canvas. But here is a working implementation using a local image
Main:
ElementToPDF: