0

I am trying to convert a dom element to Blob, which I want to use later for sending the same as attachment(as pdf). The code for the same is as following:

Dom element:

<div id="dom-container">
   Dom container
</div>

Code for dom to blob conversion: (in order to check the conversion, I am downloading as PDF)

const blobData = new Blob([document.getElementById('dom-container')], {type: "text/html"});
const a = document.createElement("a");
const object_URL = URL.createObjectURL(blobData);
a.href = object_URL;
a.download = 'file.pdf';
a.click();
URL.revokeObjectURL(object_URL);

After opening the file.pdf, getting the below error: enter image description here

Can someone please help me to figure out where is the issue while this dom to blob/pdf conversion.

Thanks in advance.

5
  • First off, PDFs are not HTML files. Secondly, you made a blob of a dom element, not its innerHTML. Commented Apr 10, 2021 at 4:59
  • @John Thanks for the comment. I tried with innerHTML as well but it didn't worked. Any way to make this work ? Commented Apr 10, 2021 at 5:19
  • Use pdf.js and understand how it works. Commented Apr 10, 2021 at 5:34
  • stackoverflow.com/questions/25734072/… Commented Apr 10, 2021 at 6:17
  • @MatthewCook0485 Already tried with the solution but it didn't worked. The issue is related to pdf conversion/rendering Commented Apr 10, 2021 at 11:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.