public function __construct($s_title, $sPageFormat = 'A4', $sPageOrientation = 'L') { parent::__construct($s_title); define(K_PATH_FONTS, APPROOT . 'lib/tcpdf/fonts'); $this->oPdf = new iTopPDF($sPageOrientation, 'mm', $sPageFormat, true, 'UTF-8', false); // set document information $this->oPdf->SetCreator(PDF_CREATOR); $this->oPdf->SetAuthor('iTop'); $this->oPdf->SetTitle($s_title); $this->oPdf->SetDocumentTitle($s_title); $this->oPdf->setFontSubsetting(true); // Set font // dejavusans is a UTF-8 Unicode font. Standard PDF fonts like helvetica or times new roman are NOT UTF-8 $this->oPdf->SetFont('dejavusans', '', 10, '', true); // set auto page breaks $this->oPdf->SetAutoPageBreak(true, 15); // 15 mm break margin at the bottom $this->oPdf->SetTopMargin(15); // Add a page, we're ready to start $this->oPdf->AddPage(); $this->SetContentDisposition('inline', $s_title . '.pdf'); $this->SetDefaultStyle(); }
public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array()) { require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "config" . PATH_SEP . "lang" . PATH_SEP . "eng.php"; require_once PATH_THIRDPARTY . "tcpdf" . PATH_SEP . "tcpdf.php"; $nrt = array("\n", "\r", "\t"); $nrthtml = array("(n /)", "(r /)", "(t /)"); $strContentAux = str_replace($nrt, $nrthtml, $sContent); $sContent = null; while (preg_match("/^(.*)<font([^>]*)>(.*)\$/i", $strContentAux, $arrayMatch)) { $str = trim($arrayMatch[2]); $strAttribute = null; if (!empty($str)) { $strAux = $str; $str = null; while (preg_match("/^(.*)([\"'].*[\"'])(.*)\$/", $strAux, $arrayMatch2)) { $strAux = $arrayMatch2[1]; $str = str_replace(" ", "__SPACE__", $arrayMatch2[2]) . $arrayMatch2[3] . $str; } $str = $strAux . $str; //Get attributes $strStyle = null; $array = explode(" ", $str); foreach ($array as $value) { $arrayAux = explode("=", $value); if (isset($arrayAux[1])) { $a = trim($arrayAux[0]); $v = trim(str_replace(array("__SPACE__", "\"", "'"), array(" ", null, null), $arrayAux[1])); switch (strtolower($a)) { case "color": $strStyle = $strStyle . "color: {$v};"; break; case "face": $strStyle = $strStyle . "font-family: {$v};"; break; case "size": $arrayPt = array(0, 8, 10, 12, 14, 18, 24, 36); $strStyle = $strStyle . "font-size: " . $arrayPt[intval($v)] . "pt;"; break; case "style": $strStyle = $strStyle . "{$v};"; break; default: $strAttribute = $strAttribute . " {$a}=\"{$v}\""; break; } } } if ($strStyle != null) { $strAttribute = $strAttribute . " style=\"{$strStyle}\""; } } $strContentAux = $arrayMatch[1]; $sContent = "<span" . $strAttribute . ">" . $arrayMatch[3] . $sContent; } $sContent = $strContentAux . $sContent; $sContent = str_ireplace("</font>", "</span>", $sContent); $sContent = str_replace($nrthtml, $nrt, $sContent); // define Save file $sOutput = 2; $sOrientation = $sLandscape == false ? PDF_PAGE_ORIENTATION : 'L'; $sMedia = isset($aProperties['media']) ? $aProperties['media'] : PDF_PAGE_FORMAT; $sLang = defined('SYS_LANG') ? SYS_LANG : 'en'; // create new PDF document $pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($aFields['USR_USERNAME']); $pdf->SetTitle('Processmaker'); $pdf->SetSubject($sFilename); $pdf->SetCompression(true); $margins = $aProperties['margins']; $margins["left"] = $margins["left"] >= 0 ? $margins["left"] : PDF_MARGIN_LEFT; $margins["top"] = $margins["top"] >= 0 ? $margins["top"] : PDF_MARGIN_TOP; $margins["right"] = $margins["right"] >= 0 ? $margins["right"] : PDF_MARGIN_RIGHT; $margins["bottom"] = $margins["bottom"] >= 0 ? $margins["bottom"] : PDF_MARGIN_BOTTOM; $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetLeftMargin($margins['left']); $pdf->SetTopMargin($margins['top']); $pdf->SetRightMargin($margins['right']); $pdf->SetAutoPageBreak(true, $margins['bottom']); $oServerConf =& serverConf::getSingleton(); // set some language dependent data: $lg = array(); $lg['a_meta_charset'] = 'UTF-8'; $lg['a_meta_dir'] = $oServerConf->isRtl($sLang) ? 'rtl' : 'ltr'; $lg['a_meta_language'] = $sLang; $lg['w_page'] = 'page'; //set some language-dependent strings $pdf->setLanguageArray($lg); if (isset($aProperties['pdfSecurity'])) { $pdfSecurity = $aProperties['pdfSecurity']; $userPass = G::decrypt($pdfSecurity['openPassword'], $sUID); $ownerPass = $pdfSecurity['ownerPassword'] != '' ? G::decrypt($pdfSecurity['ownerPassword'], $sUID) : null; $permissions = explode("|", $pdfSecurity['permissions']); $pdf->SetProtection($permissions, $userPass, $ownerPass); } // --------------------------------------------------------- // 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', '', 14, '', true); // Detect chinese, japanese, thai if (preg_match('/[\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FFF}\\x{0E00}-\\x{0E7F}]/u', $sContent, $matches)) { $pdf->SetFont('kozminproregular'); } // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); // set text shadow effect //$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); // Print text using writeHTMLCell() // $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); if (mb_detect_encoding($sContent) == 'UTF-8') { $sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', 'UTF-8'); } $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHtml($sContent); $pdf->writeHTML($doc->saveXML(), false, false, false, false, ''); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. //$pdf->Output('example_00.pdf', 'I'); //$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D'); switch ($sOutput) { case 0: // Vrew browser $pdf->Output($sPath . $sFilename . '.pdf', 'I'); break; case 1: // Donwnload $pdf->Output($sPath . $sFilename . '.pdf', 'D'); break; case 2: // Save file $pdf->Output($sPath . $sFilename . '.pdf', 'F'); break; } }
function addressLabelPDF($outputformat) { $pdf = new TCPDF('L', 'mm', 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Niels Klazenga'); $pdf->SetTitle('MEL Label'); $pdf->SetSubject('MEL Label'); //set margins $pdf->SetTopMargin(7.5); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, 0); // remove default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // --------------------------------------------------------- // set font if ($outputformat == 3) { $pdf->SetFont('helvetica', '', 12); } else { $pdf->SetFont('helvetica', '', 14); } // set cell padding $pdf->setCellPaddings(0, 0, 0, 0); // set cell margins $pdf->setCellMargins(0, 0, 0, 0); $pdf->addPage(); if ($outputformat == 3) { $x = 135; $y = 40; } else { $x = 165; $y = 30; } $this->Address(); $pdf->MultiCell(100, 5, $this->loan->ShippedTo, 0, 'L', 0, 1, $x, $y, true, false, true); // move pointer to last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('mellabel.pdf', 'I'); }
// set document information $pdf->SetCreator('Money Manager'); $pdf->SetTitle('Income Report'); // set default header data $pdf->SetHeaderData('logo.gif', '20', 'Your Company Name', 'Income Report', array(0, 64, 255), array(0, 64, 128)); $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128)); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetTopMargin(35); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- //convert to PDF $pdf->SetFont('dejavusans', '', 9, '', true); $pdf->AddPage('L', 'A4'); // set text shadow effect $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal')); $tbl_header = '<table align="center" border="1">'; $thead = '<thead align="center"> <tr> <td style="margin-bottom:12px;font-weight:bold;width:200px;">' . $Title . '</td> <td style="margin-bottom:12px;font-weight:bold;width:100px;">' . $Date . '</td> <td style="margin-bottom:12px;font-weight:bold;width:150px;">' . $Category . '</td>
$mesetrim='Trimestre'; } $intesta1=$admin_aziend['ragso1'].$admin_aziend['ragso2']; $intesta2=$admin_aziend['indspe']; $intesta3=sprintf("%05d",$admin_aziend['capspe']).' '.$admin_aziend['citspe'].' ('.$admin_aziend['prospe'].')'; $intesta4='P.I. '.$admin_aziend['pariva']; $intesta5=$admin_aziend['luonas'].' '.substr($admin_aziend['datnas'],8,2).'-'.substr($admin_aziend['datnas'],5,2).'-'.substr($admin_aziend['datnas'],0,4); $pdf=new TCPDF(); $pdf->Open(); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AliasNbPages(); $pdf->SetTopMargin(5); $pdf->SetHeaderMargin(5); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFillColor(hexdec(substr($admin_aziend['colore'],0,2)),hexdec(substr($admin_aziend['colore'],2,2)),hexdec(substr($admin_aziend['colore'],4,2))); $pdf->SetFont('helvetica','B',10); $pdf->Image('@'.$admin_aziend['image'],10,8,20,0); $pdf->Cell(25); $pdf->Cell(103,6,$intesta1,0,0,'L'); $pdf->Cell(62,6,'ACQUISTI DI CARBURANTE','LTR',1,'C',1); $pdf->SetFont('helvetica','',8); $pdf->Cell(25); $pdf->Cell(103,6,$intesta2,0,0,'L'); $pdf->SetFont('helvetica','B',10); $pdf->Cell(62,6,'PER AUTOTRAZIONE','LBR',1,'C',1); $pdf->SetFont('helvetica','',10);
function printSpiritCard($labeldata, $props, $start = 0) { set_time_limit(600); // create new PDF document $pageformat = array('format' => 'A4', 'Rotate' => 0); $pdf = new TCPDF('L', 'mm', $pageformat, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Niels Klazenga'); $pdf->SetTitle('MEL Label'); $pdf->SetSubject('MEL Label'); //set margins $pdf->SetTopMargin(7.5); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, 0); // remove default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // --------------------------------------------------------- // set font $pdf->SetFont('times', '', 9); // set cell padding $pdf->setCellPaddings(0, 0, 0, 0); // set cell margins $pdf->setCellMargins(0, 0, 0, 0); $labelheader = '<p style="font-weight: bold"><span style="font-size: 12pt;">NATIONAL HERBARIUM OF VICTORIA (MEL)</span><br /> <span style="font-size: 11pt;">MELBOURNE, AUSTRALIA</span></p>'; $barcodestyle = array('position' => '', 'padding' => 0, 'align' => 'C', 'stretch' => true, 'cellfitalign' => '', 'border' => false, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'text' => false); $left = 149.5; for ($i = 0; $i < count($labeldata); $i++) { $pdf->AddPage(); $pdf->MultiCell(94, 5, $labelheader, 0, 'C', 0, 1, $left + 5, $props['yheader'], true, false, true); $pdf->MultiCell(39.5, 5, $labeldata[$i]['spiritinfo'], 0, 'R', 0, 0, $left + 99.5, $props['yheader'], true, false, true); $pdf->write1DBarcode($labeldata[$i]['melnumber'], 'C39', $left + 96.5, $props['ybarcode'], 45, 9, 0.1, $barcodestyle, 'N'); $pdf->MultiCell(45, 5, '<b>' . $labeldata[$i]['melnumber'] . '</b>', 0, 'C', 0, 1, $left + 96.5, $props['ybarcodetext'], true, false, true); $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['determination'], 0, 'L', 0, 1, $left + 5, $pdf->GetY(), true, 0, true, true, 0, 'T', false); if ($labeldata[$i]['typeinfo']) { $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['typeinfo'], 0, 'L', 0, 1, $left + 5, $pdf->GetY(), true, 0, true, true, 0, 'T', false); } $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['collectinginfo'], 0, 'L', 0, 1, $left + 5, $pdf->GetY() + 1, true, 0, true, true, 0, 'T', false); $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['locality'], 0, 'L', 0, 1, $left + 5, $pdf->GetY() + 1, true, 0, true, true, 0, 'T', false); if ($labeldata[$i]['notes']) { $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['notes'], 0, 'L', 0, 1, $left + 5, $pdf->GetY() + 1, true, 0, true, true, 0, 'T', false); } if ($labeldata[$i]['multisheet']) { $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['multisheet'], 0, 'L', 0, 1, $left + 5, $pdf->GetY() + 1, true, 0, true, true, 0, 'T', false); } if ($labeldata[$i]['mixed']) { $pdf->MultiCell($props['whtml'], 5, $labeldata[$i]['mixed'], 0, 'L', 0, 1, $left + 5, $pdf->GetY() + 1, true, 0, true, true, 0, 'T', false); } if ($pdf->GetY() > 97) { $pdf->AddPage(); } $footer = str_replace('Main collection', 'Spirit collection', $labeldata[$i]['footer']); $pdf->MultiCell(111.5, 5, $footer, 0, 'L', 0, 1, $left + 5, 95, true, 0, true, true, 0, 'T', false); } // move pointer to last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('mellabel.pdf', 'I'); }
public function outpage($out_method = "I", $filename = "") { // if($this->lang=="cn") { // if($this->arrayPageSetting["orientation"]=="P") { // $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"])); // $this->pdf->AddUniGBhwFont("uGB"); // } // else { // $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"])); // $this->pdf->AddUniGBhwFont("uGB"); // } // } // else { // // if($this->pdflib=="TCPDF") { // if($this->arrayPageSetting["orientation"]=="P") // $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"])); // else // $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"])); // $this->pdf->setPrintHeader(false); // $this->pdf->setPrintFooter(false); // }else { // if($this->arrayPageSetting["orientation"]=="P") // $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"])); // else // $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"])); // } // } //$this->arrayPageSetting["language"]=$xml_path["language"]; $this->pdf->SetLeftMargin($this->arrayPageSetting["leftMargin"]); $this->pdf->SetRightMargin($this->arrayPageSetting["rightMargin"]); $this->pdf->SetTopMargin($this->arrayPageSetting["topMargin"]); $this->pdf->SetAutoPageBreak(true, $this->arrayPageSetting["bottomMargin"] / 2); // $this->pdf->AliasNbPages(); $this->global_pointer = 0; foreach ($this->arrayband as $band) { $this->currentband = $band["name"]; // to know current where current band in! switch ($band["name"]) { case "title": if ($this->arraytitle[0]["height"] > 0) { $this->title(); } break; case "pageHeader": if (!$this->newPageGroup) { $headerY = $this->arrayPageSetting["topMargin"] + $this->arraypageHeader[0]["height"]; $this->pageHeader($headerY); } else { $this->pageHeaderNewPage(); } break; case "detail": if (!$this->newPageGroup) { $this->detail(); } else { $this->detailNewPage(); //$this->groupNewPage(); } break; case "group": $this->group_pointer = $band["groupExpression"]; $this->group_name = $band["gname"]; break; default: break; } } $this->subreportcheckpoint = ''; // if($filename=="") // $filename=$this->arrayPageSetting["name"].".pdf"; // $this->disconnect($this->cndriver); // return true; //send out the complete page // return $this->pdf->Output($filename,$out_method); //send out the complete page }
public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array()) { require_once PATH_THIRDPARTY . 'tcpdf/config/lang/eng.php'; require_once PATH_THIRDPARTY . 'tcpdf/tcpdf.php'; // define Save file $sOutput = 2; $sOrientation = $sLandscape == false ? PDF_PAGE_ORIENTATION : 'L'; $sMedia = isset($aProperties['media']) ? $aProperties['media'] : PDF_PAGE_FORMAT; $sLang = defined('SYS_LANG') ? SYS_LANG : 'en'; // create new PDF document $pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($aFields['USR_USERNAME']); $pdf->SetTitle('Processmaker'); $pdf->SetSubject($sFilename); $margins = $aProperties['margins']; $margins['left'] = $margins['left'] > 0 ? $margins['left'] : PDF_MARGIN_LEFT; $margins['top'] = $margins['top'] > 0 ? $margins['top'] : PDF_MARGIN_TOP; $margins['right'] = $margins['right'] > 0 ? $margins['right'] : PDF_MARGIN_RIGHT; $margins['bottom'] = $margins['bottom'] > 0 ? $margins['bottom'] : PDF_MARGIN_BOTTOM; $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetLeftMargin($margins['left']); $pdf->SetTopMargin($margins['top']); $pdf->SetRightMargin($margins['right']); $pdf->SetAutoPageBreak(true, $margins['bottom']); $oServerConf =& serverConf::getSingleton(); // set some language dependent data: $lg = array(); $lg['a_meta_charset'] = 'UTF-8'; $lg['a_meta_dir'] = $oServerConf->isRtl($sLang) ? 'rtl' : 'ltr'; $lg['a_meta_language'] = $sLang; $lg['w_page'] = 'page'; //set some language-dependent strings $pdf->setLanguageArray($lg); if (isset($aProperties['pdfSecurity'])) { $pdfSecurity = $aProperties['pdfSecurity']; $userPass = G::decrypt($pdfSecurity['openPassword'], $sUID); $ownerPass = $pdfSecurity['ownerPassword'] != '' ? G::decrypt($pdfSecurity['ownerPassword'], $sUID) : null; $permissions = explode("|", $pdfSecurity['permissions']); $pdf->SetProtection($permissions, $userPass, $ownerPass); } // --------------------------------------------------------- // 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', '', 14, '', true); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); // set text shadow effect //$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); // Print text using writeHTMLCell() // $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); $pdf->writeHTML($sContent); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. //$pdf->Output('example_00.pdf', 'I'); //$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D'); switch ($sOutput) { case 0: // Vrew browser $pdf->Output($sPath . $sFilename . '.pdf', 'I'); break; case 1: // Donwnload $pdf->Output($sPath . $sFilename . '.pdf', 'D'); break; case 2: // Save file $pdf->Output($sPath . $sFilename . '.pdf', 'F'); break; } }
<?php require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require_once "{$CFG->libdir}/pdflib.php"; global $USER; $activityid = required_param('id', PARAM_INT); $activity = $DB->get_record('emarking_activities', array('id' => $activityid)); $user_object = $DB->get_record('user', array('id' => $activity->userid)); $usercontext = context_user::instance($USER->id); // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator($USER->firstname . ' ' . $USER->lastname); $pdf->SetAuthor($user->firstname . ' ' . $user->lastname); $pdf->SetTitle($activity->title); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); $pdf->SetFont('helvetica', '', 11); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, 50); $pdf->SetTopMargin(40); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); $pdf->writeHTML($activity->instructions, true, false, false, false, ''); $pdf->Output($activity->title . '.pdf', 'I');
public function outpage($out_method = "I", $filename = "") { if ($this->pdflib == "TCPDF") { if ($this->arrayPageSetting["orientation"] == "P") { $this->pdf = new TCPDF($this->arrayPageSetting["orientation"], 'pt', array(intval($this->arrayPageSetting["pageWidth"]), intval($this->arrayPageSetting["pageHeight"])), true); } else { $this->pdf = new TCPDF($this->arrayPageSetting["orientation"], 'pt', array(intval($this->arrayPageSetting["pageHeight"]), intval($this->arrayPageSetting["pageWidth"])), true); } $this->pdf->setPrintHeader(false); $this->pdf->setPrintFooter(false); } elseif ($this->pdflib == "FPDF") { if ($this->arrayPageSetting["orientation"] == "P") { $this->pdf = new FPDF($this->arrayPageSetting["orientation"], 'pt', array(intval($this->arrayPageSetting["pageWidth"]), intval($this->arrayPageSetting["pageHeight"]))); } else { $this->pdf = new FPDF($this->arrayPageSetting["orientation"], 'pt', array(intval($this->arrayPageSetting["pageHeight"]), intval($this->arrayPageSetting["pageWidth"]))); } } elseif ($this->pdflib == "XLS") { include dirname(__FILE__) . "/ExportXLS.inc.php"; $xls = new ExportXLS($this, $filename, 'Excel5', $out_method); die; } elseif ($this->pdflib == 'CSV') { include dirname(__FILE__) . "/ExportXLS.inc.php"; $xls = new ExportXLS($this, $filename, 'CSV', $out_method); die; } elseif ($this->pdflib == 'XLST' || $this->pdflib == 'XLSX') { include dirname(__FILE__) . "/ExportXLS.inc.php"; $xls = new ExportXLS($this, $filename, 'Excel2007', $out_method); die; } elseif ($this->pdflib == 'HTML') { // echo "SADSAD";die; // echo $this->pdflib."SADSAD";die; // include dirname(__FILE__) . "/ExportHTML.inc.php"; // echo $this->pdflib."aaa";die; // echo $this->pdflib."bb";die; $ht = new ExportHTML($this, $filename, 'HTML', $out_method); // die; } // } //$this->arrayPageSetting["language"]=$xml_path["language"]; // } $this->pdf->SetLeftMargin($this->arrayPageSetting["leftMargin"]); $this->pdf->SetRightMargin($this->arrayPageSetting["rightMargin"]); $this->pdf->SetTopMargin($this->arrayPageSetting["topMargin"]); $this->pdf->SetAutoPageBreak(true, $this->arrayPageSetting["bottomMargin"] / 2); //$this->pdf->AliasNbPages(); $this->global_pointer = 0; $detailbandprinted = false; foreach ($this->arrayband as $band) { switch ($band["name"]) { case "title": if ($this->arraytitle[0]["height"] > 0) { $this->title(); } break; case "pageHeader": if ($this->titlewithpagebreak == false) { $headerY = $this->arrayPageSetting["topMargin"] + $this->titlebandheight; } else { $headerY = $this->arrayPageSetting["topMargin"]; } $this->pageHeader($headerY); $this->titlebandheight = 0; break; case "detail": // if(!$this->newPageGroup) { if ($detailbandprinted == false) { $detailbandprinted = true; $this->detail(); } $totalpage = $this->pdf->getNumPages(); $lastpagefooterpageno = $this->pdf->getPage(); if ($totalpage > $lastpagefooterpageno) { $this->pdf->deletePage($totalpage); } //$this->pdf->getNumPages(); break; case "group": $this->group_pointer = $band["groupExpression"]; $this->group_name = $band["gname"]; break; default: break; } } if ($filename == "") { $filename = $this->arrayPageSetting["name"] . ".pdf"; } // $this->disconnect($this->cndriver); $this->pdf->SetXY(10, 10); //$this->pdf->IncludeJS($this->createJS()); //($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) //$this->pdf->Button('print', 100, 10, 'Print', 'Print()',null,null,20,20,true); return $this->pdf->Output($filename, $out_method); //send out the complete page }
/** * Creates a pdf from selected activity. * * @param unknown $activityid * @return boolean|multitype:unknown NULL Ambigous <boolean, number> */ function get_pdf_activity($activity) { global $USER, $CFG, $DB; require_once $CFG->libdir . '/pdflib.php'; $tempdir = emarking_get_temp_dir_path($activity->id); if (!file_exists($tempdir)) { emarking_initialize_directory($tempdir, true); } $user_object = $DB->get_record('user', array('id' => $activity->userid)); $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator($USER->firstname . ' ' . $USER->lastname); $pdf->SetAuthor($user_object->firstname . ' ' . $user_object->lastname); $pdf->SetTitle($activity->title); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); $pdf->SetFont('helvetica', '', 11); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, 50); $pdf->SetTopMargin(40); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); $pdf->writeHTML($activity->instructions, true, false, false, false, ''); $pdffilename = $activity->title . '.pdf'; $pathname = $tempdir . '/' . $pdffilename; if (@file_exists($pathname)) { unlink($pathname); } $pdf->Output($pathname, 'F'); $itemid = rand(1, 32767); $filerecord = array('contextid' => $usercontext->id, 'component' => 'user', 'filearea' => 'exam_files', 'itemid' => $itemid, 'filepath' => '/', 'filename' => $pdffilename, 'timecreated' => time(), 'timemodified' => time(), 'author' => 'pepito', 'license' => 'allrightsreserved'); // Si el archivo ya existÃa entonces lo borramos. if ($fs->file_exists($usercontext->id, 'mod_emarking', 'user', 4, '/', $pdffilename)) { $contents = $file->get_content(); } $fileinfo = $fs->create_file_from_pathname($filerecord, $pathname); return $itemid; }