9

I'm facing an issue trying to add my website export to PDF function.

When browsing the net, i found some solution, but non of them is just printing the page as is to PDF.

http://parall.ax/products/jspdf can't take pure html and make it into pdf file.

I know there is many questions regarding the issue, but there is no one clear answer to the question: Is it possible to export html content to PDF from client side.

if it's possible i will be glad to know how.

if not please suggest how should i do it from server side (java / php / node.js) .

please note that the page contains highcharts charts and images: you can have a look in here:

http://angularjs.liadlivnat.com:8080/campaign

Liad Livnat
  • 7,435
  • 16
  • 60
  • 98
  • possible duplicate of [Generate pdf from HTML in div using Javascript](http://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript) – Himanshu Tyagi Jul 17 '14 at 06:37
  • @thecbuilder well this is not duplicated cause jsPDF doesn't solve this issue – Liad Livnat Jul 17 '14 at 06:53
  • Ah no, I reread you question and looked at the fancy angular-graphomatic-page, Nothing will turn all that html into a pdf. You will have to keep it much more simple, and you're only library even close is domPDF as they support the most current CSS of the lot. Or I would consider something like phantomJS to headlessly create a "png" out of the graphic intensive stuff. – Dylan Jul 17 '14 at 07:15
  • With all that SVG, D3 or whatever, I think you have no choice but to create images prior to assembling any PDF. So I'm actually pretty convinced that something like "phantomjs" is your only real option here, assuming it will even handle all the complexity of the js going on. It's all V8, webkit etc, so it should - but just headless rendering the graphs to a 'png' would be my first test. – Dylan Jul 17 '14 at 07:33

2 Answers2

2

This is a nice JS library for HTML to PDF conversion > https://github.com/MrRio/jsPDF

Srikanta
  • 1,145
  • 2
  • 12
  • 22
-4

I use DOMPDF which takes inline PHP and uses it to convert all of your HTML markup (CSS as well) to PDF. You can implement it client side using a button at the end of your page.

Example:

THE PHP:

<?php

if(isset($_POST['submit'])) 

{   

$content = $_POST['html'];

    if(empty($page))

    {   

        $error = 'Please include at least ONE completed field.';

        }

    else

    {

        include_once('dompdf/dompdf_config.inc.php');

        $dompdf = new DOMPDF();

        $dompdf->load_html($html);

        $dompdf->render();

        $dompdf->stream('Completed_Form.pdf');

        }

}

?>

The HTML:

<input type="submit" name="submit" id="submit" value="Generate PDF" class="submitButton">

Here is an informative video on how to use DOMPDF and where to download the necessary files.

https://www.youtube.com/watch?v=PENbtWrVUjI&index=7&list=FLR4e8kAlnW4FkgpQrGrOfMg