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 ”;
}

2 Tanggapan to “Membuat Nama File PDF Sendiri”

  1. wah… keren… bisa di rename thooo cek dulu juragan…

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.