Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    957

    PDF - Nome del file nell'header

    ciao a tutti,
    ho provato a creare dei PDF con la classe EzPDF, ma non riesco ad impostare il corretto nome del file, infatti il pdf si chiama come la pagine php.
    Ho provato a impostare

    codice:
    $pdf->ezStream(array('Content-Disposition'=>'NomeDiProva.pdf'));
    e ho anche verificato che nell'header HTTP arrivasse correttamnete:

    codice:
    HTTP/1.1 200 OK
    Date: Fri, 11 Jan 2008 17:43:46 GMT
    Server: Apache/2.2.4 (Win32) PHP/5.2.3
    X-Powered-By: PHP/5.2.3
    Content-Length: 831
    Content-Disposition: inline; filename=NomeDiProva.pdf
    Content-Type: application/pdf
    Però Acrobat continua a leggerlo come test.php (come della pagina php), e se provo a salvarlo o inviarlo via email, mi propone sempre quel nome...
    In qualche modo voi avete risolto?

    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2001
    Messaggi
    525
    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);


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.