Yii Framework Forum: Membuat Laporan PDF dengan FPDF - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Membuat Laporan PDF dengan FPDF Rate Topic: -----

#1 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 21 September 2011 - 06:41 AM

para masta Yii ane mo nanya,
untuk bikin laporan PDF di Yii pakai FPDF gmn ya?
udah coba pake FPDF, tapi kenapa belum berhasil juga.
Sebelumnya folder 'fpdf' sudah sy download dan ane taroh di folder
protected/extensions
Ni codingannya (codingan simple)
<?php
Yii::import('application.extensions.fpdf.*');
require_once("fpdf.php");

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World !');
$pdf->Output();
?>


malah muncul gini gan

Quote

Failed to load PDF Document

padahal kalao ane pake prosedural biasa(tanpa yii) itu bisa gan, gimana ya solusinya?
Mohon bantuannya.. :-[
0

#2 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 21 September 2011 - 09:22 PM

pake phpexcel aja dy bisa bikin pdf kok
ni link cara pakenya...semoga membantu ^^
http://www.yiiframew...brary-with-yii/
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#3 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 21 September 2011 - 09:32 PM

klo ane pake HTML2PDF gan. Tapi karena dari francis, klo ada error pesan errornya pake bahasa francis. Tapi tutirial dan lainnya bahasa ingris kok. cuma pesan error aja yg bahasa francis.
coba ke sini gan http://html2pdf.fr/en
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#4 User is offline   Peter JK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 22-November 10
  • Location:Jakarta, Indonesia

Posted 21 September 2011 - 09:41 PM

Pahami dulu bahwa Eksekusi Action itu adanya di Controller bukan di View Jadi jangan taroh coding Open FPDF di View.



Step 0. Taroh FPDF di /protected/extensions/

A. Direct Button
Step 1. Taroh Action ini menjadi salah satu action di PostController

public function actionHelloWorld()
{

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
}

Step 2. Eksekusi Command adalah: http://localhost/blog/post/HelloWorld


B. Dengan CFormModel
Step 1. Taroh di Controller menjadi salah satu Action

public function actionHelloWorld2()
{
$model=new FAllocation;

if(isset($_POST['FAllocation']))
{
$model->attributes=$_POST['FAllocation'];
if($model->validate()) {

$pdf=new H0F1_report2();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',12);

$pdf->report2($model->begindate,$model->enddate);
$pdf->Output();

}
}

$this->render('report2',array('model'=>$model));
}

Step 2. Bikin CFormModel taroh di folder Model

class FAllocation extends CFormModel
{
public $begindate;
public $enddate;

public function rules()
{
return array(
//array('begindate, enddate', 'required'),
array('begindate, enddate', 'type', 'type'=>'date', 'dateFormat'=>'yyyy-MM-dd'),
);
}

public function attributeLabels()
{
return array(
'begindate'=>'Periode Mulai',
'enddate'=>'Periode Selesai',
);
}
}


Step 3. Buat View Report 2 untuk menampilkan Form yang kita buat di Step 2. Remember, di kode ini ada CJuiDatePicker, Remove aja kalau nggak mau pake..


<?php
$this->breadcrumbs=array(
'Report Allocation',
);

?>

<h1>My Report2</h1>

<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'allocation-form',
'enableAjaxValidation'=>false,
)); ?>

<div class="row">
<?php echo $form->labelEx($model,'begindate'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'value'=>CTimestamp::formatDate('yyyy-MM-dd',$model->begindate),
'attribute'=>'begindate',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'begindate'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'enddate'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'value'=>CTimestamp::formatDate('yyyy-MM-dd',$model->enddate),
'attribute'=>'enddate',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'enddate'); ?>
</div>

<div class="row submit">
<?php echo CHtml::submitButton('Report'); ?>
</div>

<?php $this->endWidget(); ?>
</div><!-- form -->

Step 4. Ketika Form ini dieksekusi, ingat ada 2 parameter yang di pass ke Action HelloWorld2 di PostController, BeginDate dan EndDate, So Code untuk FPDF adalah

<?php

class H0F1_report2 extends fpdf
{

//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Print Date: '. SParameter::IndoFormat() . ' ' .
'Page: '.$this->PageNo().'/{nb}' . ' ' .
'Report Code: H0F1/RP2',0,0,'C');
}


function Report2($id,$ad)
{
//Kode Buat FPDF-nya..
}
}

?>


Kalau binun, let's discuss it later....
0

#5 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 26 September 2011 - 10:07 PM

Ternyata untuk bikin report PDF dengan Yii itu sangat mudah, ane cari2 alhamdulillah dapet juga (ga sengaja kecemplung di forumnya orang eropa gan.. he)
ternyata cukup mudah, ga perlua pake cell-cell segala, cukup html biasa (misal buat tabel)
cukup tr td gan, coba pakai MPDF
Silakan bisa di coba sendiri.. Pokonya mantap

<?php

Yii::import('application.extensions.MPDF52.*');
include("mpdf.php");
<style>
table {
	font-family: sans-serif;
	border: 20mm solid aqua;
	border-collapse: collapse;
}
layout {
	border:0.2mm solid;
	background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;
}
</style>
';*/

$html = '
<pageheader name="myHeaderNoNumEven" content-left="" content-center="myHeader1Even" content-right="{DATE j-m-Y}" header-style="font-family:sans-serif; font-size:8pt; color:#000088;" header-style-left="font-weight:bold; " line="on" />

<link rel="stylesheet" type="text/css" href="'.Yii::app()->request->baseUrl.'/css/mpdfstyletables.css" />

<table style="border-collapse: collapse;" width=100%>
<tr><td rowspan=2 width=100px style="border:0.2mm solid;"><img style="vertical-align: top" src="'.Yii::app()->request->baseUrl.'/images/pgn.jpg" width="85px" /></td><td align="center"; style="border:0.2mm solid;">PT PERUSAHAAN GAS NEGARA (Persero) Tbk</td>
</tr>
<tr>
<td align="center"; style="border:0.2mm solid;">FORMULIR NOTULENSI KNOWLEDGE SHARING</td>
</tr>
</table>

<table>
	<tr><td></td></tr>
	<tr><td> Judul </td><td>: '.$judul.'</td></t>
	<tr><td> Waktu & Lokasi </td><td>: '.$lokasi.'</td></tr>
	<tr><td> Narasumber </td><td>: '.$narasumber.'</td></tr>
	<tr><td> Pemimpin </td><td>: '.$pemimpin.'</td></t>
	<tr><td> Fasilitator </td><td>: '.$fasilitator.'</td></t>
	<tr><td> Metode </td><td>: '.$metode.'</td></tr>
	<tr><td> Notulis </td><td>: '.$notulis.'</td></tr>
	<tr><td> Lampiran </td><td>: '.$a.'</td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
<table  width="100%" style="border-collapse: collapse;"><tr>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">No</td>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">Agenda / Permasalahan</td>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">Analisa / Pembahasan</td>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">Kesepakatan / Tindak Lanjut</td>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">PIC</td>
<td style="border:0.2mm solid; background-gradient: linear #c7cdde #f0f2ff 0 1 0 0.5;">Target Waktu</td>
</tr>';
$no=1;
foreach($Notulens as $data){
$html.='
	<tr>
	<td style="border:0.2mm solid;">'.$no.'</td>
	<td style="border:0.2mm solid;">'.$data->agenda.'</td>
	<td style="border:0.2mm solid;">'.$data->analisa.'</td>
	<td style="border:0.2mm solid;">'.$data->kesepakatan.'</td>
	<td style="border:0.2mm solid;">'.$data->pj.'</td>
	<td style="border:0.2mm solid;">'.$data->due_date.'</td>
';
$html.= '</tr>'; $no++;
}
$html .= '</table><br><table align=right><tr><td align=center><p style="font-size:12pt;" >Mengetahui<br>Fasilitator Knowledge Sharing,<br><br>( '.$fasilitator.' )</p></td></tr></table>';
$mpdf=new mPDF('c');
$mpdf->Bookmark('Start of the document');
$mpdf->useOddEven = 1;
$mpdf->AddPage('L','','5','i','on');
//$mpdf->AddPage('L','','','','',50,50,50,50,10,10);
//$stylesheet = file_get_contents('../../mpdfstyletables.css');
//$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
//$mpdf->WriteHTML('<div>Section 1 text</div>');
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;

?>

0

#6 User is offline   Peter JK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 22-November 10
  • Location:Jakarta, Indonesia

Posted 27 September 2011 - 04:31 AM

View PostJohn_453P, on 26 September 2011 - 10:07 PM, said:

[/code]



hehehe.. banyak jalan ke Monas, tapi kayaknya ini nggak Yii-Style banget... anyhow, kalau it's work, ini yang lebih penting memang. Daripada coding keren2 tapi kagak fungsi....hehehe
0

#7 User is offline   Finzaiko 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 18-November 11
  • Location:Indonesia

Posted 22 February 2012 - 10:17 PM

Thanks gan udah sharing..
0

#8 User is offline   Dayak Ngoding 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 14-November 11

Posted 22 February 2012 - 10:41 PM

Asli baru tahu ada mPDF ...

Thanks atas sharingnya, lagi bikin report juga.

Masalah generate PDF dari PHPExcel, adalah hasil generate yang juga menghasilkan garis-garis dari semua cell; padahal Saya tidak melakukan setting border terhadap cell yang ada.
0

#9 User is offline   ahmadroni 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 250
  • Joined: 14-June 09
  • Location:Yogyakarta-Indonesia

Posted 25 February 2012 - 08:20 PM

sekedar berbagi aja gan
kalo mau menggunakan FPDF, nama Class dan nama filenya harus sama
jika nama filenya fpdf maka nama class nya harus fpdf bukan FPDF, oleh karena itu muncul pesan seperti diatas..
Failed to load PDF Documen


Hospital Cost Management System and
Hospital Management Information System
0

#10 User is offline   mugiwiguna 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-August 12

Posted 08 August 2012 - 04:14 AM

buat nyimpen script itu dimana ya , nah terus manggilnya gimana ?
0

#11 User is offline   mbahsomo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 29-March 10

Posted 09 August 2012 - 07:50 PM

ringan mana ya tcpdf sama mpdf ?
Sugik Puja Kusuma [mbahsomo]
http://sugik.do-event.com
0

#12 User is offline   thomsite 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 27-September 12
  • Location:Jakarta

Posted 05 October 2012 - 02:20 AM

help dong gan2 skalian... ketulan aq baru kenalan ma yii, paljari woo keren. tp bingung gmn bikin laporan... dah coba pake reportico, eh ngk bagus...
0

#13 User is offline   dickypadang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 31-March 12

Posted 03 November 2012 - 11:17 AM

ane pernah gunain Mpdf, tapi untuk landscape page layoutnya ngak fungsi gan, kenapa ya? padahal udah ane set di init pdfnya, ngak mau juga. Ada yang sudah berhasil share donk
0

#14 User is offline   ihsan atkia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-January 13

Posted 08 January 2013 - 02:27 PM

mas ada contoh file yang pake fpdf gak ane udah bikin tapi masih eror nih..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users