Perchè non provi a rinominare il file che viene creato sul server???
Ecco un esempio, modifica rinominando il file temporaneo.... :
Codice PHP:
if (!isset($demotext) || strlen($demotext)==0){
$demotext='demo text';
}
$pdf = new Cpdf(array(0,0,598,842));
$pdf->selectFont('pdfClassesAndFonts_009e/fonts/Helvetica');
// do some funky stuff in the background, in a nice light blue, which is bound to clash with something
// and some red for the hell of it
$x=578;
$r1=25;
for ($xw=40;$xw>0;$xw-=3){
$tone=1.0-$xw/40*0.2;
$pdf->setLineStyle($xw);
$pdf->setStrokeColor($tone,1,$tone);
$pdf->ellipse(50,750,$r1);
$r1=$r1+$xw;
}
for ($xw=40;$xw>0;$xw-=3){
$tone=1.0-$xw/40*0.2;
$pdf->setStrokeColor($tone,$tone,1);
$pdf->setLineStyle($xw);
$pdf->line($x,0,$x,842);
$x=$x-$xw-2;
}
$pdf->setStrokeColor(0,0,0);
$pdf->setLineStyle(1);
$pdf->rectangle(20,20,558,802);
$y=800;
for ($size=50;$size>5;$size=$size-5){
$height = $pdf->getFontHeight($size);
$y=$y-$height;
$pdf->addText(30,$y,$size,$demotext);
}
for ($angle=0;$angle<360;$angle=$angle+20){
$r=rand(0,100)/100;
$g=rand(0,100)/100;
$b=rand(0,100)/100;
$pdf->setColor($r,$g,$b);
$pdf->addText(300+cos(deg2rad($angle))*40,300-
sin(deg2rad($angle))*40,20,$demotext,$angle);
}
$pdfcode = $pdf->output();
$dir = './pdf_files';
//save the file
if (!file_exists($dir)){
mkdir ($dir,0777);
}
$fname = tempnam($dir.'/','PDF_').'.pdf';
$fp = fopen($fname,'w');
fwrite($fp,$pdfcode);
fclose($fp);
echo '<html>
<head>
<SCRIPT LANGUAGE="JavaScript"><!--
function go_now () { window.location.href = "'.$fname.'"; }
//--></SCRIPT>
</head>
<body onLoad="go_now()"; >
[url="'.$fname.'"]click here[/url] if you are not re-directed.
</body>
</html>
';
// also have a look through the directory, and remove the files that are older than a week
if ($d = @opendir($dir)) {
while (($file = readdir($d)) !== false) {
if (substr($file,0,4)=="PDF_"){
// then check to see if this one is too old
$ftime = filemtime($dir.'/'.$file);
if (time()-$ftime > 3600*24){
unlink($dir.'/'.$file);
}
}
}
closedir($d);
}