CI 묻고 답하기

제목 pdf 파일 생성 및 다운로드
글쓴이 앙마 작성시각 2014/03/14 16:04:00
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 21499   RSS
ci를 적용시키지 않은 상태에서 tcpdf를 사용해 pdf 생성 및 다운이 가능했습니다

그런데 ci에 적용시키려 하니 손을 데기가 어렵네요

<?php
//============================================================+
// File name   : example_006.php
// Begin       : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 006 for TCPDF class
//               WriteHTML and RTL support
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: WriteHTML and RTL support
 * @author Nicola Asuni
 * @since 2008-03-04
 */

// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');


// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TEACH Test');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');


// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pp_nm,"과목 : ".$sb_nm);


// 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);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO*1.3);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->SetFont('cid0kr', '', 9); 

$style = array(
 'border' => true,
 'vpadding' => 'auto',
 'hpadding' => 'auto',
 'fgcolor' => array(0,0,0),
 'bgcolor' => false, //array(255,255,255)
 'module_width' => 3, // width of a single module in points
 'module_height' => 3 // height of a single module in points
);

$pdf->AddPage();
$pdf->write2DBarcode('www.naver.com', 'QRCODE',170, 0, 25, 25, $style, '');


$pdf->setEqualColumns(2, 150);

if($problems!=null){
 foreach ($problems as $item) {
  $db_data= $item->content;

  $db_data=str_replace('<','<',$db_data);
  $db_data=str_replace('>','>',$db_data); 
  $db_data=str_replace("<tr><td width='35px' align='center'></td>","<tr><td width='35px' align='center' valign='top'><font size='15'>".$item->no." </font></td>", $db_data);
  $db_data=str_replace('\'','"',$db_data);

 // $pdf->write(0, $db_data, '', 0, 'C', true, 0, false, false, 0);

  $pdf->writeHTML($db_data, true, false, true, false, '');

 }
}

$pdf->lastPage();



// ---------------------------------------------------------

//Close and output PDF document
//$pdf->Output('example_009.pdf', 'I');
$pdf->Output("questions.pdf",'D');
//============================================================+
// END OF FILE
//============================================================+

이 코드가 중심에 되는데

ci에서 무엇무엇을 설정해줘야할지 잘 모르겠네요..




 다음글 마이그레이션 질문드립니다. (1)
 이전글 안녕하세요..질문이있습니다. (2)

댓글

헛발이 / 2014/03/15 13:22:42 / 추천 0
맞는지는 모르지만... 제가 보기엔

require_once('tcpdf_include.php'); 이것만 빼고 이거 대신에 핼퍼로 로드 시켜서...

아래는 같은 방식으로 해도 될듯 싶은데요 ...
한대승(불의회상) / 2014/03/15 19:37:51 / 추천 0
라이브러리로 적용하시면 될듯...