Wednesday, January 9, 2013

Create PDF File using Dompdf

The best option for creating pdf file or report,I suggest only Dompdf.The Dompdf is fullfill all requirement.In Dompdf you have to create simple pdf file,dynamic data file,generate database related pdf file.dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS 2.1 compliant HTML layout and rendering engine written in PHP.dompdf is an HTML to PDF converter.


 
Download Dompdf :
  1. Link 1
  2. Link 2
  3. Link 3
Example For Create PDF :
$html = ("<html>");
 $html .= ("<head>");
 $html .= ("<style>");
 $html .= ("</style>");
 $html .= ("</head>");
 $html .= ("<body>");

$html.=("<table width='500' border='1' cellspacing='1' cellpadding='1'>\n");
$html .= ("<tr>");
$html .= ("<td>hello</td>");
$html .= ("<td>welcome</td>");
$html .= ("</tr>");
 $html .= ("</table>");
 $html .= ("<h2>Generated PDF</h2>\n");
 $html .= ("<p>date_today</p>\n");
 $html .= ("</div>");

 $html .= ("<p>$table->COMMENT</p>\n");

 $html .= ("</body>");
 $html .= ("</html>");

 function render($html,$filename)
 {
  require_once("../dompdf_config.inc.php");
  $dompdf = new DOMPDF();
  $dompdf->load_html($html);
  $dompdf->set_paper("a4", "landscape" );
  $dompdf->render();
  $dompdf->stream("$filename.pdf");
 }

 $filename = ("GeneratedPDF");

 render($html,$filename);
}
 

9 comments:

  1. ok,
    just replace this : $dompdf->stream("$filename.pdf");
    With below line :
    file_put_contents("foldername/$filename.pdf", $dompdf->output());

    ReplyDelete
  2. dompdf fail on large contents what will be the solution

    ReplyDelete
  3. Please set the "max execution time" in your page.so script not break if page content large data.

    Please set "set_time_limit(0)" on top of the page.

    ReplyDelete
  4. hi., i have a problem i hope you help me, i'm mexican and my english is not very good but i'm going to try to explain the problem i have. i use dompdf to generate a report that retrieve data from mysql i store the path of the images and when a retrieve the data apear data(text) and the image but when i generate the pdf occur an error and the pdf is generated but i can´t open it , thanks

    ReplyDelete
  5. hi., i have a problem i hope you help me, i'm mexican and my english is not very good but i'm going to try to explain the problem i have. i use dompdf to generate a report that retrieve data from mysql i store the path of the images and when a retrieve the data apear data(text) and the image but when i generate the pdf occur an error and the pdf is generated but i can´t open it , thanks

    ReplyDelete
  6. hi., i have a problem i hope you help me, i'm mexican and my english is not very good but i'm going to try to explain the problem i have. i use dompdf to generate a report that retrieve data from mysql i store the path of the images and when a retrieve the data apear data(text) and the image but when i generate the pdf occur an error and the pdf is generated but i can´t open it , thanks

    ReplyDelete
  7. hi., i have a problem i hope you help me, i'm mexican and my english is not very good but i'm going to try to explain the problem i have. i use dompdf to generate a report that retrieve data from mysql i store the path of the images and when a retrieve the data apear data(text) and the image but when i generate the pdf occur an error and the pdf is generated but i can´t open it , thanks

    ReplyDelete

Thanks....