1

Hi,
I'm using html2pdf for creating a PDF report of 18-20
pages my html is embeded with data from DB and Images( 10 - 20 images ).
But the pdf generation takes like 2+ mins.Is there any way to decrease the time.
This is my code:
<?php

$user_id = "";
if ( !empty( $_SESSION['user']['usr_profile_id'] ) ) {
$user_id = $_SESSION['user']['usr_profile_id'];

} else {
$user_id = $_SESSION['uid'];
}

$path1 = "reports";

if ( !file_exists($path1) ) {
print "1".$path1."<br>";

mkdir($path1,0777);
}
$path2 = "reports/$user_id";
if ( !file_exists($path2) ) {

mkdir($path2,0777);
}


ob_start();

set_time_limit(0);

//ini_set('display_errors',1);

include("report/1_cover.html");

$content = ob_get_clean();
require_once('vendors/html2pdf.class.php');

$html2pdf = new HTML2PDF('P','A4','en');

$html2pdf->setTestTdInOnePage(false);

$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();

include("report/2_letter.html");

$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();

include("report/3_form1.html");

$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();

include("report/4_form2.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();

include("report/5_form3.html");

$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();
include("report/6_form4.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();
include("report/7_form5.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();
include("report/8_form6.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();
include("report/9_summary.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));


ob_start();
include("report/addendum.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));


ob_start();
include("report/10_images.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));

ob_start();

include("report/11_plans.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));



ob_start();

include("report/12_location_map.html");

$content = ob_get_clean();
$html2pdf->WriteHTML($content,isset($_GET['vuehtml']));


$file=$_SESSION['fileNumber'];
$file_name = "Report_$file.pdf";


$html2pdf->Output("$path2/$file_name",'F');






$server= $_SERVER['SCRIPT_NAME'];
$domain = $_SERVER['SERVER_NAME'];

$server_url = "http://".$domain.str_replace( "index.php","$path2/$file_name",$server);

header("Location:$server_url");
?>

2

I'm not sure this technique is a fast way to achieve you goal:

ob_start();
include("report/11_plans.html");
$content = ob_get_clean();

Do you really need to interpret php instructions in these files or is file_get_contents sufficient to get what's in your files?

3

why you don't do this ?

require_once('vendors/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en');
$html2pdf->setTestTdInOnePage(false);

ob_start();
include("report/1_cover.html");
include("report/2_letter.html");
include("report/3_form1.html");
include("report/4_form2.html");
include("report/5_form3.html");
include("report/6_form4.html");
include("report/7_form5.html");
include("report/8_form6.html");
include("report/9_summary.html");
include("report/addendum.html");
include("report/10_images.html");
include("report/11_plans.html");
include("report/12_location_map.html");
$content = ob_get_clean();
$html2pdf->WriteHTML($content);


$file=$_SESSION['fileNumber'];
$file_name = "Report_$file.pdf";
	
	
$html2pdf->Output("$path2/$file_name",'F');


put tables in tables take very long time, try to not do this, if the embed table is very big !
Ancien pseudo : lolo

4

it will not solve your problem, but if your .html files only contain HTML code you should avoid using "include" and try "readfile" instead ("include" parses the entire file and searches for PHP tags, in your case this is just a waste of time)
avatar
All right. Keep doing whatever it is you think you're doing.
------------------------------------------
Besoin d'aide sur le site ? Essayez par ici :)

5

Hi,

Thanks My performance is also reduced but now i'm facing another issue

there some where around 60 images in my document

now it is giving a image load error

ERROR n�6
File : /var/www/html/cakephp/vendors/html2pdf.class.php
Line : 1482

Impossible to load the image http://ibs.prithvisolutions.com/cakephp/app/webroot/ibs/97/Vogue-Bathroom.jpg

is there any fix for this ?

Bijith

6

did you click on your own link? your image is invalid.

7

mur
Ancien pseudo : lolo

8

Sorry sir,

That image was corrupted let me check back and get back to u

Bijith

9

Hi Sir,

I have implemented the solutions and was implemented the solutions you suggested and it helped
me to reduce time from 2+ mins to 1+ mins nearly ( 50cheeky .

Thanks for the tips.

Is there anyother ways to further optimize this? ( say under 1 min ).

Bijith

10

have a more powerfull server ?
Ancien pseudo : lolo