1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

COnvert to PDF with PHP

Discussion in 'PHP' started by onlyican.com, Jan 4, 2006.

  1. #1
    Hey

    I did want to convert to a Word Doc, but i can't find out how, so PDF would have to do.

    I found a code, and inserted by code in it, but i got an errror.
    So i tried copying the code to the T, and the same error

    Here is the script
    $pdf = PDF_new();
    PDF_open_file($pdf);
    
    PDF_set_info($pdf, "author", "Jamie Teuma");
    PDF_set_info($pdf, "title", "Word Docs");
    PDF_set_info($pdf, "creator", "JAMIE");
    PDF_set_info($pdf, "subject", "Word Docs");
    
    PDF_begin_page($pdf, 450, 450);
    
    $font = PDF_findpoint($pdf, "Helvetica-bold", "winasi", 0);
    
    PDF_show_xy($PDF, "Hello, Dynamic PDFs!", 5, 255);
    
    PDF_end_page($pdf);
    
    PDF_close($pdf);
    
    $buffer = PDF_get_buffer($pdf);
    
    header("Content-type: application/pdf");
    header("Content-Length: ".strlen($buffer));
    header("Content-Disposition: inline; filename=text.pdf");
    
    echo $buffer;
    
    PDF_delete($pdf);
    PHP:

    The error is Fatal error: Call to undefined function: pdf_new() in /home/onlyican/public_html/mri/test/test8.php on line 11

    Line 11 is $pdf = PDF_new();
     
    onlyican.com, Jan 4, 2006 IP
  2. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The pdflib extension probably wasn't compiled into PHP on your server. If you run phpinfo() you can look to see if pdflib is there.
     
    tflight, Jan 4, 2006 IP
  3. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, so how do I get this to work then
     
    onlyican.com, Jan 4, 2006 IP
  4. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you are on your own server then you will need to recompile PHP with pdflib. If you are on a shared server then you have three options:

    1) Ask your host to install it on your server.
    2) Ask your host to move you to a server that has pdflib compiled within PHP.
    3) Move to a different host that has pdflib compiled with PHP.
     
    tflight, Jan 4, 2006 IP
  5. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #5
    $pdf = PDF_new(); <--- when you do so, you need to have a class for that object, which apparently you don't.
    try using free available pdf classes such as ezpdf.
     
    legend2, Jan 6, 2006 IP
  6. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    onlyican.com, Jan 6, 2006 IP
  7. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    cancer10, Apr 10, 2008 IP
  8. Ashish Pawaskar

    Ashish Pawaskar Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Does fpdf handle tables properly?

    Can we put the table directly into a PDF or do we have to draw it ourselves using findpoint, etc?
     
    Ashish Pawaskar, Apr 15, 2008 IP
  9. bdude

    bdude Peon

    Messages:
    124
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Bump much?
     
    bdude, Apr 16, 2008 IP
  10. JeroenR

    JeroenR Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #10
    Have a look at this one. It converts most office files from PHP. http://blog.muhimbi.com/2013/02/converting-files-to-pdf-and-other.html
     
    JeroenR, Feb 14, 2013 IP
  11. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #11
    If he hasn't solved the problem in over 7 years, I doubt he cares now.
     
    Rukbat, Feb 16, 2013 IP
  12. Nedzad Mesic

    Nedzad Mesic Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #12
    You can use jQuery Javascript library. My recommendation is DataTables jQuery . DataTables jQuery can export to Excel, PDF and CSS as well as send the print to the printer. It is very easy to use and can be customized.


    /*
    * Example initialisation
    */
    $(document).ready( function () {
    $('#example').dataTable( {
    "sDom": 'T<"clear">lfrtip',
    "oTableTools": {
    "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
    }
    } );
    } );
     
    Nedzad Mesic, Feb 27, 2013 IP