Membuat Nama File PDF Sendiri
Gimana Sih supaya nama file PDF yang telah di Generate ama Class FPDF bukan menjadi nama file default yaitu doc.pdf tetapi misalkan nomorinvoice.pdf.
Mudah saja sebenarnya, karena FPDF telah menyediakan fasilitasnya, kita hanya menambahkan pada bagian output, seperti di bawah ini :
$pdf->Output(‘namabaru’,'I’)
pilihannya ada beberapa macam bisa I, D atau ente liat saja di FPDF nya …
ini kutipan bagian Ouput
function Output($name=”, $dest=”)
{
//Output PDF to some destination
if($this->state<3)
$this->Close();
$dest=strtoupper($dest);
if($dest==”)
{
if($name==”)
{
$name=’doc.pdf’;
$dest=’I';
}
else
$dest=’F';
}
switch($dest)
{
case ‘I’:
//Send to standard output
if(ob_get_length())
$this->Error(‘Some data has already been output, can\’t send PDF file’);
if(php_sapi_name()!=’cli’)
{
//We send to a browser
header(‘Content-Type: application/pdf’);
if(headers_sent())
$this->Error(‘Some data has already been output, can\’t send PDF file’);
header(‘Content-Length: ‘.strlen($this->buffer));
header(‘Content-Disposition: inline; filename=”‘.$name.’”‘);
header(‘Cache-Control: private, max-age=0, must-revalidate’);
header(‘Pragma: public’);
ini_set(‘zlib.output_compression’,’0′);
}
echo $this->buffer;
break;
case ‘D’:
//Download file
if(ob_get_length())
$this->Error(‘Some data has already been output, can\’t send PDF file’);
header(‘Content-Type: application/x-download’);
if(headers_sent())
$this->Error(‘Some data has already been output, can\’t send PDF file’);
header(‘Content-Length: ‘.strlen($this->buffer));
header(‘Content-Disposition: attachment; filename=”‘.$name.’”‘);
header(‘Cache-Control: private, max-age=0, must-revalidate’);
header(‘Pragma: public’);
ini_set(‘zlib.output_compression’,’0′);
echo $this->buffer;
break;
case ‘F’:
//Save to local file
$f=fopen($name,’wb’);
if(!$f)
$this->Error(‘Unable to create output file: ‘.$name);
fwrite($f,$this->buffer,strlen($this->buffer));
fclose($f);
break;
case ‘S’:
//Return as a string
return $this->buffer;
default:
$this->Error(‘Incorrect output destination: ‘.$dest);
}
return ”;
}
7 Januari 2009 pada 12:46 pm
wah… keren… bisa di rename thooo cek dulu juragan…
7 Januari 2009 pada 12:54 pm
bisa boss
$pdf->Output(‘namaFileBaru’,'I’);
silakan dicoba ya boss …
klo ada apa reply comment aja lagi biar rame …