0

I have SVG images, and lot of text with inline CSS, in an HTML page. I need to export all of them into PDF. Suggest to me proper technology which caters to my need. I am using JavaScript and jQuery as front end and Python as backend.

UPDATE:

I have tried jsPDF, but it is not preserving the CSS styling and I am not able to export images also.

freginold
  • 3,640
  • 3
  • 11
  • 26
SBN AB
  • 121
  • 1
  • 12
  • Possible duplicate of [Generate pdf from HTML in div using Javascript](https://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript) – Cristyan Aug 22 '17 at 18:18
  • @Cristyan that package will not preserve the css styling while exporting as PDF – SBN AB Aug 22 '17 at 18:29
  • 1
    @freginold i have tried jsPdf, but it is not preserving the CSS styling and i am not able to export images also – SBN AB Aug 22 '17 at 18:31

2 Answers2

0

If you want to do it server-side, there's a python package for that:

Otherwise, you can do it in the browser but you will loose the CSS. jsPDF appears to have experimental support for converting HTML to a PDF, or you can programmatically populate a PDF document with similar content. SVG is supported via plugin.

Demo:

Github:

nym
  • 420
  • 1
  • 7
  • 21
  • will that package preserves the HTML css styling while exporting to PDF – SBN AB Aug 22 '17 at 18:28
  • 1
    jsPDF doesn't seem able to handle more than basic CSS. See [this issue](https://github.com/MrRio/jsPDF/issues/1384) for more detail. – freginold Aug 22 '17 at 18:41
  • jsPDF is not a great option if you want to preserve CSS. If you can do it server-side, I recommend that. I edited the post with a server-side option. – nym Aug 22 '17 at 19:17
0

Do you know the wkhtmltopdf command line tools? I was in a project where I also needed to convert a web page to PDF and I used this library (I used PHP as backend) and it worked very well for me.

I hope I have helped :D