DOMPDF of a full dynamic PHP page

1,804 views
Skip to first unread message

E. N. Vickery

unread,
Jan 31, 2015, 1:36:54 PM1/31/15
to dom...@googlegroups.com

I'm trying to utilize DOMPDF to generate a PDF from a dynamic php page (a table filled with values from a POST form on a previous page).

I'm following the solution described here: Making download link to DOMPDF generated pdf on same page

Following the formula described in that answer, I'm defining the HTML of the page as a variable, then passing it as the value of a hidden form input:

<!--HTML/PHP of page here-->
Here's some awesome dynamic page content filled with POST form values.
<!--end HTML/PHP of page-->

<form id="hidden_form" name="" action="dompdftest.php" method="POST">
<input type="hidden" id="html" name="html" value=""/>
<input type="submit" id="submitlink" name="submit"/>
</form>

<!--load jquery-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<!--when click submit_link button, assign #hidden_form_input value of page html-->
        <script>
    $(document).ready(function() {
    $('#submitlink').click(function() {
    var html = $("body").html();
  $('#html').val($html);
  $('#hidden_form').submit();
});

});
</script>

And here's the next page, dompdftest.php, which should be loading a DOMPDF PDF:

<?php

require_once("./dompdf/dompdf_config.inc.php");
if ( isset( $_POST["html"] ) ) {

    $_POST["html"] = stripslashes($_POST["html"]);

  $dompdf = new DOMPDF();
  $dompdf->load_html($_POST["html"]);
  $dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
  $dompdf->render();

  $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

}

?>

If I test by assigning a value to the hidden input, i.e.

        <script>
    $(document).ready(function() {
    $('#submitlink').click(function() {
    var html = $("body").html();
  $('#html').val('Hello');
  $('#hidden_form').submit();
});

});
</script>

...it works fine - prints a PDF with "Hello". Why isn't it working when try to pass the HTML as a variable? Do I need to pass the POST values from the dynamic page again? If so, how do I do that?

Thanks in advance for any help on this challenge!  Can also be answered on SO http://stackoverflow.com/questions/28254906/submit-full-html-of-page-w-hidden-form-dompdf-of-dynamic-php-page

BrianS

unread,
Feb 4, 2015, 10:25:01 PM2/4/15
to dom...@googlegroups.com
perhaps just a typo, but shouldn't $('#html').val($html); be $('#html').val(html);
Reply all
Reply to author
Forward
0 new messages