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


<?php
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 '';
}
?>

6 Responses to “Membuat Nama File PDF Sendiri”

  1. ianbali On

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

  2. aagun2006 On

    bisa boss

    $pdf->Output(’namaFileBaru’,'I’);

    silakan dicoba ya boss …

    klo ada apa reply comment aja lagi biar rame …

  3. annots On

    akhirnya tercerahkan juga, matur nuwun untuk artikelnya, sangat membantu…

  4. admin On

    terimakasih annots jika bermanfaat, mohon maaf commentnya baru di reply.

  5. wiwi On

    gimana caranya memasukan image ke fpdf tetapi image nya itu berasal dari database

  6. admin On

    @wiwi
    didatabase nya berbentuk blob, atau hanya nama image, dan image nya misal udah absoluth di folder image.

    tp intinya sama aja sih yang pertama mbak harus dapat mengambil gambar itu dari database, dan cara penempatannya sama seperti yang sudah dibahas di atas

Leave a Reply


Verify Code   If you cannot see the CheckCode image,please refresh the page again!