How do I create a PDF from HTML? - html

I am trying to generate a printable version of the HTML page, the printable version should have left pane and top pane stripped off. I tried to generate the printable version using JQuery, it has some layout issues while getting the stripped of content into the print preview screen(which is another stripped off HTML in pop up window).
Is there any ready made open source tool which converts HTML to PDF without much effort, because I have already lost quite a bit of time trying to explore in JQuery
I am using Grid 960 template layout

When you have processed the html, wkhtmltopdf (Windows/Mac/Linux) can convert it to pdf. wkhtmltopdf is a cross-platform, open source (LGPLv3) command line tool to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.
wkhtmltopdf can be downloaded from the official wkhtmltopdf website. It is also in the default repositories of most common Linux distributions.
Examples
Convert a remote HTML file to PDF:
wkhtmltopdf http://www.google.com example.pdf
Convert a local HTML file to PDF:
wkhtmltopdf example.html example.pdf
wkhtmltopdf usage You can also display the wkhtmltopdf help locally by running wkhtmltopdf -H.

why not just use a print stylesheet, and let your users print to PDF if they want to?
http://www.alistapart.com/articles/goingtoprint/

Related

wkhtmltopdf issues rendering bootstrap and angular page

Currently I am trying to convert an angular and bootstrap heavy url using wkhtmltopdf. However, the result of the conversion is simply just a blank pdf with a small rectangle that matches the color of the webpages background. I have a sample output from jsbin I'm using to test angular and bootstrap, and the pdf comes out as intended (http://output.jsbin.com/qucaravupi), only real difference is my sites html requires login and authentication (which I'm using --cookie option to pass in).
Trying to pdf the bootstrap homepage results in sslHandshakeError, so I'm unable to determine if the issue is server side or a result of the page failing to render via wkhtmltopdf. I can use curl to grab the page info from https://getbootstrap.com/css/, but can't use wkhtmltopdf to convert it so I know it's not a redirect problem. Any ideas as to what can be the issue?

JSP/HTML/CSS to PDF generation

Basically a simple question:
In php you have mpdf/tcpdf etc libraries that convert your HTML/CSS as is into a pdf file.
I have now a JSP page from where i open up a popup JSP including kind of a organizational chart with divs created from HTML/CSS. Is it possible that i can just take this whole popup and convert it somehow into a pdf file -> in chrome you have the option of save as pdf -- and that works it creates a pdf file successfully ! But i want the website to create a pdf itself without browser plugin. Is it possible? Does Java/JSP have such an option to convert pure HTML/CSS to pdf?
You could use Wkhtmltopdf to convert from HTML to PDF. https://code.google.com/p/wkhtmltopdf/

Convert html 5 to PDF in MVC 3

I have created an application in asp.net MVC 3, I used highchart.js for rendering chart(stacked column) in view and its output is coming as svg.
I need to convert this chart page into PDF file. I tried iTextSharp but its not showing the chart page content.
Is there anyway to convert html 5 to PDF?
ExpertPDF is a nuget package you can install. For it to work without putting text over your pdf, you'll have to purchase a license. It can handle svg.
http://www.html-to-pdf.net/ExpertPDF-HtmlToPdf-Converter.aspx
You can also use a webkit component such as HTM2PDF to render HTML to PDF - see an explanation here:
Highcharts to PDF with Webkit
If you just want to convert svg to image then you can use PhantomJS (headless webkit browser). With help of PhantomJS you can render svg and make screenshot. Then you can create a PDF and insert that image into it.
Also you can Aspose.Pdf for converting svg into PDF directly. See: http://www.aspose.com/.net/pdf-component.aspx (it's a paid component!)

HTML Printing using Gecko or Webkit engine

Is there a way where I can directly print html file or url without invoking any dialogs in .NET?
Yes. Try this program: http://cutycapt.sourceforge.net/. It will allow you to generate an image (or pdf) of a web page. Once you have that there are a variety of ways to print it. For example: Print existing PDF (or other files) in C#.

PdfSharp, GDI+ and HTML printing

I currently have a "PrintingWebService" that I call from an AJAX page with all the information that is needed to construct a highly customized PDF printout using PDF Sharp and the PDFSharp's GDI+ mode, which takes DrawString and other commands that work basically just like GDI+ only they are drawn to the PDF.
I then save the PDF file to a location on the webserver and return the file name from the web service, and the AJAX page opens a new window with the pdf file.
So far, it works well, however, there is one part of my AJAX page that I want to printout and I haven't come up with a solution for yet. I've got a string of the HTML content of a TinyMCE editor that I want to dispay in the bottom part of the PDF page.
I'm looking for some sort of tool I could use for this purpose. Even something opensource that prints to GDI+ I could use by taking the source code and translating it to use PdfSharp's GDI+ (the class names are like XGraphics, with each class having X before the GDI+ name).
If I have to I will limit what HTML can be generated by TinyMCE and write my own renderer, but that will be a big challenge, so I'm looking for other solutions first.
I've stayed away from a printer-friendly page approach because I wanted to construct a page that was a near identical of an existing WinForms printout, using my existing code. With PdfSharp I was able to convert all the code except the text area stuff (which used the RichTextBox and RTF in the WinForms version).
Tony,
I personally have used WebSupergoo's ABCPdf library with much success. You can actually render HTML directly to the PDF and it does fairly well in regards to accuracy.
Another free software that will allow you the flexibility of writing HTML to PDF that I have used in the past with much success is iTextSharp.
Otherwise, I think you'll have to write something to render HTML to GDI.
Either way, you may want to consider using an HttpHandler that you map to using your web.config to generate the PDF file. This will allow for you to render the PDF to a bytestream and then dump it directly to the user (as opposed to having to save each PDF receipt to the web server). It will also allow for you to use the .pdf extension in the page that returns the receipt (PurchaseReceipt.pdf could be mapped to a HttpHandler)... making it more cross-browser friendly. Older versions of Adobe / Browsers will not display correctly if you start throwing a PDF byte stream from an ASPX page.
Hope this helps.