Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html function not working in Node.js environment #2970

Closed
mountiny opened this issue Oct 20, 2020 · 4 comments
Closed

Html function not working in Node.js environment #2970

mountiny opened this issue Oct 20, 2020 · 4 comments

Comments

@mountiny
Copy link

I am trying to render a html data into PDF which is generated on server side. Adding image or just text work well, but html function seems to not do anything. The callback is not even run as I dont get a console log output from it.

Below is my code. Thank you for any help suggestions if I am doing anything wrong. I know this is library primarly to be used on frontend, but I found that since version 2 it should work on backend as well.
`
const doc = new jsPDF('p', 'cm', [29.7, 21]);

  doc.text(1, 1, 'Hello world!');
  doc.html(
    '<div>Hello</div>',
    {
      callback: (pdf) => {
        console.log('Callback')
        pdf.save()
      },
      x: 1,
      y: 1,
      jsPDF: doc
    }
  )
  doc.save()`

And my paykage.json:
"btoa": "^1.2.1", "canvas": "^2.6.1", "dompurify": "^2.0.12", "exceljs": "^4.1.1", "html2canvas": "^1.0.0-rc.5", "jspdf": "^2.1.1",

@HackbrettXXX
Copy link
Collaborator

Yes. Html2canvas requires a working DOM implementation. See also #2805 (comment) and following comments.

@mountiny
Copy link
Author

@HackbrettXXX Thank you for response. That example does not work tho, the call back is not called and the document generated after calling the html function is not changed.

@HackbrettXXX
Copy link
Collaborator

What I meant to say is: the html function can't work in a node environment, because it requires a complete DOM implementation. The jsdom package does not provide all required functionality.

@mountiny
Copy link
Author

@HackbrettXXX Thank you for the clarification and your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants