2

Is there a way to generate a PDF file in JavaScript out of a given rendered and styled element of a webpage and its content? Is there already a library for this?

danijar
  • 32,406
  • 45
  • 166
  • 297

2 Answers2

-1

I've never put it to use, but could https://github.com/thebluber/htmlToPdf be what you're looking for?

Crusty Smith
  • 65
  • 2
  • 11
-1

There is a library called jsPDF. It provides basic functionality to create PDF documents. It even comes with a plugin to add elements from basic HTML.

danijar
  • 32,406
  • 45
  • 166
  • 297
  • @Toolkit It's the best I'm aware of. If you found a better solution, please let me know. For now I'll stick with providing a print style cheet that hides everything else and use the browser's print to PDF functionality. – danijar Jul 28 '15 at 11:39
  • but the question was about "styled element". There is dompdf but it requires PHP – Toolkit Jul 28 '15 at 12:10
  • @Toolkit Right, there a couple of server-side solutions for that. The challenge is to get it done on the client-side. By the way, it was me who asked the question. – danijar Jul 28 '15 at 19:27
  • I know this is your question, but the answer doesn't answers the question, because jsPDF ignores styles – Toolkit Jul 29 '15 at 01:32
  • @Toolkit I agree, it's not a complete answer to the question. Fair enough. – danijar Jul 29 '15 at 02:03