Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: PHP Post to PDF

  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    PHP Post to PDF

    Hi guys

    I have this code which inserts a "print / and PDF" button on my page. However, there are ads included, and also the "email" part does not email the form correctly.

    Is there perhaps a better solution for creating a print to pdf button for my forms POST data?

    PHP Code:
    <script>var pfHeaderImgUrl '';var pfHeaderTagline '';var pfdisableClickToDel 1;var pfHideImages 0;var pfImageDisplayStyle 'left';var pfDisablePDF 0;var pfDisableEmail 0;var pfDisablePrint 1;var pfCustomCSS '';var pfBtVersion='1';(function(){var jspf;pf document.createElement('script');pf.type 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;" src="http://cdn.printfriendly.com/pf-button-both.gif" alt="Print Friendly and PDF"/></a> 

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    Use PHP? I'm sure there are PHP libraries that will allow you to output to PDF. Not a PHP person, but they are certainly available in other server-side technologies (JSP, ASP, etc.).

    So you would have the <form> submit to a PHP page that would re-print the form contents into a PDF document and then allow the user to download or view the PDF document.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    LOL! I decided to Google for "php output to pdf" and VOILA!

    http://php.net/manual/en/book.pdf.php

    So it's part of the standard available PHP libraries, even.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question

    hi there

    Thank you for your reply.,

    I have tried to use their first "example", and I receive this error:

    Code:
    Fatal error: Call to undefined function PDF_new() in /home/airportg/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 2
    PHP Code:
    <?php
    $p 
    PDF_new();

    /*  open new PDF file; insert a file name to create the PDF on disk */
    if (PDF_begin_document($p"""") == 0) {
        die(
    "Error: " PDF_get_errmsg($p));
    }

    PDF_set_info($p"Creator""hello.php");
    PDF_set_info($p"Author""Rainer Schaaf");
    PDF_set_info($p"Title""Hello world (PHP)!");

    PDF_begin_page_ext($p595842"");

    $font PDF_load_font($p"Helvetica-Bold""winansi""");

    PDF_setfont($p$font24.0);
    PDF_set_text_pos($p50700);
    PDF_show($p"Hello world!");
    PDF_continue_text($p"(says PHP)");
    PDF_end_page_ext($p"");

    PDF_end_document($p"");

    $buf PDF_get_buffer($p);
    $len strlen($buf);

    header("Content-type: application/pdf");
    header("Content-Length: $len");
    header("Content-Disposition: inline; filename=hello.pdf");
    print 
    $buf;

    PDF_delete($p);
    ?>

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    Did you read this?
    http://www.php.net/manual/en/pdf.installation.php

    Especially
    This PECL extension is not bundled with PHP...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Cool

    Thank you.

    I have read that the following can be added to avoid having to download it..
    could this be inserted at the top of my code after
    Code:
    <? php
    ?


    PHP Code:
    pecl install extname 

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    I don't use PHP. I was just quoting from the docs. You probably should ask about this in the PHP forum.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Melissafleet (05-13-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •