Print pdf button on webpage

Q: Hello,
I am looking to convert a web page to a PDF file, retaining all the look & feel of the web page. Essentially I need a Print Page button that prints the entire website page into a PDF.

HTML2PDF add-on will allow you to convert a local .html file to PDF. In your case, where sessions has to be handled, one recommendation is to use the current response buffer, then pass this buffer as a string to HTML2PDF to get the resulting PDF file. In PHP, you can output the page to a file using ob_start & ob_get_contents function.

Below is a small psuedocode that can guide you to:

<?php // do your session checking here... ob_start(); // start the output buffering... echo("


".$_SESSION["a"]); // notice the use of session... // now that we have contents, let's try saving to file... // trigger HTML2PDF... (assuming you already set-up & initialized PDFNet) $doc = new PDFDoc(); $converter = new HTML2PDF(); $converter->InsertFromHtmlString(ob_get_contents()); if ($converter->Convert($doc) == true) { $doc->Save("test.pdf", SDFDoc::e_linearized); } $doc->Close(); // PDF file should now be ready... ?>