0
<?php
require_once 'classes/postgredb.class.php';
require_once 'include/functions.php';
require_once("/tools/dompdf/dompdf_config.inc.php");
$con=new PostgreDB(); 
ob_start();

$html =
    '<html><body>'.
    '<p>Hello World!</p>'.
    '<div style="page-break-after: always;"></div>'.
    '</body></html>';

for($i=0;$i<5;$i++)
{


$dompdf = new DOMPDF();
$dompdf->load_html($html);

$dompdf->render();
$dompdf->stream("Admit card.pdf",array("Attachment"=>0));
}



?>

I want to print the "Hello World" in each page,but my code is printing it in only one page. How do i print "Hello World" in each page using a loop.Please help me.

1 Answer 1

2

Try this:

Your loop is wrong. The way you add pages to your PDF is probably wrong. Apparently you are overwriting one page again and again instead of attaching a new one.

$html = <<<HTML
  <html>
      <head>
            <style type="text/css">
                /* Your document styling goes here */
            </style>
      </head>
      <body>
HTML;
for($i=0;$i<5;$i++)
{
    $html .= '<div style="page-break-after: always;"><p>Hello World!</p></div>';
}
$html .= '</body></html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);

$dompdf->render();
$dompdf->stream("Admit card.pdf",array("Attachment"=>0));
$dompdf->clear();

NOTE: You need to make sure, is that heredoc closer HTML is in a new line and not indented.

Sign up to request clarification or add additional context in comments.

4 Comments

It works.Thank you so much for helping.I got the concept now.
Ok accepted.Is there any other way to create looping without embedding the "$html" again and again.I mean when i tried for showing only one page pdf, the total php code worked without the adding "$html" .How can the total php code will be put into a loop that will produce multiple pdf file.Any solution???
use full directory path with .jpg image to display image in pdf
@MangeshParte This code generated the three files but how can I save these pdf files because pdf files are opened in the web browser not saved in the computer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.