SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 39
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Need help in converting PDF

    Here is my code, I included html2fpdf.php

    when I run this application, I am getting the following error.

    Code:
    "Fatal error: Call to undefined method HTML2FPDF::DisplayPreferences() in C:\xampp\htdocs\PHP_PDF\html2fpdf.php on line 155"
    PHP Code:
    <?php
    ob_start
    ();
    include 
    'DBConnect.php';
    require(
    "html2fpdf.php");

    $query "Select * from tb_php_sql";
    $result mysql_query($query);
    $string '<html><body><form>';
    $string .=  '<table border="1"><tr><th>ID</th><th>Name</th><th>Phone</th></tr>';
    while(
    $rowmysql_fetch_array($result))
    {
        
    $string .= '<tr><td>';
        
    $string .= '<td>'$row['id']. '</td>';
        
    $string .= '<td>'$row['Name']. '</td>';
        
    $string .= '<td>'$row['Phone']. '</td>';
        
    $string .= '</td></tr>';
    }
    $string .= '</table></form></body></html>';

    $string nl2br($string);
    echo 
    $string


    $toWrite ob_get_contents();
    ob_end_clean();
    $html = new HTML2FPDF();
    $html->AddPage();
    $html->WriteHTML($toWrite);
    $html->Output('pdfformat.pdf','I');

    ?>


    can any one help me out with sample php application, I am new to php..
    Last edited by cpradio; Jun 12, 2013 at 04:23. Reason: Added code/php tags

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    I did a search and found this:
    https://forums.digitalpoint.com/thre...-error.956533/

    Do you have fpdf.php in the same directory as html2fpdf.php?

    And this:
    http://sourceforge.net/p/html2fpdf/d...hread/05a57b05
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I have fpdf.php in the same directory

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    In your fpdf.php file do you have a function named DisplayPreferences?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No there is no method called Display Preferences in fpdf.php

    but the same method contained in html2fpdf.php

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    When I downloaded the html2fpdf from http://sourceforge.net/projects/html...83.0.2beta%29/

    The zip contains a modified version of fpdf in it, and it had a DisplayPreferences, so you may have to use that specific version....
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the link you specified is not working.

    could you please give me another link to download that latest version.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Try this one

    If that doesn't work, here are the steps I took to get to it
    Go to http://sourceforge.net/projects/html2fpdf/
    Click on Files
    Click on html2fpdf
    Click on the link that has a modify date of 2005-02-08
    Click on the zip file link
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.. downloaded and updated all php files in my localhost

    now I am getting an error like

    Deprecated: Function ereg() is deprecated in C:\xampp\htdocs\PHP_PDF\html2fpdf.php on line 460

    Deprecated: Function set_magic_quotes_runtime() is deprecated in C:\xampp\htdocs\PHP_PDF\fpdf.php on line 1805


    Deprecated: Function set_magic_quotes_runtime() is deprecated in C:\xampp\htdocs\PHP_PDF\fpdf.php on line 1828

  10. #10
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Okay, for the ereg - http://www.develcat.com/2011/01/func...html2fpdf-php/

    For the set_magic_quotes_runtime(), just comment that line out per http://www.boonex.com/n/Function_set...d_in_PHP_5_3_0
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    everything working fine now.. but when I execute the file, it is showing

    %PDF-1.3 3 0 obj <>>><>>>] /Contents 4 0 R>> endobj 4 0 obj <> stream xœVKs0WdQ$M‡<䐡  ‘Mšl‚RZ‹x†%Ž?pr€1B)[ WJO€‰€$?„o‘lt>ojxkow!l(‹s™e".I>#_Cd7rGˆZ_k%fLs4™eq™Œ4s J>x.-8FPQ70rž“jœˆ™<DD ” s‘AQ*Mp+˜cH R0UhŒThYF™•žM|V!žw%šyŽˡŒ‹0z:} zW+}Ž›=5\bQ d“4;]ٿlbme—mGw—.;4q]v0bB2ež‰„.V:rO(u &LUPO:+Ǵ "Y ݥ›6„U5ȣrCԧ?]ž~ Żݢ$XzSi;#67›’wj‘/;taZ-™t/h7„mUpyx endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj <> >> endobj 8 0 obj << /Producer (FPDF 1.52) /Creator (HTML2FPDF >> http://html2fpdf.sf.net) /CreationDate (D:20130612145855) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000001072 00000 n 0000001460 00000 n 0000000009 00000 n 0000000342 00000 n 0000001159 00000 n 0000001255 00000 n 0000001356 00000 n 0000001568 00000 n 0000001692 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1795 %%EOF

  12. #12
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    You probably need to set the content type using a header
    PHP Code:
    header('Content-type: application/pdf');
    $html->Output('pdfformat.pdf','I'); 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much... It is working fine now.

    Thanks a lot.

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we apply styles to table and td etc.,??

    $string .= '<table border="1"><tr><th>ID</th><th>Name</th><th>Phone</th></tr>';

    I changed table style

    $string .= '<table border="4" background-color: cyan;><tr><th>ID</th><th>Name</th><th>Phone</th></tr>';

    I did not get any change in output pdf.

  15. #15
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    First off, that isn't valid HTML. You may need to use bgcolor="cyan" or style="background-color: cyan"
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  16. #16
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just need two tables side by side in pdf.

    here is my code.


    <?php
    ob_start();
    include 'DBConnect.php';
    require("html2fpdf.php");

    $query = "Select * from tb_php_sql";
    $result = mysql_query($query);
    $string = '<html><body><form><table><tr>';


    $string .= '<td align="left"><table border="1" width="33%" ><tr bgcolor="#4472c4" align="center"><th><font color="white">ID</font></th><th><font color="white">Name</font></th><th><font color="white">Phone</font></th></tr>';
    while($row= mysql_fetch_array($result))
    {
    $string .= '<tr>';
    $string .= '<td>'. $row['id']. '</td>';
    $string .= '<td>'. $row['Name']. '</td>';
    $string .= '<td>'. $row['Phone']. '</td>';
    $string .= '</tr>';
    }
    $string .= '</table></td>';

    $query1 = "Select * from tb_php_sql1";
    $result1 = mysql_query($query1);

    $string .= '<td align="right"><table border="1" width="33%" align="right" margin-top="80px"><tr bgcolor="#4472c4"><th><font color="white">First Name</font></th><th><font color="white">Last Name</font></th><th><font color="white">Age</font></th></tr>';
    while($row1= mysql_fetch_array($result1))
    {
    $string .= '<tr>';
    $string .= '<td>'. $row1['SalesOrder']. '</td>';
    $string .= '<td>'. $row1['SalesRep']. '</td>';
    $string .= '<td>'. $row1['Location']. '</td>';
    $string .= '</tr>';
    }
    $string .='</table></td>';

    $string .= '</tr></table></form></body></html>';

    $string = nl2br($string);
    echo $string;

    $toWrite = ob_get_contents();
    ob_end_clean();
    $html = new HTML2FPDF();
    $html->AddPage();
    $html->WriteHTML($toWrite);
    header('Content-type: application/pdf');
    $html->Output('pdfformat.pdf','I');

    ?>

    the output of my pdf is coming table below the table. unfortunately I couldn't upload my screenshot here while uploading an image, it is showing an error.

    could you please help me out?

  17. #17
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Now you are outside my realm on this. I really haven't done anything with html2fpdf, as I have always just built my PDFs using FPDF only. So I'm not sure how you would get side by side table layouts. Maybe specify a width on each TD tag for the columns?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  18. #18
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have already done that. but I did not get the tables side by side..

  19. #19
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Seems nested tables is not support. http://sourceforge.net/p/html2fpdf/d...hread/b37954bb

    You can supposedly use DIVs inside the table (potentially) or may need to use a different library.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  20. #20
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh god..

    can you please provide what are the different libraries available??

  21. #21
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Well, in the prior link, they reference dompdf and that looks promising...
    http://dompdf.github.io/
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  22. #22
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you please provide the example code in which, a table to be displayed which is queried from sql database. using dompdf

  23. #23
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    From https://code.google.com/p/dompdf/wiki/Usage

    Note: I haven't actually tested this code...

    PHP Code:
    <?php
    ob_start
    ();
    include 
    'DBConnect.php';
    require(
    "dompddf_config.inc.php"); // may need to require dompdf.php too?

    $query "Select * from tb_php_sql";
    $result mysql_query($query);
    $string '<html><body><form><table><tr>';


    $string .= '<td align="left"><table border="1" width="33%" ><tr bgcolor="#4472c4" align="center"><th><font color="white">ID</font></th><th><font color="white">Name</font></th><th><font color="white">Phone</font></th></tr>';
    while(
    $rowmysql_fetch_array($result))
    {
    $string .= '<tr>';
    $string .= '<td>'$row['id']. '</td>';
    $string .= '<td>'$row['Name']. '</td>';
    $string .= '<td>'$row['Phone']. '</td>';
    $string .= '</tr>';
    }
    $string .= '</table></td>';

    $query1 "Select * from tb_php_sql1";
    $result1 mysql_query($query1);

    $string .= '<td align="right"><table border="1" width="33%" align="right" margin-top="80px"><tr bgcolor="#4472c4"><th><font color="white">First Name</font></th><th><font color="white">Last Name</font></th><th><font color="white">Age</font></th></tr>';
    while(
    $row1mysql_fetch_array($result1))
    {
    $string .= '<tr>';
    $string .= '<td>'$row1['SalesOrder']. '</td>';
    $string .= '<td>'$row1['SalesRep']. '</td>';
    $string .= '<td>'$row1['Location']. '</td>';
    $string .= '</tr>';
    }
    $string .='</table></td>';

    $string .= '</tr></table></form></body></html>';

    $string nl2br($string);
    echo 
    $string;

    $toWrite ob_get_contents();
    ob_end_clean();

    $html = new DOMPDF();
    $html->load_html($toWrite);
    $html->render();
    header('Content-type: application/pdf');
    $html->stream('pdfformat.pdf');

    ?>
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  24. #24
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I run this application, the following issues are coming, but the output is saving in pdf.

    Warning: require(dompddf_config.inc.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\SIVA_DOMPDF\pdf_1.php on line 4

    Fatal error: require() [function.require]: Failed opening required 'dompddf_config.inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\SIVA_DOMPDF\pdf_1.php on line 4

  25. #25
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    where is the dompdf_config.inc.php file in relation to your pdf_1.php file?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

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