Search code examples
javaitextbatikflying-saucer

Html with embedded svg convert to PDF using Flying saucer Itext batik


I have a requirement to convert all my html reports to PDF.

Its a nodejs application so i cant find any core module which convert html to pdf.

So I use JAVA FLYING SAUCER JAR to convert html to PDF . In that every thing working perfectly apart from embedded svg in html . so i have googling about that i got this tutorial and Stackoverflow link . I am a nodejs developer and have basic knowledge about java . i dont know how to integrate this code with flying saucer.

Please guide me what to do

.

Below command line is used for convert html to pdf using fying saucer.

java -cp flyingsaucer.jar org.xhtmlrenderer.simple.PDFRenderer inpFile.html outFile.pdf

I have the source of flying saucer from github

And i use the jar from child project

flying-saucer-pdf-itext5

use maven to Build and use maven-shade plugin to build a jar with dependency


Solution

  • i resolve it with the help of my friend who work in java.

    First SVG in my example are generated by highchart api javascript.it is bit complicate svg . so the above tutorial not work for me.So i converted all SVG tag to base64 PNG using svg_todataurl.js.

    To generate png base64 in PDF i use the following tutorial. base64 encoder

    If any help need comment below ..