我试图创建一个带有一些数据的pdf文件,我从查询中获取,pdf创建者在控制器(TCPDF)中。
我的故事板: 我正在使用codeigniter来开发我的php应用程序。在我看来,有一个表,每一行都有一个按钮,用于根据其行的信息创建pdf。我可以在模态引导程序中预览它。 现在,我很困惑如何将该信息传递给pdf(TCPDF)。 我应该在控制器中使用GET或somrthing吗? 还是莫代尔?
这是我的观点
<tbody>
<?php
$no = 1;
foreach($data_request as $data) {
?>
<tr>
<td class="center"><?php echo $no++.". ";?> </td>
<td class="sorting1"><?php echo $data['id_request'];?> </td>
<td class="center"><?php echo "$name"; ?></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['time_start']));?></td>
<td class="center"><?php echo $data['keluhan'];?></td>
<td class="center"><span class="label label-warning"><?php echo $data['status_request'];?></span></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['close_request']));?></td> <td class="center">
<a class="btn btn-danger" href="#">
<i class="halflings-icon white trash"></i> Close
</a>
<a class="btn btn-success" href="#" id="print" req_id="<?php echo $data['id_request']; ?>">
<i class="halflings-icon pencil"></i> Print
</a>
</td>
</tr>
<?php } ?>
</tbody>
//This is my modal bootstrap preview :
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1>Print Preview</h1>
</div>
<div class="modal-body">
<p id="id_preview"> </p>
</div>
<div class="modal-footer">
<?php $id= $data['id_request'];?>
<a href="<?php echo base_url().'control_closing/generate_pdf/id'; ?>" class="btn btn-primary">Jadikan PDF</a>
<a href="#" class="btn" data-dismiss="modal">Close</a>
</div>
</div>
这是我的控制器
public function generate_pdf($idRequest){
$this->model_request->selectOneRequest($idRequest);
$this->load->library("TC_PDF");
$pdf = new TC_Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Dzil');
$pdf->SetTitle('Form Perbaikan / Permintaan');
$pdf->SetSubject('TMS/DEPT/IT/06');
$pdf->SetKeywords('TCPDF, PDF, form, perbaikan, Permintaan');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
$pdf->Ln(8);
$pdf->Cell(30, 5, 'Nama', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '$data_pdf[nama]', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'Departement', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'NIK', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Ln(4);
$pdf->Cell(30, 5, 'Permintaan / ', 0, 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'Perbaikan ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$html = <<<EOD
<form action="">
<input type="checkbox" name="request[]" id="Login" value="Login" > Login
<input type="checkbox" name="request[]" id="Login" value="Login" > Printer
<input type="checkbox" name="request[]" id="Login" value="Login" > Monitor
<input type="checkbox" name="request[]" id="Login" value="Login" > Computer
<input type="checkbox" name="request[]" id="Login" value="Login" > Network
<input type="checkbox" name="request[]" id="Login" value="Login" > Lain-lain
</form>
EOD;
$pdf->writeHTML($html, true, 1, false, 1);
$pdf->Ln(4);
$pdf->Cell(30, 10, 'Keluhan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 90,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(30, 10, 'Keterangan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 60,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(30, 10, 'Catatan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 10,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Ln(4);
$pdf->SetFont('helvetica', '', 8);
$pdf->Cell(30, 5, 'Tgl Permintaan / Paraf', 1, 0, 'C', 0, '', 0, false, 'T', 'C'); //width, height,
$pdf->Cell(30, 5, 'Persetujuan Manajer', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Persetujuan', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Diterima Oleh', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Terima', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Perkiraan Selesai', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Selesai', 1, 1, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T'); //width, height,
$pdf->Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Ln(2);
$pdf->SetFont('helvetica', '', 8);
$pdf->Cell(0, 0, 'TMS-IT-06 (10.2001)', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_057.pdf', 'I');
}
这是我的模特
public function selectOneRequest($id_request){
$query = $this->db->get_where('tbl_request', array('id_request'=>$id_request));
return $query->result_array();
}
答案 0 :(得分:0)
只需构建链接的href以指向generate_pdf
函数..假设您的控制器名称为Tcpdf
<a href="/tcpdf/generate_pdf/<?php echo $data['id_request']; ?>">Print</a>