Convert html to pdf

I am trying to convert html to pdf from linux, also I have to use this in web APP, please let me know what tools are available for this. Please let me know any other tools for this.

So far i tried

    html2ps htmlfilename > a.ps
    ps2pdf a.ps > a.pdf

But the above does not convert images and ignores css. My development environment is linux (RHEL5)

Also I tried http://www.webupd8.org/2009/11/convert-html-to-pdf-linux.html I got this error

  [root@localhost bin]# ./wkhtmltopdf www.example.com a.pdf
  ./wkhtmltopdf: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory
+3
source share
3 answers

: wkhtmltopdf - . , ( , ); ( , QT ).

, - libqt4-webkit-dev .

+4

, HTML + CSS pdf,

1) Jspdf javascript html2canvas (-).

  • jspdf.

    var script = document.createElement('script'); script.type = 'text/javascript'; script.src ='https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.min.js'; document.head.appendChild(script);

  • html2canvas

    var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js'; document.head.appendChild(script);

  • script

    var html2obj = html2canvas($('your div class here')); var queue = html2obj.parse(); var canvas = html2obj.render(queue);
    var img = canvas.toDataURL("image/jpg"); console.log(img);
    var doc=new jsPDF("p", "mm", "a4"); var width = doc.internal.pageSize.width;
    var height = doc.internal.pageSize.height; doc.addImage(canvas, 'JPEG', 15, 35, 180, 240,'SLOW'); doc.save("save.pdf");

  • IE 11

    document.getElementById("your div here").style.backgroundColor = "#FFFFFF";

2) wkhtmltopdf

  • wkhtmltopdf

  • wkhtmltopdf /commandLine. java- wrapper, .

  • wkhtmltopdf-

    import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf; import com.github.jhonnymertz.wkhtmltopdf.wrapper.page.PageType; import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param; public class PofPortlet extends MVCPortlet {
    @Override public void render(RenderRequest request , RenderResponse response) throws PortletException , IOException
    { super.render(request, response); Pdf pdf = new Pdf();
    pdf.addPage("http://www.google.com", PageType.url); // Add a Table of contents pdf.addToc(); // The "wkhtmltopdf" shell command accepts different types of options such as global, page, headers and footers, and toc. Please see "wkhtmltopdf -H" for a full explanation. // All options are passed as array, for example: // Save the PDF try { pdf.saveAs("E:\\output.pdf"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

3) phantom.js, itextpdf, grabz.it

0

Probably the easiest way would be to launch any modern browser, go to the site, and then use the "print" function of the browser to print in pdf format (provided that your system is equipped with a PDF printer). I do not know if this option will be in your case, and this kind of thing will not work from a web application. However, you can try.

-1
source

All Articles