<?php

require('fpdf.php');
require('fpdi.php');


$pdf=& new FPDI();


if ($handle = opendir('pdfji/')) {

while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != ".." ) {
//echo $file;
    	$dat[] = $file;
    	
	}
}
closedir($handle);
}

sort($dat);

foreach ($dat as $file) {

	$pagecount = $pdf->setSourceFile("pdfji/".$file);
		for ($i=1;$i<$pagecount+1;$i++) {
			$tplidx = $pdf->ImportPage($i);
			$pdf->addPage();
			$pdf->useTemplate($tplidx);
		}
}





$pdf->Output();

?>