Ejemplo n.º 1
14
 function convertHtmlToPdf($html)
 {
     if (!$html) {
         throw new \Exception("Html Not Given");
     }
     $pagelayout = array($this->options['width'], $this->options['height']);
     //  or array($width,$height)
     $pdf = new \TCPDF('l', 'px', $pagelayout, true, 'UTF-8', false);
     $pdf->SetMargins(0, 0, 0);
     $pdf->SetHeaderMargin(0);
     $pdf->SetFooterMargin(0);
     // $pdf = new \TCPDF_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetAutoPageBreak(false);
     if ($this->options['header_font_family']) {
         $pdf->SetFont($this->options['header_font_family']);
     }
     // add a page
     $pdf->AddPage();
     $pdf->WriteHTML($html, true, false, true, false);
     $this->pdf = $pdf->Output(null, 'S');
     //for test
     // $this->pdf = $pdf->Output(null);
     // echo $this->pdf;
     // exit;
 }
Ejemplo n.º 2
1
Archivo: pdf.php Proyecto: tmlsoft/main
 /**
  * 初始化
  *
  * @access public
  * @param  array  $params 初始化参数
  * @return void
  */
 public function __construct($params)
 {
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor($this->pdf_author);
     $pdf->SetTitle($this->pdf_title);
     $pdf->SetSubject($this->pdf_subject);
     $pdf->SetKeywords($this->pdf_keywords);
     // 不显示头部和底部
     $pdf->setPrintHeader(FALSE);
     $pdf->setPrintFooter(FALSE);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //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
     require TCPDF_BASE_PATH . 'tcpdf/config/lang/eng.php';
     $pdf->setLanguageArray($l);
     // set font
     $pdf->SetFont('stsongstdlight', '', 10);
     $pdf->AddPage();
     $pdf->writeHTML($params['content'], true, false, true, false, '');
     $pdf->lastPage();
     // 输出方式 I:浏览器直接输出 D:文件下载 如果需要浏览器输出或者下载的同时生成文件请在前面加上F
     $pdf->Output($params['filename'], $params['flag']);
 }
Ejemplo n.º 3
1
 function __construct()
 {
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $this->pdf = $pdf;
     $this->widths = new stdClass();
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetAutoPageBreak(false);
     $pdf->AddPage();
 }
Ejemplo n.º 4
1
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $dispatcher =& JDispatcher::getInstance();
     /* Load the event details */
     $course = $this->get('Details');
     $venue = $this->get('Venue');
     $pdf = new TCPDF("P", "mm", "A4", true);
     $pdf->SetCreator($mainframe->getCfg('sitename'));
     $pdf->SetAuthor($mainframe->getCfg('sitename'));
     $pdf->SetTitle($course->title);
     $pdf->SetSubject($course->title);
     $pdf->setHeaderFont(array('freesans', '', 8));
     $pdf->setFooterFont(array('freesans', '', 8));
     $pdf->setFont('freesans');
     // disable header and footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(true);
     //set the display mode
     $pdf->SetDisplayMode('default');
     //initialize document
     $pdf->AliasNbPages();
     // add a page
     $pdf->AddPage();
     $pdf->SetFontSize(10);
     /* This loads the tags replacer */
     JView::loadHelper('tags');
     $tags = new redEVENT_tags();
     $tags->setXref(JRequest::getInt('xref'));
     $message = $tags->ReplaceTags($course->submission_type_email_pdf);
     // convert urls
     $htmlmsg = REOutput::ImgRelAbs($message);
     $pdf->WriteHTML($message, true);
     // add the form data if requested
     if ($course->pdf_form_data) {
         JRequest::setVar('pdfform', $pdf);
         JPluginHelper::importPlugin('content');
         $form = new stdClass();
         $form->text = '{redform}' . $course->redform_id . ',1{/redform}';
         $form->eventid = $course->did;
         $form->task = 'userregister';
         $results = $dispatcher->trigger('onPrepareEvent', array(&$form, array(), 0));
         $pdf->WriteHTML($form->text, true);
     }
     // output the file
     $pdf->Output($course->title . ".pdf", "I");
     exit;
 }
Ejemplo n.º 5
0
 public function run()
 {
     include getcwd() . '/vendor/autoload.php';
     $navStructure = (include getcwd() . '/docs/navigation.php');
     echo "Loading markdown...\n";
     $markdown = $this->findMarkdown($navStructure);
     echo "Converting markdown to html...\n";
     $Parsedown = new \Parsedown();
     $html = $Parsedown->text($markdown);
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     #$pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('My Documentation');
     #$pdf->SetSubject('TCPDF Tutorial');
     #$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetFont('helvetica', '', 20);
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->AddPage();
     $pdf->writeHTML($html, true, 0, true, 0);
     $pdf->lastPage();
     echo "Writing PDF...\n";
     $pdf->Output($this->config['output'], 'F');
     echo "Complete.\n";
 }
Ejemplo n.º 6
0
 function processing($contextData, $options)
 {
     $prodId = $contextData[0]['id'];
     $prodName = $contextData[0]['name'];
     $unitPrice = $contextData[0]['unitprice'];
     $pFile = $contextData[0]['photofile'];
     $timestamp = new DateTime();
     $tsString = $timestamp->format("Y-m-d H:i:s");
     $fileName = "{$prodId}.pdf";
     require_once './tcpdf/tcpdf.php';
     $pdf = new TCPDF("P", "mm", "A4", true, "UTF-8");
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetMargins(0, 0, 0, 0);
     $pdf->AddPage();
     $pdf->setTextColor(100, 100, 100);
     $pdf->SetFont('', '', 14);
     $pdf->Text(40, 40, "Product ID: {$prodId}");
     $pdf->Text(40, 50, "Product Name: {$prodName}");
     $pdf->Text(40, 60, "Unit Price: {$unitPrice}");
     $pdf->Text(40, 70, "Today: {$tsString}");
     $pdf->Image("../Sample_products/images/{$pFile}", 40, 80, 100);
     header("Content-Type: application/pdf");
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     header('X-Frame-Options: SAMEORIGIN');
     $pdf->Output();
 }
Ejemplo n.º 7
0
 /**
  * Render a PDF file and show in browser or save to disk
  * If save to disk return file location
  */
 public function renderRfqRequest($quote, $saveToDisk = false)
 {
     $storeid = $quote->getStoreId();
     if ($storeid) {
         $appEmulation = Mage::getSingleton('core/app_emulation');
         $initial = $appEmulation->startEnvironmentEmulation($storeid, Mage_Core_Model_App_Area::AREA_FRONTEND, true);
     }
     $pdf = new TCPDF();
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->AddPage();
     $pdf->SetAutoPageBreak(true, 30);
     $pdf->setHeaderMargin(20);
     $pdf->setFooterMargin(20);
     $pdf->setImageScale(1.5);
     $emailtext = Mage::helper('request4quote/email')->sendRequestProposalNotification($quote, false, true);
     $pdf->writeHTML(Mage::helper('cms')->getBlockTemplateProcessor()->filter($emailtext), false);
     $pdf->endPage();
     if ($storeid) {
         $appEmulation->stopEnvironmentEmulation($initial);
     }
     $rfqfilename = 'rfq_' . $quote->getId() . '.pdf';
     if (!$saveToDisk) {
         return $pdf->Output($rfqfilename);
     } else {
         if ($saveToDisk) {
             $filePath = $this->getFilePath() . $rfqfilename;
             $pdf->Output($filePath, 'F');
             return $filePath;
         }
     }
     exit;
 }
Ejemplo n.º 8
0
 /**
  * @param string $html 要转为pdf的内容
  * @param string $filename 文件名
  * @param string $type 'I'在页面中显示;'D'直接下载
  */
 public static function pdf($html, $filename = 'hzd.pdf', $type = 'I')
 {
     import("Tools.TCPDF.TCPDF");
     import("Tools.TCPDF.config.tcpdf_config.php");
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('HZD');
     $pdf->SetTitle('HZD');
     $pdf->SetSubject('HZD');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $pdf->setPrintHeader(false);
     //不显示头部
     $pdf->setPrintFooter(false);
     //不显示底部
     // 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 font
     $pdf->SetFont('stsongstdlight', '', 20);
     // add a page
     $pdf->AddPage();
     // output the HTML content
     $pdf->writeHTML($html, true, false, true, false, '');
     // ---------------------------------------------------------
     //Close and output PDF document
     $pdf->Output($filename, $type);
 }
 /**
  * Class constructor
  *
  * @param mixed  $paper       The size of paper to use either a string (see {@link CPDF_Adapter::$PAPER_SIZES}) or
  *                            an array(xmin,ymin,xmax,ymax)
  * @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
  * @param DOMPDF $dompdf
  */
 function __construct($paper = "letter", $orientation = "portrait", DOMPDF $dompdf)
 {
     //***
     if (is_array($paper)) {
         $size = $paper;
     } else {
         if (isset(self::$PAPER_SIZES[mb_strtolower($paper)])) {
             $size = self::$PAPER_SIZES[mb_strtolower($paper)];
         } else {
             $size = self::$PAPER_SIZES["letter"];
         }
     }
     $ori = 'P';
     // ***
     if (mb_strtolower($orientation) === "landscape") {
         list($size[2], $size[3]) = array($size[3], $size[2]);
         $ori = 'L';
         // ***
     }
     $this->_width = $size[2] - $size[0];
     $this->_height = $size[3] - $size[1];
     $this->_dompdf = $dompdf;
     //***$this->_pdf = new My_TCPDF('P', 'pt', $paper, true, 'UTF-8', false);
     $this->_pdf = new My_TCPDF($ori, 'pt', $paper, true, 'UTF-8', false);
     // ***
     $this->_pdf->SetCreator("DOMPDF Converter");
     // CreationDate and ModDate info are added by TCPDF itself
     // don't use TCPDF page defaults
     $this->_pdf->SetAutoPageBreak(false);
     $this->_pdf->SetMargins(0, 0, 0, true);
     $this->_pdf->setPrintHeader(false);
     // remove default header/footer
     $this->_pdf->setPrintFooter(false);
     $this->_pdf->setHeaderMargin(0);
     $this->_pdf->setFooterMargin(0);
     $this->_pdf->SetCellPadding(0);
     $this->_pdf->AddPage();
     $this->_pdf->SetDisplayMode('fullpage', 'continuous');
     $this->_page_number = $this->_page_count = 1;
     $this->_page_text = array();
     $this->_pages = array($this->_pdf->PageNo());
     $this->_image_cache = array();
     // other TCPDF stuff...
     $this->_objs = array();
     // for templating support
     $this->_nameddest = array();
     // for internal link support
     $this->_internal_links = array();
     //		"	"	"
     $this->_pdf->setAlpha(1.0);
     $this->_currentLineTransparency = array("mode" => "Normal", "opacity" => 1.0);
     $this->_currentFillTransparency = array("mode" => "Normal", "opacity" => 1.0);
     $this->_last_fill_color = $this->_last_stroke_color = null;
     //dompdf_debug("trace", "Exit");
 }
Ejemplo n.º 10
0
 private function getPdfData()
 {
     $pdf = new \TCPDF();
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetFont('times', 'BI', 12);
     $pdf->AddPage();
     $pdf->Write(0, 'Fichier pdf', '', 0, 'C', true, 0, false, false, 0);
     return $pdf->Output('fichier.pdf', 'S');
 }
 function Adresaro()
 {
     $pdf = new TCPDF();
     $tiparo = "freesans";
     $pdf->AddFont($tiparo, '', $tiparo . ".php");
     $pdf->AddFont($tiparo, 'B', $tiparo . "b.php");
     $pdf->setFont($tiparo);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->setAutoPageBreak(false);
     $pdf->Open();
     $this->pdf =& $pdf;
 }
Ejemplo n.º 12
0
 function orderViewPDF()
 {
     $l = null;
     require_once OSEMSC_F_PATH . DS . 'libraries' . DS . 'tcpdf' . DS . 'tcpdf.php';
     require_once OSEMSC_F_PATH . DS . 'libraries' . DS . 'tcpdf' . DS . 'config' . DS . 'lang' . DS . 'eng.php';
     $order_id = JRequest::getInt('order_id', 0);
     //$my = JFactory::getUser();
     $member_id = JRequest::getInt('member_id', 0);
     $where = array();
     $where[] = " `order_id` = {$order_id}";
     $where[] = " `user_id` = {$member_id}";
     $orderInfo = oseRegistry::call('payment')->getOrder($where, 'obj');
     if (empty($orderInfo)) {
         $result = array();
         $result['title'] = 'Error';
         $result['content'] = 'Error';
         oseExit('Error');
     }
     $receipt = oseRegistry::call('member')->getReceipt($orderInfo);
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('OSEMSC');
     $pdf->SetTitle('Invoice #' . $order_id);
     $pdf->SetSubject('Invoice');
     $pdf->SetKeywords('invoice');
     // set default header data
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $pdf->SetMargins(30, 18, 30);
     //set some language-dependent strings
     $pdf->setLanguageArray($l);
     $pdf->SetAutoPageBreak(TRUE, 10);
     $pdf->AddPage();
     //ob_get_clean();
     $pdf->WriteHTML($receipt->body, true);
     $pdf->Output("Invoice-#{$order_id}.pdf", "I");
     oseExit();
     /*
     //$receipt = self::orderView();
     $order_id = JRequest::getInt('order_id');
     
     $app = JFactory::getApplication('SITE');
     //oseExit('dfdf');
     $app->redirect( JRoute::_('index.php?option=com_osemsc&view=member&format=pdf&memberTask=generateOrderView&order_id='.$order_id));
     */
 }
Ejemplo n.º 13
0
 public function __construct()
 {
     //		$orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false
     $pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetDefaultMonospacedFont('courier');
     $pdf->SetMargins(10, 10, 7, true);
     $pdf->SetAutoPageBreak(true, 5);
     $pdf->setImageScale(1);
     $pdf->SetFont('freeserif', '', 12, '', false);
     $pdf->SetLineWidth(0.05);
     $this->pdf = $pdf;
     $this->cell = new cell($this->pdf);
 }
Ejemplo n.º 14
0
 /**
  * 
  * @param string $orientation P / L
  * @param string $size paper size
  * @param string $title document title
  * @return \TCPDF model
  */
 public function initializePdf($orientation, $size, $title)
 {
     Yii::createComponent('ext.tcpdf.TcPdf', 'P', 'cm', 'A4', true, 'UTF-8');
     spl_autoload_unregister(array('YiiBase', 'autoload'));
     $pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     spl_autoload_register(array('YiiBase', 'autoload'));
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetTitle($title);
     //no headers and footers
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //automatically insert page break bottom
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->addPage($orientation, $size);
     return $pdf;
 }
Ejemplo n.º 15
0
 public function create_pdf_from_eml($piler_id = '', $text = '', $images = array())
 {
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetAuthor('Yourcompany Ltd');
     $pdf->SetTitle('EML email title');
     $pdf->SetSubject('EML email subject');
     //$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // set default header data
     //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,190,255), array(0,64,128));
     //$pdf->setFooterData($tc=array(0,64,0), $lc=array(0,64,128));
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     //$pdf->SetMargins(10, 25, 10);
     $pdf->SetMargins(10, 5, 10);
     //$pdf->SetHeaderMargin(120);
     //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //set auto page breaks
     //$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->SetAutoPageBreak(TRUE, 20);
     //set image scale factor
     //$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     //set some language-dependent strings
     //$pdf->setLanguageArray($l);
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     $pdf->SetFont('dejavusans', '', 8, '', true);
     $pdf->AddPage();
     $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $text, $border = 0, $ln = 1, $fill = 0, $reseth = true, 'L', $autopadding = true);
     $i = 0;
     foreach ($images as $img) {
         if ($i > 0) {
             $pdf->AddPage();
         }
         $pdf->Image(DIR_BASE . 'tmp/' . $img['id']);
         $i++;
     }
     $pdf->Output(DIR_BASE . 'tmp/' . $piler_id . '.pdf', 'F');
 }
Ejemplo n.º 16
0
function exportDataToPDF($content)
{
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Matija Lovreković');
    $pdf->SetTitle('Rezultati pretrage');
    $pdf->SetSubject('DWA Lab 4');
    $pdf->SetKeywords('DWA');
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $pdf->SetFont('dejavusans', '', 20, '', true);
    $pdf->AddPage();
    $pdf->writeHTML($content);
    ob_end_clean();
    $pdf->Output('rezultati_pretrage.pdf', 'I');
}
Ejemplo n.º 17
0
 /**
  * Generate the pdf document
  * @param   IsotopeProductCollection
  * @param   array
  * @return  \TCPDF
  */
 protected function generatePDF(IsotopeProductCollection $objCollection, array $arrTokens)
 {
     // TCPDF configuration
     $l = array();
     $l['a_meta_dir'] = 'ltr';
     $l['a_meta_charset'] = $GLOBALS['TL_CONFIG']['characterSet'];
     $l['a_meta_language'] = substr($GLOBALS['TL_LANGUAGE'], 0, 2);
     $l['w_page'] = 'page';
     // Include TCPDF config
     require_once TL_ROOT . '/system/config/tcpdf.php';
     if (version_compare(VERSION, '3.3', '<')) {
         require_once TL_ROOT . '/system/modules/core/vendor/tcpdf/tcpdf.php';
     }
     // Create new PDF document
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
     // Set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor(PDF_AUTHOR);
     $pdf->SetTitle(\String::parseSimpleTokens($this->documentTitle, $arrTokens));
     // Prevent font subsetting (huge speed improvement)
     $pdf->setFontSubsetting(false);
     // Remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // Set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     // 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
     $pdf->setLanguageArray($l);
     // Initialize document and add a page
     $pdf->AddPage();
     // Set font
     $pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN);
     // Write the HTML content
     $pdf->writeHTML($this->generateTemplate($objCollection, $arrTokens), true, 0, true, 0);
     $pdf->lastPage();
     return $pdf;
 }
 function generate_product_report_pdf($data = null)
 {
     App::import('Vendor', 'tcpdf/tcpdf');
     $tcpdf = new TCPDF();
     $textfont = 'helvetica';
     $tcpdf->SetAutoPageBreak(true);
     $tcpdf->setPrintHeader(false);
     $tcpdf->setPrintFooter(false);
     $tcpdf->SetTextColor(0, 0, 0);
     $tcpdf->SetFont($textfont, '', 10);
     $tcpdf->AddPage();
     // session details
     $htmlcontent = "<html><body>";
     $htmlcontent .= "<strong><h2>Product Report</h2></strong>";
     $htmlcontent .= "<br/>";
     // table start
     $htmlcontent .= "<table border=\".5\" >\r\r\n                <tr>\r\r\n                        <td align='left' valign='top'><strong>Product</strong></td>\r\r\n\t\t\t<td align='left' valign='top'><strong>Product Code</strong></td>\r\r\n\t\t\t<td align='left' valign='top'><strong>Status</strong></td>\r\r\n\t\t\t<td align='left' valign='top'><strong>Created</strong></td>\r\r\n                </tr>";
     $charges = "No";
     if (count($data) > 0) {
         $status = array('Deactive', 'Active');
         foreach ($data as $result) {
             $htmlcontent .= "<tr><td align='left' valign='top'>";
             $htmlcontent .= $result['Product']['title'];
             $htmlcontent .= "</td><td align='left' valign='top'>";
             $htmlcontent .= $result['Product']['product_code'];
             $htmlcontent .= "</td><td align='left' valign='top'>";
             $htmlcontent .= $status[$result['Product']['is_active']];
             $htmlcontent .= "</td><td align='left' valign='top'>";
             $htmlcontent .= $result['Product']['created'];
             $htmlcontent .= "</td></tr>";
         }
     } else {
         $htmlcontent .= "<tr><td colspan='4' style='border-bottom:0px' class='tc'>No records found</td></tr>";
     }
     $htmlcontent .= "</table></body></html>";
     // output the HTML content
     $tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
     $tcpdf->Output('product_report.pdf', 'D');
     exit;
 }
Ejemplo n.º 19
0
function generate_pdf($start, $end, $userid, $courseid, $method = 'I', $base = '', $timesheetid = -1, $unsignedonly = false)
{
    global $CFG, $DB;
    $htmlpages = generate_html($start, $end, $userid, $courseid, $timesheetid, $unsignedonly);
    // Collect Data
    $conf = get_timetracker_config($courseid);
    $month = userdate($start, "%m");
    $year = userdate($start, "%Y");
    $workerrecord = $DB->get_record('block_timetracker_workerinfo', array('id' => $userid));
    if (!$workerrecord) {
        print_error('usernotexist', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $courseid);
    }
    // ********** BEGIN PDF ********** //
    // Create new PDF
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $fn = $year . '_' . ($month < 10 ? '0' . $month : $month) . 'Timesheet_' . substr($workerrecord->firstname, 0, 1) . $workerrecord->lastname . '_' . $workerrecord->mdluserid;
    // Set Document Data
    $pdf->setCreator(PDF_CREATOR);
    $pdf->SetFont('helvetica', '', 8);
    $pdf->SetCellPadding(0);
    $pdf->SetTitle($fn);
    $pdf->SetAuthor('TimeTracker');
    $pdf->SetSubject(' ');
    $pdf->SetKeywords(' ');
    // Remove Default Header/Footer
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    foreach ($htmlpages as $page) {
        $pdf->AddPage();
        $pdf->writeHTML($page);
    }
    //create the filename
    $fn .= '.pdf';
    //Close and Output PDF document
    //change the $method from 'I' to $method -- allow more than just a single file
    //to be created
    $pdf->Output($base . '/' . $fn, $method);
    return $fn;
}
Ejemplo n.º 20
0
    public function testPdfOutput()
    {
        // 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('TCPDF Example 002');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // remove default header/footer
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        // 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)
        $pdf->setLanguageArray($this->langSettings);
        // ---------------------------------------------------------
        // set font
        $pdf->SetFont('times', 'BI', 20);
        // add a page
        $pdf->AddPage();
        // set some text to print
        $txt = <<<EOD
TCPDF Example 002

Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
EOD;
        // print a block of text using Write()
        $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
        $this->comparePdfs($pdf);
    }
Ejemplo n.º 21
0
 /**
  * Saves as a PDF to a file.
  *
  * @param string $file_name File name
  *
  * @return void
  * @access public
  */
 public function toFileAsPdf($file_name)
 {
     $this->init();
     include_once './libraries/tcpdf/tcpdf.php';
     // create pdf
     $pdf = new TCPDF('', 'pt', $GLOBALS['cfg']['PDFDefaultPageSize'], true, 'UTF-8', false);
     // disable header and footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //set auto page breaks
     $pdf->SetAutoPageBreak(false);
     // add a page
     $pdf->AddPage();
     $scale_data = $this->_scaleDataSet($this->_data);
     $pdf = $this->_prepareDataSet($this->_data, $scale_data, 'pdf', $pdf);
     // sanitize file name
     $file_name = $this->_sanitizeName($file_name, 'pdf');
     $pdf->Output($file_name, 'D');
 }
} else {
    require "../config.php";
}
require "../db.class.php";
$db = new Database($dbserver, $dbuser, $dbpassword, $dbname);
$db->connect();
// create new PDF document
$pdf = new TCPDF('L', PDF_UNIT, 'A5', true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('OpenSourceBikeShare');
$pdf->SetTitle('OpenSourceBikeShare QR codes');
$pdf->SetSubject('QR codes for bikes and stands');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(0, 0, 0);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set font
$pdf->SetFont('helvetica', 'B', 50);
// set style for barcode
$style = array('border' => 0, 'vpadding' => 1, 'hpadding' => 0, 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'module_width' => 1, 'module_height' => 1, 'position' => 'C');
$result = $db->query("SELECT bikeNum FROM bikes ORDER BY bikeNum");
Ejemplo n.º 23
0
$pdf = new TCPDF('P', 'mm', 'Letter', true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Tramas');
$pdf->SetTitle('Generacion_de_contraseñas');
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetHeaderMargin(1);
$pdf->SetMargins(10, 47, 10);
$pdf->SetFooterMargin(7);
$pdf->SetAutoPageBreak(TRUE, 15);
//$pdf->setFontSubsetting(true);
$pdf->SetFont('Helvetica', '', 8, '', true);
$pdf->setPrintHeader(true);
//no imprime la cabecera ni la linea
$pdf->setPrintFooter(true);
// imprime el pie ni la linea
$pdf->SetHeaderData('img1.png', 180, "", "", array(0, 64, 255), array(0, 64, 128));
$pdf->AddPage();
// set cell padding
$pdf->setCellPaddings(0, 0, 2, 0);
// set cell margins
$pdf->setCellMargins(0.5, 0.5, 0.5, 0.5);
//*************
ob_end_clean();
//rompimiento de pagina
//*************
$cadena = '';
//$cadena .= '<center><div><img src="img10.png" alt="attribute" width="500" height="150" border="0" ></div></center>';
$cadena .= $_SESSION['encabezado_tabla'];
$cadena .= $_SESSION['cuerpo_tabla'];
Ejemplo n.º 24
0
    public function bend29()
    {
        $id = Input::get('nomor');
        if (substr($id, 0, 3) == 'ALO') {
            $data = DB::table('pkm_alokasi')->where('nomor', $id)->first();
            $dtl = DB::table('pkm_alokasidtl')->join('aset_data', 'pkm_alokasidtl.id_inventori', '=', 'aset_data.id')->where('nomor', $id)->where('tipe', 'aset')->get();
        } else {
            $data = DB::table('aset_keluar')->where('nomor', $id)->first();
            $dtl = DB::table('aset_keluardtl')->join('aset_data', 'aset_keluardtl.id_inventori', '=', 'aset_data.id')->where('nomor', $id)->select('aset_data.*')->get();
        }
        $ka1 = DB::table('pkm_pegawai')->where('id_unit', $data->id_puskesmas)->where('jabatan', 1)->first();
        $ka2 = DB::table('pkm_pegawai')->where('id_unit', $data->id_unit)->where('jabatan', 1)->first();
        $pb1 = DB::table('pkm_pegawai')->where('id', Input::get('pihak1'))->first();
        $pb2 = DB::table('pkm_pegawai')->where('id', Input::get('pihak2'))->first();
        $header = '
            <table>
                <tr style="font-weight: bold">
                    <td colspan="7" style="text-align: left"><br><br><br><br><br><br><br><br><br></td>
                </tr>
                <tr style="font-weight: bold">
                    <td colspan="4" style="text-align: left">PEMERINTAH KOTA SURABAYA</td>
                    <td colspan="3" style="text-align: right">BEND. 29</td>
                </tr>
                <tr style="font-weight: bold">
                    <td colspan="4" style="text-align: left">&nbsp;</td>
                    <td colspan="3" style="text-align: right">NOMOR JURNAL : ' . $id . '</td>
                </tr>
                <tr style="font-size: large;font-weight: bold">
                    <td colspan="7" style="text-align: center">BUKTI PENYERAHAN BARANG DARI DAERAH/UNIT: ' . $data->nama_puskesmas . '</td>
                </tr>
                <tr style="font-size: large;font-weight: bold">
                    <td colspan="7" style="text-align: center">KEPADA DAERAH:UNIT : ' . $data->nama_unit . '</td>
                </tr>
                <tr style="font-size: large;font-weight: bold">
                    <td colspan="7" style="text-align: center">NO BERITA ACARA SERAH TERIMA: 028/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.24/436.6.3/2014</td>
                </tr>
                <tr style="font-size: large;font-weight: bold">
                    <td colspan="7" style="text-align: center">&nbsp;</td>
                </tr>
            </table>
            <table border="1" cellspacing="3">
                <thead>
                    <tr style="font-weight: bold;text-align: center;">
                        <th rowspan="2" style="width: 10%">NO</th>
                        <th rowspan="2" style="width: 10%">TANGGAL</th>
                        <th rowspan="2" style="width: 30%">Nama & Spesifikasi Barang <br> (Merk, Tipe, Kode, Kode Neraca, No Reg Induk)</th>
                        <th rowspan="2" style="width: 10%">SATUAN</th>
                        <th colspan="2" style="width: 20%">JUMLAH</th>
                        <th rowspan="2" style="width: 20%">NILAI (Rp)</th>
                    </tr>
                    <tr style="font-weight: bold;text-align: center;">
                        <th style="width: 10%">ANGKA</th>
                        <th style="width: 10%">HURUF</th>
                    </tr>
                </thead>
        ';
        $footer = '</table>';
        $content = '';
        for ($i = 0; $i < count($dtl); $i++) {
            $jml = $dtl[$i]->jumlah * $dtl[$i]->h_satuan;
            $content .= '
                <tr style="text-align: center;">
                    <td style="width: 10%">' . ($i + 1) . '</td>
                    <td style="width: 10%">' . $data->tanggal . '</td>
                    <td style="width: 30%;text-align: left;">&nbsp;' . $dtl[$i]->nama . '<br>&nbsp;' . $dtl[$i]->kode_bidang . '<br>&nbsp;' . $dtl[$i]->kode_perwali . '<br>&nbsp;' . $dtl[$i]->no_register . '</td>
                    <td style="width: 10%">' . $dtl[$i]->satuan . '</td>
                    <td style="width: 10%">' . $dtl[$i]->jumlah . '</td>
                    <td style="width: 10%">' . Terbilang::rupiah($dtl[$i]->jumlah) . '</td>
                    <td style="width: 20%;text-align: right;">' . number_format($jml + $jml * $dtl[$i]->ppn / 100) . '</td>
                </tr>
            ';
        }
        //$peg1 = DB::table('pkm_pegawai')->where('id_unit', $data->id_unit)->where('jabatan', 2)->first();
        if (Auth::user()->id_puskesmas == '0999') {
            $tt = '<tr>
                    <td style="width: 20%"></td>
                    <td style="width: 60%">
                        <table cellpadding="5">
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr>
                                <td style="text-align: right">Mengetahui,</td>
                                <td style="width: 2%"></td>
                                <td></td>
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr>
                                <td>Tanda Tangan</td>
                                <td style="width: 2%">:</td>
                                <td>............................</td>
                            </tr>
                            <tr>
                                <td>NAMA</td>
                                <td style="width: 2%">:</td>
                                <td>NANIK SUKRISTINA, SKM</td>
                            </tr>
                            <tr>
                                <td>NIP</td>
                                <td style="width: 2%">:</td>
                                <td>19700117 199403 2 008</td>
                            </tr>
                            <tr>
                                <td>PANGKAT</td>
                                <td style="width: 2%">:</td>
                                <td>PEMBINA / IV A</td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 20%"></td>
                </tr>';
        } else {
            $tt = '<tr>
                    <td colspan="3" style="width: 48%">
                        <table cellpadding="5">

                            <tr>
                                <td colspan="3">Mengetahui,</td>
                            </tr>
                            <tr>
                                <td>Tanda Tangan</td>
                                <td style="width: 2%">:</td>
                                <td>............................</td>
                            </tr>
                            <tr>
                                <td>NAMA</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka2->nama_pegawai . '</td>
                            </tr>
                            <tr>
                                <td>NIP</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka2->nip . '</td>
                            </tr>
                            <tr>
                                <td>PANGKAT</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka2->pangkat . '</td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 5%">&nbsp;</td>
                    <td colspan="3" style="width: 47%">
                        <table cellpadding="5">
                            <tr>
                                <td colspan="3">Yang Menyerahkan,</td>
                            </tr>
                            <tr>
                                <td>Tanda Tangan</td>
                                <td style="width: 2%">:</td>
                                <td>............................</td>
                            </tr>
                            <tr>
                                <td>NAMA</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka1->nama_pegawai . '</td>
                            </tr>
                            <tr>
                                <td>NIP</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka1->nip . '</td>
                            </tr>
                            <tr>
                                <td>PANGKAT</td>
                                <td style="width: 2%">:</td>
                                <td>' . $ka1->pangkat . '</td>
                            </tr>
                        </table>
                    </td>
                </tr>';
        }
        $ttd = '
            <table>
                <tr><td colspan="7">&nbsp;</td></tr>
                <tr><td colspan="7">&nbsp;</td></tr>
                <tr>
                    <td colspan="3" style="width: 48%">
                        <table cellpadding="5">
                            <tr>
                                <td>DAERAH</td>
                                <td style="width: 2%">:</td>
                                <td style="width: 90%">KOTA SURABAYA</td>
                            </tr>
                            <tr>
                                <td>UNIT</td>
                                <td style="width: 2%">:</td>
                                <td>' . $data->nama_puskesmas . '</td>
                            </tr>
                            <tr>
                                <td>TANGGAL</td>
                                <td style="width: 2%">:</td>
                                <td>' . date("d/m/Y") . '</td>
                            </tr>
                            <tr>
                                <td colspan="3">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="3">Yang Menerima,</td>
                            </tr>
                            <tr>
                                <td>Tanda Tangan</td>
                                <td style="width: 2%">:</td>
                                <td>............................</td>
                            </tr>
                            <tr>
                                <td>NAMA</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb2->nama_pegawai . '</td>
                            </tr>
                            <tr>
                                <td>NIP</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb2->nip . '</td>
                            </tr>
                            <tr>
                                <td>PANGKAT</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb2->pangkat . '</td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 5%">&nbsp;</td>
                    <td colspan="3" style="width: 47%">
                        <table cellpadding="5">
                            <tr>
                                <td></td><td></td><td></td>
                            </tr>
                            <tr>
                                <td>Dibuat di</td>
                                <td style="width: 2%">:</td>
                                <td>SURABAYA</td>
                            </tr>
                            <tr>
                                <td>TANGGAL</td>
                                <td style="width: 2%">:</td>
                                <td>' . date("d/m/Y") . '</td>
                            </tr>
                            <tr>
                                <td colspan="3">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="3">Yang Menyerahkan,</td>
                            </tr>
                            <tr>
                                <td>Tanda Tangan</td>
                                <td style="width: 2%">:</td>
                                <td>............................</td>
                            </tr>
                            <tr>
                                <td>NAMA</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb1->nama_pegawai . '</td>
                            </tr>
                            <tr>
                                <td>NIP</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb1->nip . '</td>
                            </tr>
                            <tr>
                                <td>PANGKAT</td>
                                <td style="width: 2%">:</td>
                                <td>' . $pb1->pangkat . '</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                ' . $tt . '
            </table>
        ';
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor(PDF_AUTHOR);
        $pdf->SetTitle('Gudang DKK');
        $pdf->SetSubject('Laporan Penerimaan Barang Pengadaan');
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        $pdf->SetAutoPageBreak(TRUE, 8);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // CONTENT-------------------------------------------
        $pdf->AddPage('P', 'A4');
        /*$pdf->SetFont('helvetica', 'B', 10);
          $pdf->Write(0, "PEMERINTAH KOTA SURABAYA", '', 0, 'C', true, 0, false, false, 0);
          $pdf->SetFont('helvetica', 'B', 12);
          $pdf->Write(0, "DINAS KESEHATAN KOTA SURABAYA", '', 0, 'C', true, 0, false, false, 0);
          $pdf->SetFont('helvetica', 'U', 10);
          $pdf->Write(0, "JL. JEMURSARI NO 197 Tlp (031)8439473, 8439372, Fax. (031)8494965", '', 0, 'C', true, 0, false, false, 0);
          $pdf->SetFont('helvetica', 'B', 10);
          $pdf->Write(0, , '', 0, 'C', true, 0, false, false, 0);*/
        $pdf->ln();
        $pdf->SetFont('helvetica', '', 8);
        $pdf->writeHTML($header . $content . $footer . $ttd, true, false, false, false, '');
        $pdf->Output('ben29' . date('d-m-Y') . ' . pdf', 'I');
    }
Ejemplo n.º 25
0
 /**
  * @Route("/pdf/{id}")
  */
 public function pdfAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $conf = $this->container->getParameter('metador');
     $metadata = $this->get('metador_metadata');
     $data = $metadata->getById($id);
     if ($data) {
         $p = $data->getObject();
         ksort($p);
         $html = $this->render($conf['templates']['form'] . '::pdf.html.twig', array("p" => $p));
         error_reporting(E_ERROR);
         require_once __DIR__ . '/../../../../vendor/tecnick.com/tcpdf/tcpdf.php';
         $pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false, false);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetAuthor('Metador');
         $pdf->SetTitle($p['title']);
         $pdf->SetSubject('Metadaten');
         $pdf->SetFont('helvetica', '', 10);
         $pdf->SetMargins(20, 20, 15);
         $pdf->setPrintHeader(false);
         $pdf->setPrintFooter(false);
         $pdf->setAutoPageBreak(true, 20);
         $pdf->AddPage();
         $pdf->writeHTML($html->getContent(), true, true, false, false, '');
         $pdf->Output(md5($p['fileIdentifier']) . '.pdf', 'D');
     } else {
         // TODO: add error handling
         $xml = $this->render("WhereGroupMetadorBundle::exception.xml.twig", array("message" => "Datensatz nicht gefunden."));
     }
     $response = new Response();
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($xml->getContent());
     return $response;
 }
Ejemplo n.º 26
0
    /**
     * Generate JSON array for grid rendering
     * @param $grid_id Unique ID for grid
     */
    function render($grid_id)
    {
        // render grid for first time (non ajax), but specific grid on ajax calls
        $is_ajax = isset($_REQUEST["nd"]) || isset($_REQUEST["oper"]) || isset($_REQUEST["export"]);
        if ($is_ajax && $_REQUEST["grid_id"] != $grid_id) {
            return;
        }
        $append_by = strpos($this->options["url"], "?") === false ? "?" : "&";
        $this->options["url"] .= $append_by . "grid_id={$grid_id}";
        $this->options["editurl"] .= $append_by . "grid_id={$grid_id}";
        $this->options["cellurl"] .= $append_by . "grid_id={$grid_id}";
        if (isset($_REQUEST["subgrid"])) {
            $grid_id .= "_" . $_REQUEST["subgrid"];
        }
        // generate column names, if not defined
        if (!$this->options["colNames"]) {
            $this->set_columns();
        }
        // manage uploaded files
        foreach ($this->options["colModel"] as $col) {
            if ($col["edittype"] == "file") {
                $this->require_upload_ajax = 1;
                $this->options["add_options"]["onInitializeForm"] = "function(formid) \n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('method','POST');\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('action','');\n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery(formid).attr('enctype','multipart/form-data');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                $this->options["add_options"]["recreateForm"] = true;
                $this->options["add_options"]["afterSubmit"] = "function(r,d) { \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tajaxFileUpload('" . $col["name"] . "','" . $this->options["url"] . "'); \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn [true,'','']; \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                $this->options["edit_options"]["afterSubmit"] = "function(formid) { \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tajaxFileUpload('" . $col["name"] . "','" . $this->options["url"] . "'); \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn [true,'','']; \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}";
                break;
            }
        }
        // manage uploaded files
        if (count($_FILES)) {
            $files = array_keys($_FILES);
            $fileElementName = $files[0];
            if (!empty($_FILES[$fileElementName]['error'])) {
                switch ($_FILES[$fileElementName]['error']) {
                    case '1':
                        $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                        break;
                    case '2':
                        $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                        break;
                    case '3':
                        $error = 'The uploaded file was only partially uploaded';
                        break;
                    case '4':
                        $error = 'No file was uploaded.';
                        break;
                    case '6':
                        $error = 'Missing a temporary folder';
                        break;
                    case '7':
                        $error = 'Failed to write file to disk';
                        break;
                    case '8':
                        $error = 'File upload stopped by extension';
                        break;
                    case '999':
                    default:
                        $error = 'No error code avaiable';
                }
            } elseif (empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') {
                $error = 'No file was uploaded..';
            } else {
                foreach ($this->options["colModel"] as $col) {
                    if ($col["edittype"] == "file" && $col["name"] == $fileElementName) {
                        $tmp_name = $_FILES[$fileElementName]["tmp_name"];
                        $name = $_FILES[$fileElementName]["name"];
                        $uploads_dir = $col["upload_dir"];
                        if (move_uploaded_file($tmp_name, "{$uploads_dir}/{$name}")) {
                            $msg = "File Uploaded";
                        } else {
                            $error = "Unable to move to desired folder {$uploads_dir}/{$name}";
                        }
                        break;
                    }
                }
            }
            echo "{";
            echo "error: '" . $error . "',\n";
            echo "msg: '" . $msg . "'\n";
            echo "}";
            die;
        }
        // for duplicate row function
        if ($_POST["id"] == "_empty") {
            $_POST["oper"] = "add";
        }
        if (isset($_POST['oper'])) {
            $op = $_POST['oper'];
            $data = $_POST;
            $id = $data['id'];
            $pk_field = $this->options["colModel"][0]["index"];
            // reformat date w.r.t mysql
            foreach ($this->options["colModel"] as $c) {
                // fix for d/m/Y date format. strtotime expects m/d/Y
                if ($c["formatoptions"]["newformat"] == "d/m/Y") {
                    $tmp = explode("/", $data[$c["index"]]);
                    $data[$c["index"]] = $tmp[1] . "/" . $tmp[0] . "/" . $tmp[2];
                }
                // put zeros for blank date field
                if (($c["formatter"] == "date" || $c["formatter"] == "datetime") && (empty($data[$c["index"]]) || $data[$c["index"]] == "//")) {
                    $data[$c["index"]] = "NULL";
                } else {
                    if ($c["isnull"] && empty($data[$c["index"]])) {
                        $data[$c["index"]] = "NULL";
                    } else {
                        if ($c["formatter"] == "date") {
                            $data[$c["index"]] = date("Y-m-d", strtotime($data[$c["index"]]));
                        } else {
                            if ($c["formatter"] == "datetime") {
                                $data[$c["index"]] = date("Y-m-d H:i:s", strtotime($data[$c["index"]]));
                            } else {
                                if ($c["formatter"] == "autocomplete") {
                                    unset($data[$c["index"]]);
                                }
                            }
                        }
                    }
                }
            }
            // handle grid operations of CRUD
            switch ($op) {
                case "autocomplete":
                    $field = $data['element'];
                    $term = $data['term'];
                    foreach ($this->options["colModel"] as $c) {
                        if ($c["index"] == $field) {
                            $sql = $c["formatoptions"]["sql"] . " WHERE {$c["formatoptions"]["search_on"]} like '{$term}%'";
                            $rs = $this->execute_query($sql);
                            $data_client = array();
                            while ($row = mysql_fetch_assoc($rs)) {
                                $arr['id'] = $row['client_id'];
                                $arr['label'] = $row['name'];
                                $arr['value'] = $row['name'];
                                $data_arr[] = $arr;
                            }
                            header('Content-type: application/json');
                            echo json_encode($data_arr);
                            die;
                        }
                    }
                    break;
                case "add":
                    unset($data['id']);
                    unset($data['oper']);
                    $update_str = array();
                    // custom onupdate event execution
                    if (!empty($this->events["on_insert"])) {
                        $func = $this->events["on_insert"][0];
                        $obj = $this->events["on_insert"][1];
                        $continue = $this->events["on_insert"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    foreach ($data as $k => $v) {
                        // remove any table alias from query - obseleted
                        if (strstr($k, "::") !== false) {
                            list($tmp, $k) = explode("::", $k);
                        }
                        $k = addslashes($k);
                        $v = addslashes($v);
                        $fields_str[] = "{$k}";
                        $v = $v == "NULL" ? $v : "'{$v}'";
                        $values_str[] = "{$v}";
                    }
                    $insert_str = "(" . implode(",", $fields_str) . ") VALUES (" . implode(",", $values_str) . ")";
                    $sql = "INSERT INTO {$this->table} {$insert_str}";
                    $insert_id = $this->execute_query($sql, "insert_id");
                    // custom onupdate event execution
                    if (!empty($this->events["on_after_insert"])) {
                        $func = $this->events["on_after_insert"][0];
                        $obj = $this->events["on_after_insert"][1];
                        $continue = $this->events["on_after_insert"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $insert_id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $insert_id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    // for inline row addition, return insert id to update PK of grid (e.g. order_id#33)
                    if ($id == "new_row") {
                        die($pk_field . "#" . $insert_id);
                    }
                    break;
                case "edit":
                    //pr($_POST);
                    unset($data['id']);
                    unset($data['oper']);
                    $update_str = array();
                    // custom onupdate event execution
                    if (!empty($this->events["on_update"])) {
                        $func = $this->events["on_update"][0];
                        $obj = $this->events["on_update"][1];
                        $continue = $this->events["on_update"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id, "params" => &$data));
                        } else {
                            call_user_func($func, array($pk_field => $id, "params" => &$data));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    foreach ($data as $k => $v) {
                        // remove any table alias from query - obseleted
                        if (strstr($k, "::") !== false) {
                            list($tmp, $k) = explode("::", $k);
                        }
                        $k = addslashes($k);
                        $v = addslashes($v);
                        $v = $v == "NULL" ? $v : "'{$v}'";
                        $update_str[] = "{$k}={$v}";
                    }
                    $update_str = "SET " . implode(",", $update_str);
                    if (strstr($pk_field, "::") !== false) {
                        $pk_field = explode("::", $pk_field);
                        $pk_field = $pk_field[1];
                    }
                    $sql = "UPDATE {$this->table} {$update_str} WHERE {$pk_field} = '{$id}'";
                    $this->execute_query($sql);
                    break;
                case "del":
                    // obseleted
                    if (strstr($pk_field, "::") !== false) {
                        $pk_field = explode("::", $pk_field);
                        $pk_field = $pk_field[1];
                    }
                    // custom onupdate event execution
                    if (!empty($this->events["on_delete"])) {
                        $func = $this->events["on_delete"][0];
                        $obj = $this->events["on_delete"][1];
                        $continue = $this->events["on_delete"][2];
                        if ($obj) {
                            call_user_method($func, $obj, array($pk_field => $id));
                        } else {
                            call_user_func($func, array($pk_field => $id));
                        }
                        if (!$continue) {
                            break;
                        }
                    }
                    $id = "'" . implode("','", explode(",", $id)) . "'";
                    $sql = "DELETE FROM {$this->table} WHERE {$pk_field} IN ({$id})";
                    $this->execute_query($sql);
                    break;
            }
            die;
        }
        // apply search conditions (where clause)
        $wh = "";
        if (!isset($_REQUEST['_search'])) {
            $_REQUEST['_search'] = "";
        }
        $searchOn = $this->strip($_REQUEST['_search']);
        if ($searchOn == 'true') {
            $fld = $this->strip($_REQUEST['searchField']);
            $cols = array();
            foreach ($this->options["colModel"] as $col) {
                $cols[] = $col["index"];
            }
            // quick search bar
            if (!$fld) {
                $searchstr = $this->strip($_REQUEST['filters']);
                $wh = $this->construct_where($searchstr);
            } else {
                if (in_array($fld, $cols)) {
                    $fldata = $this->strip($_REQUEST['searchString']);
                    $foper = $this->strip($_REQUEST['searchOper']);
                    // costruct where
                    $wh .= " AND " . $fld;
                    switch ($foper) {
                        case "eq":
                            if (is_numeric($fldata)) {
                                $wh .= " = " . $fldata;
                            } else {
                                $wh .= " = '" . $fldata . "'";
                            }
                            break;
                        case "ne":
                            if (is_numeric($fldata)) {
                                $wh .= " <> " . $fldata;
                            } else {
                                $wh .= " <> '" . $fldata . "'";
                            }
                            break;
                        case "lt":
                            if (is_numeric($fldata)) {
                                $wh .= " < " . $fldata;
                            } else {
                                $wh .= " < '" . $fldata . "'";
                            }
                            break;
                        case "le":
                            if (is_numeric($fldata)) {
                                $wh .= " <= " . $fldata;
                            } else {
                                $wh .= " <= '" . $fldata . "'";
                            }
                            break;
                        case "gt":
                            if (is_numeric($fldata)) {
                                $wh .= " > " . $fldata;
                            } else {
                                $wh .= " > '" . $fldata . "'";
                            }
                            break;
                        case "ge":
                            if (is_numeric($fldata)) {
                                $wh .= " >= " . $fldata;
                            } else {
                                $wh .= " >= '" . $fldata . "'";
                            }
                            break;
                        case "ew":
                            $wh .= " LIKE '%" . $fldata . "'";
                            break;
                        case "en":
                            $wh .= " NOT LIKE '%" . $fldata . "'";
                            break;
                        case "cn":
                            $wh .= " LIKE '%" . $fldata . "%'";
                            break;
                        case "nc":
                            $wh .= " NOT LIKE '%" . $fldata . "%'";
                            break;
                        case "in":
                            $wh .= " IN (" . $fldata . ")";
                            break;
                        case "ni":
                            $wh .= " NOT IN (" . $fldata . ")";
                            break;
                        case "bw":
                        default:
                            $fldata .= "%";
                            $wh .= " LIKE '" . $fldata . "'";
                            break;
                    }
                }
            }
            // setting to persist where clause in export option
            $_SESSION["jqgrid_filter"] = $wh;
        } elseif ($searchOn == 'false') {
            $_SESSION["jqgrid_filter"] = '';
        }
        // generate main json
        if (isset($_GET['jqgrid_page'])) {
            $page = $_GET['jqgrid_page'];
            // get the requested page
            $limit = $_GET['rows'];
            // get how many rows we want to have into the grid
            $sidx = $_GET['sidx'];
            // get index row - i.e. user click to sort
            $sord = $_GET['sord'];
            // get the direction
            if (!$sidx) {
                $sidx = 1;
            }
            if (!$limit) {
                $limit = 20;
            }
            $sidx = str_replace("::", ".", $sidx);
            // if export option is requested
            if (isset($_GET["export"])) {
                $arr = array();
                // by default export all
                $export_where = "";
                if ($this->options["export"]["range"] == "filtered") {
                    $export_where = $_SESSION["jqgrid_filter"];
                }
                $limit_sql = "";
                if ($this->options["export"]["paged"] == "1") {
                    $offset = $limit * $page - $limit;
                    // do not put $limit*($page - 1)
                    if ($offset < 0) {
                        $offset = 0;
                    }
                    $limit_sql = "LIMIT {$limit} OFFSET {$offset}";
                }
                if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                    $start = substr($this->select_command, 0, $p);
                    $end = substr($this->select_command, $p);
                    $SQL = $start . $export_where . $end . " ORDER BY {$sidx} {$sord} {$limit_sql}";
                } else {
                    $SQL = $this->select_command . $export_where . " ORDER BY {$sidx} {$sord} {$limit_sql}";
                }
                $result = $this->execute_query($SQL);
                // export only selected columns
                $cols_not_to_export = array();
                if ($this->options["colModel"]) {
                    foreach ($this->options["colModel"] as $c) {
                        if ($c["export"] === false) {
                            $cols_not_to_export[] = $c["name"];
                        }
                    }
                }
                foreach ($this->options["colModel"] as $c) {
                    $header[$c["name"]] = $c["title"];
                }
                $arr[] = $header;
                if ($this->con) {
                    $arr = $result->GetRows();
                } else {
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        foreach ($header as $k => $v) {
                            $export_data[$k] = $row[$k];
                        }
                        $arr[] = $export_data;
                    }
                }
                if (!empty($cols_not_to_export)) {
                    $export_arr = array();
                    foreach ($arr as $arr_item) {
                        foreach ($arr_item as $k => $i) {
                            if (in_array($k, $cols_not_to_export)) {
                                unset($arr_item[$k]);
                            }
                        }
                        $export_arr[] = $arr_item;
                    }
                    $arr = $export_arr;
                }
                if (!$this->options["export"]["filename"]) {
                    $this->options["export"]["filename"] = $grid_id;
                }
                if (!$this->options["export"]["sheetname"]) {
                    $this->options["export"]["sheetname"] = ucwords($grid_id) . " Sheet";
                }
                if ($this->options["export"]["format"] == "pdf") {
                    $html = "";
                    // if customized pdf render is defined, use that
                    if (!empty($this->events["on_render_pdf"])) {
                        $func = $this->events["on_render_pdf"][0];
                        $obj = $this->events["on_render_pdf"][1];
                        if ($obj) {
                            $html = call_user_method($func, $obj, array("grid" => $this, "data" => $arr));
                        } else {
                            $html = call_user_func($func, array("grid" => $this, "data" => $arr));
                        }
                    } else {
                        $html .= "<h1>" . $this->options["export"]["heading"] . "</h1>";
                        $html .= '<table border="1" cellpadding="4" cellspacing="0">';
                        $i = 0;
                        foreach ($arr as $v) {
                            $shade = $i++ % 2 ? 'bgcolor="#efefef"' : '';
                            $html .= "<tr>";
                            foreach ($v as $d) {
                                // bold header
                                if ($i == 1) {
                                    $html .= "<td bgcolor=\"lightgrey\"><strong>{$d}</strong></td>";
                                } else {
                                    $html .= "<td {$shade}>{$d}</td>";
                                }
                            }
                            $html .= "</tr>";
                        }
                        $html .= "</table>";
                    }
                    $orientation = $this->options["export"]["orientation"];
                    if ($orientation == "landscape") {
                        $orientation = "L";
                    } else {
                        $orientation = "P";
                    }
                    $paper = $this->options["export"]["paper"];
                    // Using opensource TCPdf lib
                    // for more options visit http://www.tcpdf.org/examples.php
                    require_once 'tcpdf/config/lang/eng.php';
                    require_once 'tcpdf/tcpdf.php';
                    // create new PDF document
                    $pdf = new TCPDF($orientation, PDF_UNIT, $paper, true, 'UTF-8', false);
                    // set document information
                    $pdf->SetCreator("www.phpgrid.org");
                    $pdf->SetAuthor('www.phpgrid.org');
                    $pdf->SetTitle('TCPDF Example 002');
                    $pdf->SetSubject($this->options["caption"]);
                    $pdf->SetKeywords('www.phpgrid.org');
                    // remove default header/footer
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                    // set default monospaced font
                    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                    $pdf->setFontSubsetting(false);
                    //set margins
                    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                    //set auto page breaks
                    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                    //set image scale factor
                    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
                    // set some language dependent data:
                    // lines for rtl pdf generation
                    if ($this->options["direction"] == "rtl") {
                        $lg = array();
                        $lg['a_meta_charset'] = 'UTF-8';
                        $lg['a_meta_dir'] = 'rtl';
                        $lg['a_meta_language'] = 'fa';
                        $lg['w_page'] = 'page';
                    }
                    $pdf->setLanguageArray($lg);
                    // To set your custom font
                    // $fontname = $pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);
                    // set font http://www.tcexam.org/doc/code/classTCPDF.html#afd56e360c43553830d543323e81bc045
                    $pdf->SetFont('helvetica', '', 12);
                    // add a page
                    $pdf->AddPage();
                    // output the HTML content
                    $pdf->writeHTML($html, true, false, true, false, '');
                    //Close and output PDF document
                    $pdf->Output($this->options["export"]["filename"] . ".pdf", 'I');
                    die;
                } else {
                    if ($this->options["export"]["format"] == "csv") {
                        header('Content-Type: text/csv');
                        header('Content-Disposition: attachment;filename=' . $this->options["export"]["filename"] . '.csv');
                        $fp = fopen('php://output', 'w');
                        foreach ($arr as $key => $value) {
                            fputcsv($fp, $value);
                        }
                        die;
                    } else {
                        $html = "";
                        $html .= "<table border='0' cellpadding='2' cellspacing='2'>";
                        $i = 0;
                        foreach ($arr as $v) {
                            $html .= "<tr>";
                            foreach ($v as $d) {
                                $html .= "<td>{$d}</td>";
                            }
                            $html .= "</tr>";
                        }
                        $html .= "<table>";
                        // Convert to UTF-16LE
                        $output = mb_convert_encoding($html, 'UTF-16LE', 'UTF-8');
                        // Prepend BOM
                        $output = "ÿþ" . $output;
                        header('Pragma: public');
                        header("Content-type: application/x-msexcel");
                        header('Content-Disposition: attachment;  filename="' . $this->options["export"]["filename"] . '.xls"');
                        echo $output;
                    }
                }
                die;
            }
            // make count query
            if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                $sql_count = preg_replace("/SELECT (.*) FROM/i", "SELECT 1 as c FROM", $this->select_command);
                $p = stripos($sql_count, "GROUP BY");
                $start_q = substr($sql_count, 0, $p);
                $end_q = substr($sql_count, $p);
                $sql_count = "SELECT count(*) as c FROM ({$start_q} {$wh} {$end_q}) o";
            } else {
                $sql_count = $this->select_command . $wh;
                $sql_count = "SELECT count(*) as c FROM (" . $sql_count . ") table_count";
            }
            # print_r($sql_count);
            $result = $this->execute_query($sql_count);
            if ($this->con) {
                $row = $result->FetchRow();
            } else {
                $row = mysql_fetch_array($result, MYSQL_ASSOC);
            }
            $count = $row['c'];
            // fix for oracle, alias in capitals
            if (empty($count)) {
                $count = $row['C'];
            }
            if ($count > 0) {
                $total_pages = ceil($count / $limit);
            } else {
                $total_pages = 0;
            }
            if ($page > $total_pages) {
                $page = $total_pages;
            }
            $start = $limit * $page - $limit;
            // do not put $limit*($page - 1)
            if ($start < 0) {
                $start = 0;
            }
            $responce = new stdClass();
            $responce->page = $page;
            $responce->total = $total_pages;
            $responce->records = $count;
            if (($p = stripos($this->select_command, "GROUP BY")) !== false) {
                $start_q = substr($this->select_command, 0, $p);
                $end_q = substr($this->select_command, $p);
                $SQL = "{$start_q} {$wh} {$end_q} ORDER BY {$sidx} {$sord} LIMIT {$limit} OFFSET {$start}";
            } else {
                $SQL = $this->select_command . $wh . " ORDER BY {$sidx} {$sord} LIMIT {$limit} OFFSET {$start}";
            }
            $SQL = $this->prepare_sql($SQL, $this->db_driver);
            $result = $this->execute_query($SQL);
            if ($this->con) {
                $rows = $result->GetRows();
                // simulate artificial paging for mssql
                if (count($rows) > $limit) {
                    $rows = array_slice($rows, count($rows) - $limit);
                }
            } else {
                $rows = array();
                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                    $rows[] = $row;
                }
            }
            // custom on_data_display event execution
            if (!empty($this->events["on_data_display"])) {
                $func = $this->events["on_data_display"][0];
                $obj = $this->events["on_data_display"][1];
                $continue = $this->events["on_data_display"][2];
                if ($obj) {
                    call_user_method($func, $obj, array("params" => &$rows));
                } else {
                    call_user_func($func, array("params" => &$rows));
                }
                if (!$continue) {
                    break;
                }
            }
            foreach ($rows as $row) {
                // apply php level formatter for image url 30.12.10
                foreach ($this->options["colModel"] as $c) {
                    $col_name = $c["name"];
                    if (isset($c["default"]) && !isset($row[$col_name])) {
                        $row[$col_name] = $c["default"];
                    }
                    // link data in grid to any given url
                    if (!empty($c["default"])) {
                        // replace any param in link e.g. http://domain.com?id={id} given that, there is a $col["name"] = "id" exist
                        $row[$col_name] = $this->replace_row_data($row, $c["default"]);
                    }
                    // check conditional data
                    if (!empty($c["condition"][0])) {
                        $r = true;
                        // replace {} placeholders from connditional data
                        $c["condition"][1] = $this->replace_row_data($row, $c["condition"][1]);
                        $c["condition"][2] = $this->replace_row_data($row, $c["condition"][2]);
                        eval("\$r = " . $c["condition"][0] . ";");
                        $row[$col_name] = $r ? $c["condition"][1] : $c["condition"][2];
                    }
                    // link data in grid to any given url
                    if (!empty($c["link"])) {
                        // replace any param in link e.g. http://domain.com?id={id} given that, there is a $col["name"] = "id" exist
                        foreach ($this->options["colModel"] as $link_c) {
                            $link_row_data = urlencode($row[$link_c["name"]]);
                            $c["link"] = str_replace("{" . $link_c["name"] . "}", $link_row_data, $c["link"]);
                        }
                        if (!empty($c["linkoptions"])) {
                            $attr = $c["linkoptions"];
                        }
                        $row[$col_name] = "<a {$attr} href='{$c["link"]}'>{$row[$col_name]}</a>";
                    }
                    // render row data as "src" value of <img> tag
                    if (isset($c["formatter"]) && $c["formatter"] == "image") {
                        $attr = array();
                        foreach ($c["formatoptions"] as $k => $v) {
                            $attr[] = "{$k}='{$v}'";
                        }
                        $attr = implode(" ", $attr);
                        $row[$col_name] = "<img {$attr} src='" . $row[$col_name] . "'>";
                    }
                    // show masked data in password
                    if (isset($c["formatter"]) && $c["formatter"] == "password") {
                        $row[$col_name] = "*****";
                    }
                }
                foreach ($row as $k => $r) {
                    $row[$k] = stripslashes($row[$k]);
                }
                $responce->rows[] = $row;
            }
            echo json_encode($responce);
            die;
        }
        // if loading from array
        if (is_array($this->table)) {
            $this->options["data"] = json_encode($this->table);
            $this->options["datatype"] = "local";
            $this->actions["rowactions"] = false;
            $this->actions["add"] = false;
            $this->actions["edit"] = false;
            $this->actions["delete"] = false;
        }
        // few overides - pagination fixes
        $this->options["pager"] = '#' . $grid_id . "_pager";
        $this->options["jsonReader"] = array("repeatitems" => false, "id" => "0");
        // allow/disallow edit,del operations
        if ($this->actions["edit"] === false && $this->actions["delete"] === false || $this->options["cellEdit"] === true) {
            $this->actions["rowactions"] = false;
        }
        if ($this->actions["rowactions"] !== false) {
            // CRUD operation column
            $f = false;
            $defined = false;
            foreach ($this->options["colModel"] as &$c) {
                if ($c["name"] == "act") {
                    $defined =& $c;
                }
                if (!empty($c["width"])) {
                    $f = true;
                }
            }
            // width adjustment for row actions column
            if ($f) {
                $action_column = array("name" => "act", "align" => "center", "index" => "act", "width" => "40", "sortable" => false, "search" => false, "viewable" => false);
            } else {
                $action_column = array("name" => "act", "align" => "center", "index" => "act", "width" => "60", "sortable" => false, "search" => false, "viewable" => false);
            }
            if (!$defined) {
                $this->options["colNames"][] = "Actions";
                $this->options["colModel"][] = $action_column;
            } else {
                $defined = array_merge($action_column, $defined);
            }
        }
        $out = json_encode_jsfunc($this->options);
        $out = substr($out, 0, strlen($out) - 1);
        // create Edit/Delete - Save/Cancel column in grid
        if ($this->actions["rowactions"] !== false) {
            $act_links = array();
            if ($this->actions["edit"] !== false) {
                $act_links[] = "<a title=\"Edit this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').editRow(\\''+cl+'\\',true); jQuery(this).parent().hide(); jQuery(this).parent().next().show(); \">Edit</a>";
            }
            if ($this->actions["delete"] !== false) {
                $act_links[] = "<a title=\"Delete this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').delGridRow(\\''+cl+'\\'); \">Delete</a>";
            }
            if ($this->actions["clone"] === true) {
                $act_links[] = "<a title=\"Duplicate this row\" href=\"javascript:void(0);\" onclick=\"duplicate_row(\\'#{$grid_id}\\',\\''+cl+'\\'); \">Clone</a>";
            }
            $act_links = implode(" | ", $act_links);
            $out .= ",'gridComplete': function(){\n\t\t\t\t\t\tvar ids = jQuery('#{$grid_id}').jqGrid('getDataIDs');\n\t\t\t\t\t\tfor(var i=0;i < ids.length;i++){\n\t\t\t\t\t\t\tvar cl = ids[i];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbe = '{$act_links}'; \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tse = ' <a title=\"Save this row\" href=\"javascript:void(0);\" onclick=\"if (jQuery(\\'#{$grid_id}\\').saveRow(\\''+cl+'\\')) { jQuery(this).parent().hide(); jQuery(this).parent().prev().show(); }\">Save</a>'; \n\t\t\t\t\t\t\tce = ' | <a title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}\\').restoreRow(\\''+cl+'\\'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel</a>'; \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ids[i] == 'new_row')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tse = ' <a title=\"Save this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}_ilsave\\').click(); \">Save</a>'; \n\t\t\t\t\t\t\t\tce = ' | <a title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\\'#{$grid_id}_ilcancel\\').click(); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel</a>'; \n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').jqGrid('setRowData',ids[i],{act:'<span style=display:none id=\"edit_row_{$grid_id}_'+cl+'\">'+be+'</span>'+'<span id=\"save_row_{$grid_id}_'+cl+'\">'+se+ce+'</span>'});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').jqGrid('setRowData',ids[i],{act:'<span id=\"edit_row_{$grid_id}_'+cl+'\">'+be+'</span>'+'<span style=display:none id=\"save_row_{$grid_id}_'+cl+'\">'+se+ce+'</span>'});\n\t\t\t\t\t\t}\t\n\t\t\t\t\t}";
            /*
            // theme buttons -- not looking good
            $out .= ",'gridComplete': function(){
            			var ids = jQuery('#$grid_id').jqGrid('getDataIDs');
            			for(var i=0;i < ids.length;i++){
            				var cl = ids[i];
            				be = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Edit this row\" onclick=\"jQuery(\'#$grid_id\').editRow('+cl+',true); jQuery(this).parent().hide(); jQuery(this).parent().next().show(); \">Edit <span class=\"ui-icon ui-icon-pencil\"></span></a>'; 
            				de = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Delete this row\" onclick=\"jQuery(\'#$grid_id\').delRowData('+cl+'); \">Delete <span class=\"ui-icon ui-icon-close\"></span></a>';
            
            				se = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Save this row\" onclick=\"jQuery(\'#$grid_id\').saveRow('+cl+'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Save <span class=\"ui-icon ui-icon-disk\"></span></a>'; 
            				ce = ' <a style=\"padding:0 0.5em;padding-left:1.6em;font-weight:normal;\" class=\"fm-button fm-button-icon-left ui-state-default ui-corner-all\" title=\"Restore this row\" href=\"javascript:void(0);\" onclick=\"jQuery(\'#$grid_id\').restoreRow('+cl+'); jQuery(this).parent().hide(); jQuery(this).parent().prev().show();\">Cancel <span class=\"ui-icon ui-icon-cancel\"></span></a>'; 
            				
            				jQuery('#$grid_id').jqGrid('setRowData',ids[i],{act:'<div style=\"white-space:nowrap;float:left\" id=\"edit_row_'+cl+'\">'+be+de+'</div>'+'<div style=\"white-space:nowrap;float:left;display:none;\" id=\"save_row_'+cl+'\">'+se+ce+'</div>'});
            			}	
            		}";
            */
        }
        // double click editing option
        if ($this->actions["rowactions"] !== false && $this->actions["edit"] !== false && $this->options["cellEdit"] !== true) {
            if ($this->options["reloadedit"] === true) {
                $reload_after_edit = "jQuery('#{$grid_id}').jqGrid().trigger('reloadGrid',[{jqgrid_page:1}]);";
            }
            $out .= ",'ondblClickRow':function(id)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(id && id!==lastSel){ \n\t\t\t\t\t\t\t\tjQuery('#{$grid_id}').restoreRow(lastSel); \n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t// disabled previously edit icons\n\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+lastSel).show();\n\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+lastSel).hide();\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tlastSel=id; \t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tjQuery('#{$grid_id}').editRow(id, true, function(){}, function(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},null,null,function(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// force reload grid after inline save\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$reload_after_edit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},null,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfunction(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t); \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tjQuery('#edit_row_{$grid_id}_'+id).hide();\n\t\t\t\t\t\t\tjQuery('#save_row_{$grid_id}_'+id).show();\n\t\t\t\t\t\t}";
        }
        // if subgrid is there, enable subgrid feature
        if (isset($this->options["subgridurl"]) && $this->options["subgridurl"] != '') {
            // we pass two parameters
            // subgrid_id is a id of the div tag created within a table
            // the row_id is the id of the row
            // If we want to pass additional parameters to the url we can use
            // the method getRowData(row_id) - which returns associative array in type name-value
            // here we can easy construct the following
            $pass_params = "false";
            if (!empty($this->options["subgridparams"])) {
                $pass_params = "true";
            }
            $out .= ",'subGridRowExpanded': function(subgridid, id) \n\t\t\t\t\t\t\t\t\t\t\t{ \n\t\t\t\t\t\t\t\t\t\t\t\tvar data = {subgrid:subgridid, rowid:id};\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif('{$pass_params}' == 'true') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar anm= '" . $this->options["subgridparams"] . "';\n\t\t\t\t\t\t\t\t\t\t\t\t\tanm = anm.split(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar rd = jQuery('#" . $grid_id . "').jqGrid('getRowData', id);\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(rd) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfor(var i=0; i<anm.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(rd[anm[i]]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata[anm[i]] = rd[anm[i]];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\tjQuery('#'+jQuery.jgrid.jqID(subgridid)).load('" . $this->options["subgridurl"] . "',data);\n\t\t\t\t\t\t\t\t\t\t\t}";
        }
        // on error
        $out .= ",'loadError': function(xhr,status, err) { \n\t\t\t\t\ttry \n\t\t\t\t\t{\n\t\t\t\t\t\tjQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class=\"ui-state-error\">'+ xhr.responseText +'</div>', \n\t\t\t\t\t\t\t\t\t\t\t\t\tjQuery.jgrid.edit.bClose,{buttonalign:'right'});\n\t\t\t\t\t} \n\t\t\t\t\tcatch(e) { alert(xhr.responseText);}\n\t\t\t\t}\n\t\t\t\t";
        // on row selection operation
        $out .= ",'onSelectRow': function(ids) { ";
        if (isset($this->options["detail_grid_id"]) && $this->options["detail_grid_id"] != '') {
            $detail_grid_id = $this->options["detail_grid_id"];
            $d_grids = explode(",", $detail_grid_id);
            foreach ($d_grids as $detail_grid_id) {
                $detail_url = "?grid_id=" . $detail_grid_id;
                $out .= "\n\t\t\n\t\t\t\t\t\tvar data = '';\n\t\t\t\t\t\tif ('{$this->options["subgridparams"]}'.length > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvar anm = '" . $this->options["subgridparams"] . "';\n\t\t\t\t\t\t\tanm = anm.split(',');\n\t\t\t\t\t\t\tvar rd = jQuery('#" . $grid_id . "').jqGrid('getRowData', ids);\n\t\t\t\t\t\t\tif(rd) {\n\t\t\t\t\t\t\t\tfor(var i=0; i<anm.length; i++) {\n\t\t\t\t\t\t\t\t\tif(rd[anm[i]]) {\n\t\t\t\t\t\t\t\t\t\tdata += '&' + anm[i] + '=' + rd[anm[i]];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tif(ids == null) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tids=0;\n\t\t\t\t\t\t\tif(jQuery('#" . $detail_grid_id . "').jqGrid('getGridParam','records') >0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').jqGrid('setGridParam',{url:'" . $detail_url . "&rowid='+ids+data,editurl:'" . $detail_url . "&rowid='+ids,jqgrid_page:1});\n\t\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').trigger('reloadGrid',[{jqgrid_page:1}]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').jqGrid('setGridParam',{url:'" . $detail_url . "&rowid='+ids+data,editurl:'" . $detail_url . "&rowid='+ids,jqgrid_page:1});\n\t\t\t\t\t\t\tjQuery('#" . $detail_grid_id . "').trigger('reloadGrid',[{jqgrid_page:1}]);\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t";
            }
        }
        if (!empty($this->events["js_on_select_row"])) {
            $out .= "if (typeof({$this->events["js_on_select_row"]}) != 'undefined') {$this->events["js_on_select_row"]}(ids);";
        }
        // closing of select row events
        $out .= "}";
        // on load complete operation
        $out .= ",'loadComplete': function(ids) { ";
        $out .= "if(ids.rows) jQuery.each(ids.rows,function(i){";
        if (count($this->conditional_css)) {
            foreach ($this->conditional_css as $value) {
                if ($value["op"] == "cn") {
                    $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]}.toLowerCase().indexOf('{$value[value]}'.toLowerCase()) != -1)\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                } else {
                    if ($value["op"] == "eq") {
                        $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]}.toLowerCase() == '{$value[value]}'.toLowerCase())\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                    } else {
                        if ($value["op"] == "<" || $value["op"] == "<=" || $value["op"] == ">" || $value["op"] == ">=" || $value["op"] == "!=") {
                            $out .= "\n\t\t\t\t\t\t\t\tif (this.{$value[column]} {$value["op"]} {$value[value]})\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('tr.jqgrow:eq('+i+')').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                        } else {
                            if (empty($value["op"]) && !empty($value["column"]) && !empty($value["css"])) {
                                $out .= "\n\t\t\t\t\t\t\t \t{\n\t\t\t\t\t\t\t \t\tjQuery('td[aria-describedby={$grid_id}_{$value["column"]}]').removeClass('ui-widget-content').css({{$value[css]}});\n\t\t\t\t\t\t\t \t}";
                            }
                        }
                    }
                }
            }
        }
        $out .= "});";
        // closing of load complete events
        $out .= "}";
        // closing of param list
        $out .= "}";
        // Geneate HTML/JS code
        ob_start();
        ?>
			<table id="<?php 
        echo $grid_id;
        ?>
"></table> 
			<div id="<?php 
        echo $grid_id . "_pager";
        ?>
"></div> 

			<script>
			var phpgrid = jQuery("#<?php 
        echo $grid_id;
        ?>
");
			var phpgrid_pager = jQuery("#<?php 
        echo $grid_id . "_pager";
        ?>
");
			jQuery(document).ready(function(){
				<?php 
        echo $this->render_js($grid_id, $out);
        ?>
			});	
			</script>	
		<?php 
        return ob_get_clean();
    }
Ejemplo n.º 27
0
 protected function download_pdf($html)
 {
     $this->load->library('tcpdf');
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 001');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
     $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     $pdf->setFontSubsetting(true);
     $pdf->SetFont('dejavusans', '', 14, '', true);
     $pdf->AddPage();
     $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     $pdf->Output('example_001.pdf', 'I');
 }
Ejemplo n.º 28
-1
 public function print_pdf($text, $title = 'PDF Document')
 {
     require_once '../backend/tcpdf/tcpdf.php';
     $pdf = new TCPDF();
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->AddPage();
     $pdf->writeHTML($text, true, false, true, false, '');
     $pdf->Output($title, 'I');
 }
Ejemplo n.º 29
-2
 public function save($file)
 {
     $orientation = $this->_getOrientation();
     $size = $this->_getSize();
     /* @TODO Not sure if this works either, in comparison with $pdf->AddPage() */
     $pdf = new TCPDF($orientation, 'mm', $size, true, $this->_page['encoding'], false);
     if (is_array($this->_page['size'])) {
         list($width, $height) = $this->_page['size'];
         $orientation = $height > $width ? 'P' : 'L';
         $pdf->addFormat("custom", $width, $height);
         $pdf->reFormat("custom", $orientation);
     }
     $pdf->SetAutoPageBreak(TRUE, $this->_page['margin'][2]);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $tagvs = array('p' => array(array('h' => 0, 'n' => 1), array('h' => '', 'n' => 1)), 'hr' => array(array('h' => 0, 'n' => 0), array('h' => 0, 'n' => 0)));
     $pdf->setHtmlVSpace($tagvs);
     //        $pdf->SetHeaderMargin(0);
     //        $pdf->SetFooterMargin(0);
     call_user_func_array(array($pdf, 'SetMargins'), $this->_page['margin']);
     foreach ($this->_html as $i => $page) {
         $page = (strpos($page, '<style') !== FALSE && strpos($page, '<style') < strpos($page, '<body') ? substr($page, strpos($page, '<style'), strpos($page, '</style') - strpos($page, '<st') + 8) : '') . preg_replace('/<body[^>]+>/i', '', substr($page, strpos($page, '<body'), strpos($page, '</body') - strpos($page, '<body')));
         $page = str_replace(array("\r", "\n"), "", $page);
         if (!is_array($size)) {
             $pdf->AddPage();
         } else {
             $pdf->AddPage($orientation, $size);
             // @TODO must verify if this is correct
         }
         $pdf->writeHTML($page, true, false, true, false);
         $pdf->lastPage();
     }
     //        $pdf->Output($file, 'I'); die();
     $pdf->Output($file, 'F');
 }
Ejemplo n.º 30
-4
 function output($html, $title = 'document', $pFilename = 'doc.pdf')
 {
     require_once '../classes/PHPExcel/Shared/PDF/tcpdf.php';
     require_once "../classes/Settings.php";
     require_once "../classes/SettingsQuery.php";
     // Create PDF
     $pdf = new TCPDF('P', 'pt', 'A4');
     $pdf->SetMargins(56.7, 56.7);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->setTitle($title);
     $pdf->AddPage();
     // Set the appropriate font
     $setQ = new SettingsQuery();
     $setQ->connect();
     if ($setQ->errorOccurred()) {
         $setQ->close();
         displayErrorPage($setQ);
     }
     $setQ->execSelect();
     if ($setQ->errorOccurred()) {
         $setQ->close();
         displayErrorPage($setQ);
     }
     $set = $setQ->fetchRow();
     $pdf->setFont($set->getFontNormal());
     $pdf->writeHTML($html);
     $pdf->SetTitle($title);
     return $pdf->output($pFilename, 'S');
 }