Need help in converting PDF

Here is my code, I included html2fpdf.php

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

"Fatal error: Call to undefined method HTML2FPDF::DisplayPreferences() in C:\\xampp\\htdocs\\PHP_PDF\\html2fpdf.php on line 155"
<?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($row= mysql_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… :frowning:

I did a search and found this:

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

And this:
http://sourceforge.net/p/html2fpdf/discussion/391791/thread/05a57b05

Yes I have fpdf.php in the same directory

In your fpdf.php file do you have a function named DisplayPreferences?

No there is no method called Display Preferences in fpdf.php

but the same method contained in html2fpdf.php

When I downloaded the html2fpdf from http://sourceforge.net/projects/html2fpdf/files/html2fpdf/HTML%202%20PDF%20-%20a%20PHP%20script%20(3.0.2beta)/

The zip contains a modified version of fpdf in it, and it had a DisplayPreferences, so you may have to use that specific version…

the link you specified is not working.

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

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

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

Okay, for the ereg - http://www.develcat.com/2011/01/function-ereg-is-deprecated-in-html2fpdf-php/

For the set_magic_quotes_runtime(), just comment that line out per http://www.boonex.com/n/Function_set_magic_quotes_runtime_is_deprecated_in_PHP_5_3_0

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œ½VKsÚ0¾çWìd¦Q$ùM§‡<Û䐡 Óâ ãÜË‘Mšüû®l‚RZ¨Ó‹Çxåýú´†ÃÍ%Ža?ÎúprÅ€1B)ô¸ìè[ £ºÄWJO€À÷‰å€çû$ð¡?„Ão‘ÊÒltýï¸>oj¼xÛãkow!ÍâÉl(Â˳s™e".I>ÎÃ#¸_¶¼ÀCd®ùõ7rGˆªZ_k%ªfLâs4™eq™ÊŒ4Øs ÅJø>x.±-8F»PäQ7ÿ¸0ª±rþ¹¨úÒž“jœ³ˆë™<ºDéD ¡” s‘AQ*M»p+¡˜ÅcH° RÁ0UhŒT¯h¬YýËF™•ÝžM|V!žwÃð%šæyŽË¡Œ‹0¼»þz:è}ê zWø+}ŽôÓ›ð§=5\bQ d“4;°µ¸]Ù¿lbmeð—êmÜGw—¨.;4q]v0âÚbB2ež‰ó»„.V:ÄrÛO(u å&LèUPOô:+Ç´ ¦³"Y Ý¥›6Ââ„aUÛð°Ñ5È£rü¡CÞeÁÔ§?ì]ž~é Å»ÅÝ¢$Xz«¼ÛúSi¼;Ü#67›´’wj‘Àþ§¼/;taúZ-óÉÚ™tôß/äh7§é„mUðpyx 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

You probably need to set the content type using a header

header('Content-type: application/pdf');
$html->Output('pdfformat.pdf','I');

Thank you so much… It is working fine now.

Thanks a lot.

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.

First off, that isn’t valid HTML. You may need to use bgcolor=“cyan” or style=“background-color: cyan”

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?

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?

I have already done that. but I did not get the tables side by side… :frowning:

Seems nested tables is not support. http://sourceforge.net/p/html2fpdf/discussion/391791/thread/b37954bb

You can supposedly use DIVs inside the table (potentially) or may need to use a different library.

oh god…

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