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 017'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 017', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 20); // add a page $pdf->AddPage(); $pdf->Write(0, 'Example of independent Multicell() columns', '', 0, 'L', true, 0, false, false, 0); $pdf->Ln(5); $pdf->SetFont('times', '', 12); // create columns content // create columns content $left_column = '[LEFT COLUMN] left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column left column' . "\n"; $right_column = '[RIGHT COLUMN] right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column right column' . "\n"; // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) // set color for background $pdf->SetFillColor(255, 255, 200); // set color for text $pdf->SetTextColor(0, 63, 127); // write the first column $pdf->MultiCell(80, 0, $left_column, 1, 'J', 1, 0, '', '', true, 0, false, true, 0); // set color for background $pdf->SetFillColor(215, 235, 255); // set color for text $pdf->SetTextColor(127, 31, 0); // write the second column $pdf->MultiCell(80, 0, $right_column, 1, 'J', 1, 1, '', '', true, 0, false, true, 0); // reset pointer to the last page $pdf->lastPage(); $this->comparePdfs($pdf); }
/** * @param TicketsOrder $order * @param string $format 'S': data string - 'I' to see in browser * @return string */ public function getPdfFileData(TicketsOrder $order, $format = 'S') { $pdf = new \TCPDF(); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Billets du Louvre'); $pdf->SetTitle('Commande ' . $order->getRef()); $pdf->setPrintHeader(false); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128)); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set style for barcode $style = array('border' => 0, 'vpadding' => 'auto', 'hpadding' => 'auto', 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'module_width' => 1, 'module_height' => 1); /** @var Ticket $ticket */ foreach ($order->getTickets() as $ticket) { $pdf->AddPage(); $html = $this->renderTicket(array('visit_date' => $order->getVisitDate()->format('d/m/Y'), 'visit_duration' => $order->getVisitDuration(), 'code' => $order->getRef(), 'ticket_name' => $ticket->getName(), 'price' => $ticket->getPrice(), 'details' => $ticket->getTicketDetails())); $pdf->writeHTML($html, true, false, true); $pdf->write2DBarcode($order->getRef(), 'QRCODE,H', 150, 10, 50, 50, $style, 'N'); $pdf->lastPage(); } return $pdf->Output('tickets.pdf', $format); }
/** * 初始化 * * @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']); }
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 021'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 021', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 9); // add a page $pdf->AddPage(); // create some HTML content $html = '<h1>Example of HTML text flow</h1>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. <em>Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?</em> <em>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</em><br /><br /><b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i> -> <b>A</b> + <b>B</b> = <b>C</b> -> <i>C</i> - <i>B</i> = <i>A</i> -> <i>C</i> - <i>A</i> = <i>B</i><br /><br /><b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u> <b>Bold</b><i>Italic</i><u>Underlined</u>'; // output the HTML content $pdf->writeHTML($html, true, 0, true, 0); // reset pointer to the last page $pdf->lastPage(); $this->comparePdfs($pdf); }
public function order($order_id) { $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('KHANSA TRADER'); $pdf->SetTitle('Surat perjanjian'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $html = pdf_view($order_id); // Print text using writeHTMLCell() $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, 'J', true); $pdf->lastPage(); $pdf->Output('KHANSA-TRADER - Surat perjanjian.pdf', 'I'); }
static function printTicket($ticket_html, $order) { ob_end_clean(); $config = JComponentHelper::getParams('com_bookpro'); $page_ticket = "<h1 color='Red'> Wellcome to tcpdf </h1>"; $page_ticket = $ticket_html; // create new PDF document $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); $order_number = $order->order_number; // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Joombooking'); $pdf->SetTitle('Travel Ticket ' . $order_number); $pdf->SetSubject('Travel Ticket'); $pdf->SetKeywords('TCPDF, PDF, ticket, travel, booking'); // set default header data //$pdf->SetHeaderData($config->get('company_logo'),50, $config->get('company_name'), "Ticket \n www."); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); //$pdf->setHeaderMargin(10); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins //$pdf->SetMargins(30, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('times', '', 11); // add a page $pdf->AddPage(); // set JPEG quality $pdf->setJPEGQuality(75); $style['position'] = 'R'; /* * $type type of barcode (see tcpdf_barcodes_1d.php for supported formats). * */ //$pdf->write1DBarcode($order_number, 'C128B','', '', '', 10, 0.4, $style, 'M'); // create some HTML content //$pdf->writeHTML($htmlcontent, true, 0, true, 0); //$pdf->WriteHTML(file_get_contents('test.html')); $pdf->WriteHTML($page_ticket); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document ob_end_clean(); $pdf->Output($order->name . '.pdf', 'I'); //Should use variable to make file name ob_end_flush(); }
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"; }
/** * Starts a new page * * Subsequent drawing operations will appear on the new page. */ function new_page() { dompdf_debug("trace", "()"); // Add objects to the current page $this->_place_objects(); //$this->_pdf->endPage(); $this->_pdf->lastPage(); $this->_pdf->AddPage(); //$this->_page_count++; $this->_pages[] = $this->_pdf->PageNo(); return $this->_pdf->getNumPages(); }
/** * Render the invoice. * * @return mixed */ public function render() { /* @var $l array */ require_once 'tcpdf/config/lang/eng.php'; require_once 'tcpdf/tcpdf.php'; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator('Kimai Timetracking (http://www.kimai.org)'); //$pdf->SetAuthor('Kevin Papst'); //$pdf->SetTitle('Invoice'); //$pdf->SetSubject('Invoice'); //$pdf->SetKeywords('Invoice'); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING); // set header and footer fonts //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $html = $this->getHtml(); // output the HTML content $pdf->writeHTML($html, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document $pdf->Output('invoice.pdf', 'I'); }
/** * Generate the pdf document * * @param IsotopeProductCollection $objCollection * @param array $arrTokens * * @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'; // 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(\StringUtil::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; }
public function invoicedownloadAction() { //error_reporting(E_ALL); //ini_set('display_errors', 1); error_reporting(0); $renderer = new PhpRenderer(); //whole TCPDF's settings goes here $id = $this->params()->fromQuery('id'); $lang_code = $this->params()->fromRoute('lang'); // Get Project $entityManager = $this->getEntityManager(); $project = $entityManager->find('\\User\\Entity\\Project', (int) $id); $project_data = $project->getData(); $types = $project_data['types']; $hasTypeTranslationNoTM = 0; $hasTypeTranslationUseTM = 0; $hasTypeDesktopPublishingWin = 0; $hasTypeDesktopPublishingMac = 0; $hasTypeDesktopPublishingEngineer = 0; $hasTypeDesktopPublishingInterpreting = 0; foreach ($types as $type) { if ($type == 1) { $hasTypeTranslationNoTM = 1; } else { if ($type == 2) { $hasTypeTranslationUseTM = 1; } else { if ($type == 3) { $hasTypeDesktopPublishingWin = 1; } else { if ($type == 4) { $hasTypeDesktopPublishingMac = 1; } else { if ($type == 5) { $hasTypeDesktopPublishingEngineer = 1; } else { if ($type > 5) { $hasTypeDesktopPublishingInterpreting = 1; } } } } } } } if ($project_data['serviceLevel'] == 1) { $serviceLevel = "Professional"; } else { if ($project_data['serviceLevel'] == 2) { $serviceLevel = "Business"; } else { if ($project_data['serviceLevel'] == 3) { $serviceLevel = "Premium"; } } } //get invoice $repository = $entityManager->getRepository('User\\Entity\\Invoice'); $invoice = $repository->findBy(array('project' => $project)); $invoices = array(); foreach ($invoice as $k => $v) { $invoices[$k] = $v->getData(); } $invoices['invoice_no'] = "INV-" . $project_data["project_no"]; $invoices = $invoices[0]; $invoiceDate = ''; $dueDate = ''; if ($invoices['invoiceDate']) { $invoiceDate = $invoices['invoiceDate']->format('d M Y'); } if ($invoices['dueDate']) { $dueDate = $invoices['dueDate']->format('d M Y'); } //Get company info if ($project_data['currency'] == 'cny') { $companyinfo = $entityManager->find('\\Admin\\Entity\\ProfileInfo', 1); } else { $companyinfo = $entityManager->find('\\Admin\\Entity\\ProfileInfo', 2); } //$companyinfo = $entityManager->find('\Admin\Entity\ProfileInfo', 1); //Get bank info if ($project_data['currency'] == 'cny') { $bankinfo = $entityManager->find('\\Admin\\Entity\\ProfileBank', 1); } else { $bankinfo = $entityManager->find('\\Admin\\Entity\\ProfileBank', 2); } $subtotal = 0; //get iterm translation $repository = $entityManager->getRepository('User\\Entity\\Itermnotm'); $iterm_translation = $repository->findBy(array('project' => $project)); $iterm_translations = array(); foreach ($iterm_translation as $k => $v) { $iterm_translations[$k] = $v->getData(); if ($hasTypeTranslationNoTM == 1) { $subtotal = $subtotal + $iterm_translations[$k]['total']; } } //get iterm translationtm $repository = $entityManager->getRepository('User\\Entity\\Itermtm'); $iterm_translationtm = $repository->findBy(array('project' => $project)); $iterm_translationtms = array(); foreach ($iterm_translationtm as $k => $v) { $tmp = $v->getData(); $iterm_translationtms[$tmp['language']['id']] = $v->getData(); if ($hasTypeTranslationUseTM == 1) { $subtotal = $subtotal + $iterm_translationtms[$k]['total']; } } //get iterm iterm_dtppcs $repository = $entityManager->getRepository('User\\Entity\\Itermdtppc'); $iterm_dtppc = $repository->findBy(array('project' => $project)); $iterm_dtppcs = array(); foreach ($iterm_dtppc as $k => $v) { $tmp = $v->getData(); if ($tmp['unit'] == 1) { $tmp['unit'] = 'Day'; } else { $tmp['unit'] = 'Half Day'; } $iterm_dtppcs[$k] = $tmp; if ($hasTypeDesktopPublishingWin == 1) { $subtotal = $subtotal + $iterm_dtppcs[$k]['total']; } } //get iterm iterm_dtpmac $repository = $entityManager->getRepository('User\\Entity\\Itermdtpmac'); $iterm_dtpmac = $repository->findBy(array('project' => $project)); $iterm_dtpmacs = array(); foreach ($iterm_dtpmac as $k => $v) { $tmp = $v->getData(); if ($tmp['unit'] == 1) { $tmp['unit'] = 'Day'; } else { $tmp['unit'] = 'Half Day'; } $iterm_dtpmacs[$k] = $tmp; if ($hasTypeDesktopPublishingMac == 1) { $subtotal = $subtotal + $iterm_dtpmacs[$k]['total']; } } // Get Interpreting Price $repository = $entityManager->getRepository('User\\Entity\\Iterminterpreting'); $iterm_interpreting = $repository->findBy(array('project' => $project)); $iterm_interpretings = array(); foreach ($iterm_interpreting as $k => $v) { $tmp = $v->getData(); if ($tmp['unit'] == 1) { $tmp['unit'] = 'Day'; } else { if ($tmp['unit'] == 2) { $tmp['unit'] = 'Half Day'; } } $iterm_interpretings[$k] = $tmp; if ($hasTypeDesktopPublishingInterpreting == 1) { $subtotal = $subtotal + $iterm_interpretings[$k]['total']; } } // Get Itermengineering $repository = $entityManager->getRepository('User\\Entity\\Itermengineering'); $iterm_engineering = $repository->findBy(array('project' => $project)); $iterm_engineerings = array(); foreach ($iterm_engineering as $k => $v) { $tmp = $v->getData(); if ($tmp['unit'] == 1) { $tmp['unit'] = 'Hour'; } else { if ($tmp['unit'] == 2) { $tmp['unit'] = 'Day'; } else { if ($tmp['unit'] == 3) { $tmp['unit'] = 'Month'; } else { if ($tmp['unit'] == 4) { $tmp['unit'] = 'Word'; } else { if ($tmp['unit'] == 5) { $tmp['unit'] = 'Graphic'; } else { $tmp['unit'] = 'Page'; } } } } } $iterm_engineerings[$k] = $tmp; if ($hasTypeDesktopPublishingEngineer == 1) { $subtotal = $subtotal + $iterm_engineerings[$k]['total']; } } $view = $this->getServiceLocator()->get('Zend\\View\\Renderer\\RendererInterface'); $viewModel = new ViewModel(); $template = '/admin/project/invoicedownload'; $viewModel->setTemplate($template)->setVariables(array('id' => $id, 'lang_code' => $lang_code, 'project' => $project->getData(), 'companyinfo' => $companyinfo->getData(), 'bankinfo' => $bankinfo ? $bankinfo->getData() : null, 'hasTypeTranslationNoTM' => $hasTypeTranslationNoTM, 'hasTypeTranslationUseTM' => $hasTypeTranslationUseTM, 'hasTypeDesktopPublishingWin' => $hasTypeDesktopPublishingWin, 'hasTypeDesktopPublishingMac' => $hasTypeDesktopPublishingMac, 'hasTypeDesktopPublishingEngineer' => $hasTypeDesktopPublishingEngineer, 'hasTypeDesktopPublishingInterpreting' => $hasTypeDesktopPublishingInterpreting, 'iterm_translations' => $iterm_translations, 'iterm_translationtms' => $iterm_translationtms, 'iterm_dtppcs' => $iterm_dtppcs, 'iterm_dtpmacs' => $iterm_dtpmacs, 'iterm_interpretings' => $iterm_interpretings, 'iterm_engineerings' => $iterm_engineerings, 'serviceLevel' => $serviceLevel, 'subtotal' => $subtotal, 'invoices' => $invoices, 'dueDate' => $dueDate, 'invoiceDate' => $invoiceDate))->setTerminal(true); //return $viewModel; $content = $view->render($viewModel); // set array for viewer preferences $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $font = new \TCPDF_FONTS(); //$fontx = $font->addTTFfont('public/fonts/STHeiti-Light.ttc'); //$pdf->SetFont($fontx, '', 12, '', false); //$pdf->SetFont('microsoftyahei' , '', 12,'',false); $pdf->SetFont('droidsansfallback', '', 7); $pdf->setFontSubsetting(true); $preferences = array('HideToolbar' => true, 'HideMenubar' => true, 'HideWindowUI' => true, 'FitWindow' => true, 'CenterWindow' => true, 'DisplayDocTitle' => true, 'NonFullScreenPageMode' => 'UseNone', 'ViewArea' => 'CropBox', 'ViewClip' => 'CropBox', 'PrintArea' => 'CropBox', 'PrintClip' => 'CropBox', 'PrintScaling' => 'AppDefault', 'Duplex' => 'DuplexFlipLongEdge', 'PickTrayByPDFSize' => true, 'PrintPageRange' => array(1, 1, 2, 3), 'NumCopies' => 2); // set pdf viewer preferences $pdf->setViewerPreferences($preferences); // add a page $pdf->AddPage(); // output the HTML content $pdf->writeHTML($content, true, false, true, false, ''); $pdf->lastPage(); $name = "INV-" . $project_data['project_no'] . ".pdf"; ob_end_clean(); $pdf->Output($name, 'D'); //$pdf->Output("pdf-name.pdf", 'D'); exit; }
function generatePDF($action = 'return') { if (!in_array($action, ['return', 'dump'])) { throw $this->exception('Please provide action as result or dump'); } $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('xEpan ERP'); $pdf->SetTitle($this['type'] . ' ' . $this['document_no']); $pdf->SetSubject($this['type'] . ' ' . $this['document_no']); $pdf->SetKeywords($this['type'] . ' ' . $this['document_no']); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set font $pdf->SetFont('dejavusans', '', 10); //remove header or footer hr lines $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // add a page $pdf->AddPage(); if ($org = $this->ref('contact_id')->get('organization')) { $this['contact'] = $org; $this['contact_id'] = ''; } // getting layouts from config $layout_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['master' => 'xepan\\base\\RichText', 'detail' => 'xepan\\base\\RichText'], 'config_key' => strtoupper($this['type']) . '_LAYOUT', 'application' => 'commerce']); $layout_m->tryLoadAny(); $info_config = $layout_m['master']; $info_layout = $this->add('GiTemplate'); $info_layout->loadTemplateFromString($info_config); $detail_config = $layout_m['detail']; $detail_layout = $this->add('GiTemplate'); $detail_layout->loadTemplateFromString($detail_config); $new = $this->add('xepan\\commerce\\Model_QSP_Master'); $new->addHook('afterLoad', function ($m) { $m['round_amount'] = abs($m['round_amount']); }); $new->load($this->id); $view = $this->app->add('xepan\\commerce\\View_QSP', ['qsp_model' => $new, 'master_template' => $info_layout, 'detail_template' => $detail_layout, 'action' => 'pdf']); // $view = $this->owner->add('xepan\commerce\View_QSP',['qsp_model'=>$this]); if ($bar_code = $this->getBarCode()) { $barcodeobj = new \TCPDFBarcode($bar_code, 'C128'); // $barcode_html = $barcodeobj->getBarcodePNG(2, 30, 'black'); $barcode_html = $barcodeobj->getBarcodePngData(1, 20, array(0, 128, 0)); $info_layout->trySetHtml('dispatch_barcode', '<img src="data:image/png;base64, ' . base64_encode($barcode_html) . '"/>'); } $html = $view->getHTML(); // echo "string".$html; // echo $html; // exit; // output the HTML content $pdf->writeHTML($html, false, false, true, false, ''); // set default form properties $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128))); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document switch ($action) { case 'return': return $pdf->Output(null, 'S'); break; case 'dump': return $pdf->Output(null, 'I'); exit; break; } }
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 054'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 054', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // IMPORTANT: disable font subsetting to allow users editing the document $pdf->setFontSubsetting(false); // set font $pdf->SetFont('helvetica', '', 10, '', false); // add a page $pdf->AddPage(); // create some HTML content $html = <<<EOD <h1>XHTML Form Example</h1> <form method="post" action="http://localhost/printvars.php" enctype="multipart/form-data"> <label for="name">name:</label> <input type="text" name="name" value="" size="20" maxlength="30" /><br /> <label for="password">password:</label> <input type="password" name="password" value="" size="20" maxlength="30" /><br /><br /> <label for="infile">file:</label> <input type="file" name="userfile" size="20" /><br /><br /> <input type="checkbox" name="agree" value="1" checked="checked" /> <label for="agree">I agree </label><br /><br /> <input type="radio" name="radioquestion" id="rqa" value="1" /> <label for="rqa">one</label><br /> <input type="radio" name="radioquestion" id="rqb" value="2" checked="checked"/> <label for="rqb">two</label><br /> <input type="radio" name="radioquestion" id="rqc" value="3" /> <label for="rqc">three</label><br /><br /> <label for="selection">select:</label> <select name="selection" size="0"> <option value="0">zero</option> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select><br /><br /> <label for="selection">select:</label> <select name="multiselection" size="2" multiple="multiple"> <option value="0">zero</option> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select><br /><br /><br /> <label for="text">text area:</label><br /> <textarea cols="40" rows="3" name="text">line one line two</textarea><br /> <br /><br /><br /> <input type="reset" name="reset" value="Reset" /> <input type="submit" name="submit" value="Submit" /> <input type="button" name="print" value="Print" onclick="print()" /> <input type="hidden" name="hiddenfield" value="OK" /> <br /> </form> EOD; // output the HTML content $pdf->writeHTML($html, true, 0, true, 0); // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- $this->comparePdfs($pdf); }
/** * Convert html to tcpdf. * * @param $paper_size * @param $orientation * @param $margins * @param $html * @param $output * @param $fileName * @param $stationery_path */ public static function _html2pdf_tcpdf($paper_size, $orientation, $margins, $html, $output, $fileName, $stationery_path) { // Documentation on the TCPDF library can be found at: http://www.tcpdf.org // This function also uses the FPDI library documented at: http://www.setasign.com/products/fpdi/about/ // Syntax borrowed from https://github.com/jake-mw/CDNTaxReceipts/blob/master/cdntaxreceipts.functions.inc require_once 'tcpdf/tcpdf.php'; require_once 'FPDI/fpdi.php'; // This library is only in the 'packages' area as of version 4.5 $paper_size_arr = array($paper_size[2], $paper_size[3]); $pdf = new TCPDF($orientation, 'pt', $paper_size_arr); $pdf->Open(); if (is_readable($stationery_path)) { $pdf->SetStationery($stationery_path); } $pdf->SetAuthor(''); $pdf->SetKeywords('CiviCRM.org'); $pdf->setPageUnit($margins[0]); $pdf->SetMargins($margins[4], $margins[1], $margins[2], TRUE); $pdf->setJPEGQuality('100'); $pdf->SetAutoPageBreak(TRUE, $margins[3]); $pdf->AddPage(); $ln = TRUE; $fill = FALSE; $reset_parm = FALSE; $cell = FALSE; $align = ''; // output the HTML content $pdf->writeHTML($html, $ln, $fill, $reset_parm, $cell, $align); // reset pointer to the last page $pdf->lastPage(); // close and output the PDF $pdf->Close(); $pdf_file = 'CiviLetter' . '.pdf'; $pdf->Output($pdf_file, 'D'); CRM_Utils_System::civiExit(1); }
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'); }
protected function renderPDFIntoFile($template, $filename) { require_once DIR_SYSTEM . 'tcpdf/config/lang/eng.php'; require_once DIR_SYSTEM . 'tcpdf/tcpdf.php'; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('dejavusans', '', 10); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // add a page $pdf->AddPage(); $tablecontent = $this->fetch($template); // output the HTML content $pdf->writeHTML($tablecontent, true, false, true, false, ''); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('invoice' . $filename . '.pdf', 'F'); //============================================================+ // END OF FILE //============================================================+ }
function generatePDF($action = 'return') { if (!in_array($action, ['return', 'dump'])) { throw $this->exception('Please provide action as result or dump'); } $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('xEpan ERP'); $pdf->SetTitle($this['type'] . ' ' . $this['id']); $pdf->SetSubject($this['type'] . ' ' . $this['id']); $pdf->SetKeywords($this['type'] . ' ' . $this['id']); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); $config_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['subject' => 'Line', 'body' => 'xepan\\base\\RichText', 'master' => 'xepan\\base\\RichText'], 'config_key' => 'PRODUCTION_JOBCARD_SYSTEM_CONFIG', 'application' => 'production']); $config_m->tryLoadAny(); $jobcard_config = $config_m['master']; if (!$config_m->loaded()) { $jobcard_config = file_get_contents(realpath("../vendor/xepan/production/templates/default/jobcard-received-print.html")); } $jobcard_layout = $this->add('GiTemplate'); $jobcard_layout->loadTemplateFromString($jobcard_config); $new = $this->add('xepan\\production\\Model_Jobcard'); $new->load($this->id); $view = $this->app->add('View', null, null, $jobcard_layout); $view->setModel($new); $order_item_detail = $this->add('xepan\\commerce\\Model_QSP_Detail'); $order_item_detail->tryLoadBy('id', $this['order_item_id']); $array = json_decode($order_item_detail['extra_info'] ?: "[]", true); $cf_html = ""; foreach ($array as $department_id => &$details) { $department_name = $details['department_name']; $cf_list = $view->add('CompleteLister', null, 'extra_info', ['view\\qsp\\extrainfo']); $cf_list->template->trySet('department_name', $department_name); unset($details['department_name']); $cf_list->setSource($details); $cf_html .= $cf_list->getHtml(); } $view->template->trySetHtml('extra_info', $cf_html); // $view = $this->add('View')->set("Production Jobcard Received View TODO"); $html = $view->getHTML(); // echo "<pre>"; // print_r($html); // echo "</pre>"; // output the HTML content $pdf->writeHTML($html, false, false, true, false, ''); // set default form properties $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128))); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document switch ($action) { case 'return': return $pdf->Output(null, 'S'); break; case 'dump': return $pdf->Output(null, 'I'); exit; break; } }
function generatePDF($action = 'return', $view) { if (!in_array($action, ['return', 'dump'])) { throw $this->exception('Please provide action as result or dump'); } $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('xEpan ERP'); // $pdf->SetTitle($this['type']. ' '. $this['document_no']); // $pdf->SetSubject($this['type']. ' '. $this['document_no']); // $pdf->SetKeywords($this['type']. ' '. $this['document_no']); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set font $pdf->SetFont('dejavusans', '', 10); //remove header or footer hr lines $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // add a page $pdf->AddPage(); $html = $view->getHTML(); // echo $html; // exit; // output the HTML content $pdf->writeHTML($html, false, false, true, false, ''); // set default form properties $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128))); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document switch ($action) { case 'return': return $pdf->Output(null, 'S'); break; case 'dump': return $pdf->Output(null, 'I'); exit; break; } }
function exppdf($filter = array(), $mailback = false, $translate = true) { global $ff_compath; jimport('joomla.version'); $version = new JVersion(); $_version = $version->getShortVersion(); $tz = 'UTC'; if (version_compare($_version, '3.2', '>=')) { $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); } $file = JPATH_SITE . '/media/breezingforms/pdftpl/' . $this->formrow->name . '_pdf_attachment.php'; if (!JFile::exists($file)) { $file = JPATH_SITE . '/media/breezingforms/pdftpl/pdf_attachment.php'; } if ($mailback) { $mb_file = JPATH_SITE . '/media/breezingforms/pdftpl/' . $this->formrow->name . '_pdf_mailback_attachment.php'; if (JFile::exists($mb_file)) { $file = $mb_file; } else { $mb_file = JPATH_SITE . '/media/breezingforms/pdftpl/pdf_mailback_attachment.php'; if (JFile::exists($mb_file)) { $file = $mb_file; } } } $processed = array(); $xmldata = array(); $_xmldata = $this->xmldata; if ($mailback) { $_xmldata = $this->mb_xmldata; } foreach ($_xmldata as $data) { if (!in_array($data[_FF_DATA_NAME], $filter) && !in_array($data[_FF_DATA_NAME], $processed)) { if ($translate) { $title_translated = ''; $this->getFieldTranslated('label', $data[_FF_DATA_NAME], $title_translated); $data[_FF_DATA_TITLE] = $title_translated != '' ? $title_translated : $data[_FF_DATA_TITLE]; } $xmldata[] = $data; //$processed[] = $data[_FF_DATA_NAME]; } } $submitted = $this->submitted; if (version_compare($_version, '3.2', '>=')) { $date_ = JFactory::getDate($this->submitted, $tz); $this->submitted = $date_->format('Y-m-d H:i:s'); } ob_start(); require $file; $c = ob_get_contents(); ob_end_clean(); $this->submitted = $submitted; require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/tcpdf/tcpdf.php'; $pdf = new TCPDF(); $pdf->setPrintHeader(false); $pdf->AddPage(); $pdf->writeHTML($c); mt_srand(); $pdfname = $ff_compath . '/exports/ffexport-pdf-' . date('YmdHis') . '-' . mt_rand(0, mt_getrandmax()) . '.pdf'; $pdf->lastPage(); $pdf->Output($pdfname, "F"); return $pdfname; }
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 049'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 049', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * IMPORTANT: If you are printing user-generated content, tcpdf tag can be unsafe. You can disable this tag by setting to false the K_TCPDF_CALLS_IN_HTML constant on TCPDF configuration file. For security reasons, the parameters for the 'params' attribute of TCPDF tag must be prepared as an array and encoded with the serializeTCPDFtagParameters() method (see the example below). * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ $html = '<h1>Test TCPDF Methods in HTML</h1> <h2 style="color:red;">IMPORTANT:</h2> <span style="color:red;">If you are using user-generated content, the tcpdf tag can be unsafe.<br /> You can disable this tag by setting to false the <b>K_TCPDF_CALLS_IN_HTML</b> constant on TCPDF configuration file.</span> <h2>write1DBarcode method in HTML</h2>'; $params = $pdf->serializeTCPDFtagParameters(array('CODE 39', 'C39', '', '', 80, 30, 0.4, array('position' => 'S', 'border' => true, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => true, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N')); $html .= '<tcpdf method="write1DBarcode" params="' . $params . '" />'; $params = $pdf->serializeTCPDFtagParameters(array('CODE 128', 'C128', '', '', 80, 30, 0.4, array('position' => 'S', 'border' => true, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => true, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N')); $html .= '<tcpdf method="write1DBarcode" params="' . $params . '" />'; $html .= '<tcpdf method="AddPage" /><h2>Graphic Functions</h2>'; $params = $pdf->serializeTCPDFtagParameters(array(0)); $html .= '<tcpdf method="SetDrawColor" params="' . $params . '" />'; $params = $pdf->serializeTCPDFtagParameters(array(50, 50, 40, 10, 'DF', array(), array(0, 128, 255))); $html .= '<tcpdf method="Rect" params="' . $params . '" />'; // output the HTML content $pdf->writeHTML($html, true, 0, true, 0); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // reset pointer to the last page $pdf->lastPage(); $this->comparePdfs($pdf); }
/** * fetchPdf - fetch rendered document as a string * * @param Response $response \Xoops\Core\Service\Response object * * @return void - response->value set to string containing document */ public function fetchPdf($response) { $this->initPdf(); $this->pdfEngine->lastPage(); $response->seValue($this->pdfEngine->Output('', 'S')); }
function viewCarpetas() { require_once 'tcpdf/config/lang/eng.php'; require_once 'tcpdf/tcpdf.php'; $this->usuario = new usuario(); // create new PDF document $pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($this->usuario->obtenerNombre($_SESSION['USU_ID'])); $pdf->SetTitle('Etiquetado de Expedientes'); $pdf->SetSubject('Etiquetado de Expedientes'); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(11, 12, 9); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, 2); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->SetFont('helvetica', '', 8); $tipo = $_REQUEST['tipo']; $nro_exps_max = 20; $nro_exps = $_REQUEST['nro_exps']; if ($nro_exps > $nro_exps_max || $nro_exps == '') { $nro_exps = $nro_exps_max; } $res = $this->obtenerContenidoXFilas('ARCHIVADOR', $nro_exps, 35); $st = ''; $i = 0; foreach ($res as $i => $etiq) { if ($i % 4 == 0) { $pdf->AddPage('L', 'LETTER'); $st = ''; $st .= '<table width="18cm" border="0" style="width: 18cm;height:18.5cm;" cellspacing="5" ><tr>'; } $st .= '<td width="6.5cm" height="18.5cm">'; $st .= '<table width="5.5cm" border="1" style="width: 5.5cm;height:18.5cm;" cellspadding="2" >'; $st .= '<tr><td width="5.5cm" height="17.5cm" align="center">'; $st .= '<img src="' . PATH_ROOT . '/web/img/escudo.png" width="60" height="60" border="0" />'; $st .= '<span style="font-size: 30px;font-weight: bold;width:80%">'; // if ($etiq['ins_id'] != 1) { // //obtenemos la descripcion de la institucion 1 // $inst = new tab_unidad(); // $sql = "SELECT // tun.uni_codigo, // tun.uni_descripcion as inst_origen, // tun.uni_id // FROM // tab_institucion AS tin // Inner Join tab_unidad AS tun ON tun.uni_id = tin.uni_id // WHERE // tin.ins_id = '1' "; // $r_inst = $inst->dbselectBySQL($sql); // $inst_origen = ''; // if (count($r_inst) > 0) { // $inst_origen = $r_inst[0]->inst_origen; // } // $st.='<br />' . $inst_origen; // } else { // $st.='<br />' . $etiq['institucion']; // } $st .= '</span>'; $st .= '<span style="font-size: 30px;font-weight: bold;">'; // if ($etiq['ins_id'] != 1) { // $st.='<br />' . $etiq['ins_nombre']; // } if ($etiq['direccion'] != '') { $st .= '<br />' . $etiq['direccion']; } if ($etiq['unidad'] != $etiq['direccion']) { $st .= '<br />' . $etiq['unidad']; } $st .= '</span>'; $st .= '<br />SERIE: ' . strtoupper($etiq['serie']) . '<br />'; $st .= '<font size="6">'; $st .= '<table width="5.45cm" border="1" cellspadding="2" >'; $st .= '<tr><td width="15%">Nº</td><td width="85%">Tituto</td></tr>'; foreach ($etiq['rows'] as $ei => $exp) { $st .= '<tr><td width="15%">' . ($ei + 1) . '</td><td width="85%" align="left">' . substr($exp['exp_nombre'], 0, 100) . '</td></tr>'; } $st .= '</table>'; $st .= '</font></td></tr>'; $st .= '<tr><td width="5.5cm" align="center">FECHAS EXTREMAS: ' . strtoupper($etiq['fextremas']) . '</td></tr>'; $st .= '<tr><td width="5.5cm" align="center">CARPETA NRO.: ' . strtoupper($etiq['nro']) . '<br />'; $st .= 'GESTION: ' . strtoupper($etiq['gestion']) . '</td></tr>'; $st .= '<tr><td width="5.5cm" align="center"> '; if ($etiq['contenedor'] != '') { $st .= strtoupper($etiq['contenedor']); } $st .= '</td></tr>'; $st .= '</table>'; $st .= '</td>'; if ($i % 4 == 3) { $st .= '</tr></table>'; $pdf->writeHTML($st, false, false, false, false, ''); $pdf->lastPage(); } } if ($i % 4 != 3) { $st .= '</tr></table>'; $pdf->writeHTML($st, false, false, false, false, ''); $pdf->lastPage(); } $pdf->Output('etiquetasCarpetas.pdf', 'I'); }
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('times', '', 10); // add a page $pdf->AddPage(); // set color for filler $pdf->SetFillColor(255, 255, 0); // Multicell test $pdf->MultiCell(40, 5, 'A test multicell line 1 test multicell line 2 test multicell line 3', 1, 'L', 1, 0, '', '', true); $pdf->MultiCell(40, 5, 'B test multicell line 1 test multicell line 2 test multicell line 3', 1, 'R', 0, 1, '', '', true); $pdf->MultiCell(40, 5, 'C test multicell line 1 test multicell line 2 test multicell line 3', 1, 'C', 0, 0, '', '', true); $pdf->MultiCell(40, 5, 'D test multicell line 1 test multicell line 2 test multicell line 3' . "\n", 1, 'J', 1, 2, '', '', true); $pdf->MultiCell(40, 5, 'E test multicell line 1 test multicell line 2 test multicell line 3', 1, 'L', 0, 1, '', '', true); $pdf->SetFillColor(255, 200, 200); $pdf->MultiCell(40, 5, 'F test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line test multicell line' . "\n", 1, 'J', 1, 1, '', '', true); // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('example_005.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $obj_pdf->SetMargins(10, 34, 10); $obj_pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM); $obj_pdf->SetFont('helvetica', '', 10); $obj_pdf->setFontSubsetting(FALSE); $obj_pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone'); $obj_pdf->AddPage(); $obj_pdf->SetFont("helvetica", '', 20); $obj_pdf->Ln(107); $obj_pdf->MultiCell(180, 10, $no, 0, 'C', 0, 1, '', '', true, 0, false, true, 10, 'B'); $obj_pdf->Ln(30); $obj_pdf->SetFont($fontnama, '', 22); $obj_pdf->MultiCell(220, 10, $nama, 0, 'C', 0, 1, '', '', true, 0, false, true, 10, 'B'); $obj_pdf->Ln(5); $obj_pdf->SetFont('helvetica', '', 12); $obj_pdf->MultiCell(75, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(50, 8, $tgl, 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(20, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(40, 8, strtoupper($tempat), 0, 'L', 0, 1, '', '', true, 0, false, true, 9, 'B'); $obj_pdf->Ln(7); $obj_pdf->MultiCell(120, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(70, 8, $jns, 0, 'L', 0, 1, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(70, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(80, 8, $hasil, 0, 'L', 0, 1, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(100, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(30, 8, $mulai, 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(20, 8, "", 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->MultiCell(30, 8, $selesai, 0, 'L', 0, 0, '', '', true, 0, false, true, 8, 'B'); $obj_pdf->lastPage(); $obj_pdf->Output('Cetak Ijazah ' . $no . '.pdf', 'I');
/** * display article as pdf * * @author Erik Spaan * @param 'sid' The article ID * @param 'objectid' generic object id maps to sid if present * @return string HTML string */ public function displaypdf($args) { // Get parameters from whatever input we need $sid = (int)FormUtil::getPassedValue('sid', null, 'REQUEST'); $objectid = (int)FormUtil::getPassedValue('objectid', null, 'REQUEST'); $title = FormUtil::getPassedValue('title', null, 'REQUEST'); $year = FormUtil::getPassedValue('year', null, 'REQUEST'); $monthnum = FormUtil::getPassedValue('monthnum', null, 'REQUEST'); $monthname = FormUtil::getPassedValue('monthname', null, 'REQUEST'); $day = FormUtil::getPassedValue('day', null, 'REQUEST'); // User functions of this type can be called by other modules extract($args); // At this stage we check to see if we have been passed $objectid, the // generic item identifier if ($objectid) { $sid = $objectid; } // Validate the essential parameters if ((empty($sid) || !is_numeric($sid)) && (empty($title))) { return LogUtil::registerArgsError(); } if (!empty($title)) { unset($sid); } // we set TEMPLATE caching to false because we will utilize // FILE caching of pdf files instead $this->view->setCaching(false); // Get the news story if (isset($sid)) { $item = ModUtil::apiFunc('News', 'user', 'get', array('sid' => $sid, 'status' => 0)); } else { $item = ModUtil::apiFunc('News', 'user', 'get', array('title' => $title, 'year' => $year, 'monthname' => $monthname, 'monthnum' => $monthnum, 'day' => $day, 'status' => 0)); $sid = $item['sid']; System::queryStringSetVar('sid', $sid); } if ($item === false) { return LogUtil::registerError($this->__('Error! No such article found.'), 404); } // check for cached pdf file if ($this->getVar('pdflink_enablecache', true)) { $cachedPdf = $this->pdfIsCached($item['urltitle']); if ($cachedPdf) { $this->outputCachedPdf($cachedPdf); return true; } } // $info is array holding raw information. $info = ModUtil::apiFunc('News', 'user', 'getArticleInfo', $item); // $links is an array holding pure URLs to specific functions for this article. $links = ModUtil::apiFunc('News', 'user', 'getArticleLinks', $info); // $preformat is an array holding chunks of preformatted text for this article. $preformat = ModUtil::apiFunc('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links)); // Assign the story info arrays $this->view->assign(array('info' => $info, 'links' => $links, 'preformat' => $preformat)); // Store output in variable $articlehtml = $this->view->fetch('user/articlepdf.tpl'); // Include and configure the TCPDF class define('K_TCPDF_EXTERNAL_CONFIG', true); $classfile = DataUtil::formatForOS('modules/News/lib/vendor/tcpdf/tcpdf.php'); include_once $classfile; $lang = ZLanguage::getInstance(); $langcode = $lang->getLanguageCodeLegacy(); $langfile = DataUtil::formatForOS("modules/News/lib/vendor/tcpdf/config/lang/{$langcode}.php"); if (file_exists($langfile)) { include_once $langfile; } else { // default to english include_once DataUtil::formatForOS('modules/News/lib/vendor/tcpdf/config/lang/eng.php'); } $configfile = DataUtil::formatForOS('modules/News/lib/vendor/tcpdf_news_config.php'); require_once $configfile; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set pdf document information $pdf->SetCreator(System::getVar('sitename')); $pdf->SetAuthor($info['contributor']); $pdf->SetTitle($info['title']); $pdf->SetSubject($info['cattitle']); //$pdf->SetKeywords($info['cattitle']); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $sitename = System::getVar('sitename'); /* $pdf->SetHeaderData( $modvars['pdflink_headerlogo'], $modvars['pdflink_headerlogo_width'], $this->__f('Article %1$s by %2$s', array($info['title'], $info['contributor'])), $sitename . ' :: ' . $this->__('News publisher')); */ $pdf->SetHeaderData($this->getVar('pdflink_headerlogo'), $this->getVar('pdflink_headerlogo_width'), '', $sitename . ' :: ' . $info['cattitle'] . ' :: ' . $info['topicname']); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // $l is undefined??? TODO // set font, freeserif is big ! //$pdf->SetFont('freeserif', '', 10); // For Unicode data put dejavusans in tcpdf_config.php $pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN); // add a page $pdf->AddPage(); // output the HTML content $pdf->writeHTML($articlehtml, true, 0, true, 0); // reset pointer to the last page $pdf->lastPage(); if ($this->getVar('pdflink_enablecache', true)) { $pdfMode = "FI"; $dir = CacheUtil::getLocalDir('NewsPDF'); $pdfFileName = $dir . '/' . $info['urltitle'] . '.pdf'; } else { $pdfMode = "I"; $pdfFileName = $info['urltitle'] . '.pdf'; } //Close and output PDF document $pdf->Output($pdfFileName, $pdfMode); // Since the output doesn't need the theme wrapped around it, // let the theme know that the function is already finished return true; }
function generatePDF($action = 'return') { if (!in_array($action, ['return', 'dump'])) { throw $this->exception('Please provide action as result or dump'); } $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('xEpan ERP'); $pdf->SetTitle($this['type'] . ' ' . $this['id']); $pdf->SetSubject($this['type'] . ' ' . $this['id']); $pdf->SetKeywords($this['type'] . ' ' . $this['id']); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); $challan_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['master' => 'xepan\\base\\RichText', 'detail' => 'xepan\\base\\RichText'], 'config_key' => 'CHALLAN_LAYOUT', 'application' => 'commerce']); $challan_m->tryLoadAny(); $chalan_config = $challan_m['master']; // $chalan_config = $this->app->epan->config->getConfig('CHALLANLAYOUT'); $chalan_layout = $this->add('GiTemplate'); $chalan_layout->loadTemplateFromString($chalan_config); // $detail_config = $this->app->epan->config->getConfig('CHALLANDETAILLAYOUT'); $detail_config = $challan_m['detail']; $detail_layout = $this->add('GiTemplate'); $detail_layout->loadTemplateFromString($detail_config); $company_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['company_name' => "Line", 'mobile_no' => "Line", 'company_address' => "Line", 'company_pin_code' => "Line"], 'config_key' => 'COMPANY_AND_OWNER_INFORMATION', 'application' => 'communication']); $company_m->tryLoadAny(); $address = $company_m['company_address'] . " (Pincode : " . $company_m['company_pin_code'] . ")"; $new = $this->add('xepan\\commerce\\Model_Store_Delivered'); $new->load($this->id); $view = $this->app->add('View', null, null, $chalan_layout); $view->setModel($new); $tr_row = $this->add('xepan\\commerce\\Model_Store_TransactionRow'); $tr_row->addExpression('from_warehousename')->set($tr_row->refSQL('store_transaction_id')->fieldQuery('from_warehouse')); $tr_row->addCondition('store_transaction_id', $new->id); $details_view = $view->add('CompleteLister', null, 'item_info', $detail_layout); $details_view->setModel($tr_row); $details_view->addHook('formatRow', function ($m) { $m->current_row_html['s_no'] = $this->s_no; $this->s_no++; $m->current_row_html['from_warehouse_name'] = $m['from_warehousename']; }); $tr_row->tryLoadAny(); $view->template->trySetHTML('related_sale_order', $tr_row['related_sale_order']); $view->template->trySetHTML('date', $this->app->today); $view->template->trySetHTML('company_name', $company_m['company_name']); $view->template->trySetHTML('company_contact', $company_m['mobile_no']); $view->template->trySetHTML('company_address', $address); // if($bar_code = $this->getBarCode()){ // $barcodeobj = new \TCPDFBarcode($bar_code, 'C128'); // // $barcode_html = $barcodeobj->getBarcodePNG(2, 30, 'black'); // $barcode_html = $barcodeobj->getBarcodePngData(1, 20, array(0,128,0)); // $info_layout->trySetHtml('dispatch_barcode','<img src="data:image/png;base64, '.base64_encode($barcode_html).'"/>'); // } // $view = $this->add('View')->set("Challan View TODO"); $html = $view->getHTML(); // output the HTML content $pdf->writeHTML($html, false, false, true, false, ''); // set default form properties $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128))); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document switch ($action) { case 'return': return $pdf->Output(null, 'S'); break; case 'dump': return $pdf->Output(null, 'I'); exit; break; } }
public function send_t() { // require_once 'dompdf/autoload.inc.php'; $idOrder = $_GET['id_order']; $toEmail = $_GET['email']; $idOrder = 339; $toEmail = "*****@*****.**"; $order = new MasterOrderModel(); $order->getByID($idOrder); $resto = new MasterRestaurantModel(); $resto->getByID($order->id_restaurant); $od = new OrderDetailModel(); $d = new MasterDishModel(); // $dompdf = new Dompdf\Dompdf(); global $db; $q = "SELECT {$od->table_name}.id_dish, {$d->table_name}.name, SUM(quantity) AS sum_qty, {$d->table_name}.price,\nSUM({$od->table_name}.price) AS sum_price, status_progress FROM `{$od->table_name}`\nRIGHT JOIN {$d->table_name} ON {$od->table_name}.id_dish = {$d->table_name}.id_dish WHERE id_order='{$idOrder}' GROUP BY id_dish"; $arrDetails = $db->query($q, 2); $css_boot = _BPATH . "themes/tbstheme_ori/css/bootstrap.min.css"; $image1 = _BPATH . _PHOTOURL . $resto->image_logo; if ($image1 == "") { $image1 = _BPATH . _PHOTOURL . "noimage.jpg"; } $html = "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $head = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Notification email</title>"; $head = $head . "<link href=" . $css_boot . " rel=\"stylesheet\">"; $head = $head . "<link href=\"https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700&subset=latin,latin-ext\" rel=\"stylesheet\" type=\"text/css\">"; $head = $head . "</head>"; $body = "<body bgcolor=\"#8d8e90\" style=\"font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;font-size: 14px;line-height: 1.42857143;color: #333;background-color: #fff;margin: 0;box-sizing: border-box;\">"; $body = $body . "<div class=\"container\" style=\" margin: 10px; font-family: 'Roboto Condensed', sans-serif;\">"; $body = $body . "<div style=\" box-shadow: inset 0 1px 1px; margin-left: 25%;float: left;position: relative; min-height: 20px; padding: 19px; margin-bottom: 20px; background-color: #f5f5f5; border: 1px solid #e3e3e3; border-radius: 4px; padding-left: 30px; padding-right: 30px\">"; //class="well col-xs-10 col-sm-10 col-md-6 col-xs-offset-1 col-sm-offset-1 col-md-offset-3" // $body = $body . "<div class=\"well col-xs-10 col-sm-10 col-md-6 col-xs-offset-1 col-sm-offset-1 col-md-offset-3\">"; $body = $body . "<div style=\"margin-right: -15px; margin-left: -15px;\">"; $body = $body . "<div style=\"text-align: center;\">"; $body = $body . "<h2>"; if ($order->status_progress < 4) { $body = $body . "Order Not Done"; } elseif ($order->status_progress == 9) { $body = $body . "Order Voided"; } $body = $body . "</h2> </div> </div> "; if ($order->status_progress >= 4 && $order->status_progress < 9) { $body = $body . "<div style=\"margin-right: -15px; margin-left: -15px;box-sizing: border-box;display: block;\">"; $body = $body . "<div style=\"float: left; position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px;box-sizing: border-box;display: block;\">"; //$body = $body . "<img class=\"img-responsive center-block\" src= $image1 alt= $resto->name width=\"180\" height=\"180\">"; $body = $body . "<img style=\" display: block; margin-right: auto; margin-left: auto;max-width: 100%;height: auto; vertical-align: middle;border: 0;\" src= {$image1} alt= {$resto->name} width=\"180\" height=\"180\">"; $body = $body . "</div>"; $body = $body . "<div style=\"width: 50%;float: left; position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px;text-align: left;box-sizing: border-box;display: block;\">"; $body = $body . "<address style=\"margin-bottom: 20px; font-style: normal; line-height: 1.42857143;\">"; $body = $body . "<strong style=\"font-size: 28px\">"; $body = $body . $resto->name; $body = $body . "</strong>"; $body = $body . " <br>"; $body = $body . $resto->address; $body = $body . " <br>"; $body = $body . $resto->district . " - " . $resto->city; $body = $body . " <br>"; $body = $body . "Phone : " . $resto->phone_no; $body = $body . "</address>"; $body = $body . " </div> </div>"; $body = $body . "<br>"; $body = $body . "<div style=\"margin-right: -15px;margin-left: -15px;box-sizing: border-box;display: block;\">"; $body = $body . " <div style=\"width: 100%;float: left;position: relative; min-height: 1px;padding-right: 15px;padding-left: 15px;text-align: left;box-sizing: border-box;display: block;\">"; $body = $body . "Receipt #: " . $idOrder; $body = $body . "<br>"; $body = $body . " Server : "; if ($order->type_order == "1" || $order->type_order == "3") { $body = $body . "Apps Order"; } else { $body = $body . $order->server_name; } $body = $body . "<br>"; $body = $body . " Time Order : " . date("d M, Y H:m", strtotime($order->datetime_order)); $body = $body . "<br>"; $body = $body . " Payment Method : " . Generic::selectPaymentMethod($order->status_payment); $body = $body . "<br>"; if ($order->type_order == "1" || $order->type_order == "3") { $body = $body . "Apps Order"; } else { $body = $body . "Manual Order"; } $body = $body . "<br>"; $body = $body . "</div></div>"; $body = $body . "<div style=\"margin-right: -15px;margin-left: -15px;box-sizing: border-box;display: block;\">"; $body = $body . "<table style=\" width: 100%;max-width: 100%; margin-bottom: 20px;background-color: transparent;border-spacing: 0; border-collapse: collapse;box-sizing: border-box;\">"; $body = $body . "<thead style=\" box-sizing: border-box; \"> <tr><th>Item(s)</th><th style=\" text-align: center; border-top: 0; vertical-align: bottom; border-bottom: 2px solid #ddd;padding: 8px;line-height: 1.42857143;box-sizing: border-box;\">#</th><th style=\"border-top: 0;vertical-align: bottom; border-bottom: 2px solid #ddd;padding: 8px; line-height: 1.42857143;text-align: right; box-sizing: border-box;\">Price</th> <th style=\"border-top: 0;vertical-align: bottom; border-bottom: 2px solid #ddd;padding: 8px; line-height: 1.42857143;text-align: right;box-sizing: border-box;\">Total</th>"; $body = $body . "</tr></thead> <tbody>"; foreach ($arrDetails as $details) { $void = ""; if ($details->status_progress == "9") { $void = "<strong> Voided </strong>"; $details->price = 0; $details->sum_price = 0; } $body = $body . " <tr>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top; border-top: 1px solid #ddd;position: static;display: table-cell;float: none;width: 50%; min-height: 1px;box-sizing: border-box;\">"; $body = $body . $details->name . $void; $body = $body . " </h4></td>"; $body = $body . "<td style = \"text-align: center;padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd;position: static;display: table-cell;float: none;width: 8.33333333%;min-height: 1px; box-sizing: border-box; text-align: center\">"; $body = $body . $details->sum_qty; $body = $body . "</td>"; $body = $body . " <td style=\"\tpadding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd;position: static;display: table-cell;float: none;width: 16.66666667%;min-height: 1px;text-align: right;box-sizing: border-box;\">"; $body = $body . Generic::formatRupiah($details->price); $body = $body . "<td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd;position: static;display: table-cell;float: none;width: 25%;min-height: 1px;box-sizing: border-box;\">"; $body = $body . Generic::formatRupiah($details->sum_price); $body = $body . "</td></tr>"; } $body = $body . "<tr>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\" colspan=\"3\">"; $body = $body . " <p><strong>Total : </strong> </p></td>"; $body = $body . "<td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\" <p><strong>"; $body = $body . Generic::formatRupiah($order->total_cost); $body = $body . "</strong></p></td></tr>"; $body = $body . "<tr>"; $body = $body . "<td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\" colspan=\"3\">"; if ($order->disc_resto != "0" || $order->disc_resto != "") { $body = $body . "<p><strong>Disc Resto : </strong></p>"; } if ($order->disc_bank != "0" || $order->disc_bank != "") { $body = $body . "<p><strong>Disc Credit Card : </strong></p>"; } if ($order->disc_mr != "0" || $order->disc_mr != "") { $body = $body . "<p><strong>Disc MR : </strong></p>"; } $body = $body . " </td>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\">"; if ($order->disc_resto != "0" || $order->disc_resto != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->disc_resto) . "</strong></p>"; } if ($order->disc_bank != "0" || $order->disc_bank != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->disc_bank) . "</strong></p>"; } if ($order->disc_mr != "0" || $order->disc_mr != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->disc_mr) . "</strong></p>"; } $body = $body . " </td></tr>"; $body = $body . "<tr>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\" colspan=\"3\">"; if ($order->tax_pb1 != "0" || $order->tax_pb1 != "") { $body = $body . "<p><strong>Tax PB1 : </strong></p>"; } if ($order->service_charge != "0" || $order->service_charge != "") { $body = $body . "<p><strong> Service Charge : </strong></p>"; } if ($order->other_charge != "0" || $order->other_charge != "") { $body = $body . "<p><strong>Other Charge : </strong></p>"; } $body = $body . "</td>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\">"; if ($order->tax_pb1 != "0" || $order->tax_pb1 != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } if ($order->service_charge != "0" || $order->service_charge != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } if ($order->other_charge != "0" || $order->other_charge != "") { $body = $body . "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } $body = $body . "</td> </tr>"; $body = $body . " <tr>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\" colspan=\"3\">"; $body = $body . " <h5><strong>Grand Total : </strong></h5></td>"; $body = $body . " <td style=\"padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd; text-align: right;box-sizing: border-box;\">"; $body = $body . " <h5><strong>"; $body = $body . Generic::formatRupiah($order->grand_total); $body = $body . " </strong></h5>"; $body = $body . " </td> </tr>"; $body = $body . "</tbody></table></div>"; // $body = $body . " <div>"; $body = $body . " <h1 style=\"text-align:center;\">"; $body = $body . " Thank you for your order. </h1> </div>"; } $html = $html . $head . $body; $html = $html . "</body> " . "</html>"; echo $html; // $a = new TCPDF($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa) $pdf = new TCPDF("portrait", PDF_UNIT, "a4", true, 'UTF-8', true); // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); // $pdf->writeHTML($html); $pdf->writeHTML($html, true, true, true, false, ''); // reset pointer to the last page $pdf->lastPage(); // ob_clean(); $t = time(); $pdf->Output("uploads/file_" . $t . ".pdf", "F"); //Close and output PDF document // die; $mail = new Leapmail(); $mail->sendEmailHTML($toEmail, "Menu Revolution, Receipt", $html); die; ?> <link href='https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700&subset=latin,latin-ext' rel = 'stylesheet' type = 'text/css'> <div class = "container" style = "margin: 10px; font-family: 'Roboto Condensed', sans-serif;"> <div class = "well col-xs-10 col-sm-10 col-md-6 col-xs-offset-1 col-sm-offset-1 col-md-offset-3" style = "padding-left: 30px; padding-right: 30px"> <div class = "row"> <div class = "text-center"> <h2> <?php if ($order->status_progress < 4) { echo "Order Not Done"; } elseif ($order->status_progress == 9) { echo "Order Voided"; } ?> </h2> </div> </div> <?php if ($order->status_progress >= 4 && $order->status_progress < 9) { ?> <div class="row"> <div class="col-xs-12 col-sm-6 col-md-6"> <img class="img-responsive center-block" src="<?php echo _BPATH . _PHOTOURL . $resto->image_logo; ?> " alt="<?php echo $resto->name; ?> " width="180" height="180"> </div> <div class="col-xs-12 col-sm-6 col-md-6 text-left"> <address> <strong style="font-size: 28px"><?php echo $resto->name; ?> </strong> <br> <?php echo $resto->address; ?> <br> <?php echo $resto->district . " - " . $resto->city; ?> <br> Phone : <?php echo $resto->phone_no; ?> </address> </div> </div> <br> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 text-left"> <br>Receipt #: <?php echo $idOrder; ?> <br>Server : <?php echo $order->type_order == "1" || $order->type_order == "3" ? "Apps Order" : $order->server_name; ?> <br> Time Order : <?php echo date("d M, Y H:m", strtotime($order->datetime_order)); ?> <br> Payment Method : <?php echo Generic::selectPaymentMethod($order->status_payment); ?> <br> Order Method : <?php echo $order->type_order == "1" || $order->type_order == "3" ? "Apps Order" : "Manual Order"; ?> <br> </div> </div> <div class="row"> <table class="table table-hover"> <thead> <tr> <th>Item(s)</th> <th style="text-align: center">#</th> <th class="text-right">Price</th> <th class="text-right">Total</th> </tr> </thead> <tbody> <?php foreach ($arrDetails as $details) { $void = ""; if ($details->status_progress == "9") { $void = "<strong> Voided </strong>"; $details->price = 0; $details->sum_price = 0; } ?> <tr> <td class="col-md-6"><?php echo $details->name; echo $void; ?> </h4></td> <td class="col-md-1" style="text-align: center"> <?php echo $details->sum_qty; ?> </td> <td class="col-md-2 text-right"><?php echo Generic::formatRupiah($details->price); ?> </td> <td class="col-md-3 text-right"><?php echo Generic::formatRupiah($details->sum_price); ?> </td> </tr> <?php } ?> <tr> <td class="text-right" colspan="3"> <p> <strong>Total : </strong> </p> </td> <td class="text-right"> <p> <strong><?php echo Generic::formatRupiah($order->total_cost); ?> </strong> </p> </td> </tr> <tr> <td class="text-right" colspan="3"> <?php if ($order->disc_resto != "0" || $order->disc_resto != "") { echo "<p><strong>Disc Resto : </strong></p>"; } if ($order->disc_bank != "0" || $order->disc_bank != "") { echo "<p><strong>Disc Credit Card : </strong></p>"; } if ($order->disc_mr != "0" || $order->disc_mr != "") { echo "<p><strong>Disc MR : </strong></p>"; } ?> </td> <td class="text-right"> <?php if ($order->disc_resto != "0" || $order->disc_resto != "") { echo "<p><strong>" . Generic::formatRupiah($order->disc_resto) . "</strong></p>"; } if ($order->disc_bank != "0" || $order->disc_bank != "") { echo "<p><strong>" . Generic::formatRupiah($order->disc_bank) . "</strong></p>"; } if ($order->disc_mr != "0" || $order->disc_mr != "") { echo "<p><strong>" . Generic::formatRupiah($order->disc_mr) . "</strong></p>"; } ?> </td> </tr> <tr> <td class="text-right" colspan="3"> <?php if ($order->tax_pb1 != "0" || $order->tax_pb1 != "") { echo "<p><strong>Tax PB1 : </strong></p>"; } if ($order->service_charge != "0" || $order->service_charge != "") { echo "<p><strong>Service Charge : </strong></p>"; } if ($order->other_charge != "0" || $order->other_charge != "") { echo "<p><strong>Other Charge : </strong></p>"; } ?> </td> <td class="text-right"> <?php if ($order->tax_pb1 != "0" || $order->tax_pb1 != "") { echo "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } if ($order->service_charge != "0" || $order->service_charge != "") { echo "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } if ($order->other_charge != "0" || $order->other_charge != "") { echo "<p><strong>" . Generic::formatRupiah($order->tax_pb1) . "</strong></p>"; } ?> </td> </tr> <tr> <td class="text-right" colspan="3"> <h5><strong>Grand Total : </strong></h5></td> <td class="text-right"> <h5><strong><?php echo Generic::formatRupiah($order->grand_total); ?> </strong></h5> </td> </tr> </tbody> </table> <div> <h1 style="text-align:center;"> Thank you for your order. </h1> </div> </div> <?php } ?> </div> </div> <?php }
/** * Print an article as PDF and stream it to the browser */ public function generatePdf() { $this->headline = $this->title; $this->printable = false; // Generate article $strArticle = $this->replaceInsertTags($this->generate(), false); $strArticle = html_entity_decode($strArticle, ENT_QUOTES, \Config::get('characterSet')); $strArticle = $this->convertRelativeUrls($strArticle, '', true); // Remove form elements and JavaScript links $arrSearch = array('@<form.*</form>@Us', '@<a [^>]*href="[^"]*javascript:[^>]+>.*</a>@Us'); $strArticle = preg_replace($arrSearch, '', $strArticle); // HOOK: allow individual PDF routines if (isset($GLOBALS['TL_HOOKS']['printArticleAsPdf']) && is_array($GLOBALS['TL_HOOKS']['printArticleAsPdf'])) { foreach ($GLOBALS['TL_HOOKS']['printArticleAsPdf'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($strArticle, $this); } } // URL decode image paths (see #6411) $strArticle = preg_replace_callback('@(src="[^"]+")@', function ($arg) { return rawurldecode($arg[0]); }, $strArticle); // Handle line breaks in preformatted text $strArticle = preg_replace_callback('@(<pre.*</pre>)@Us', function ($arg) { return str_replace("\n", '<br>', $arg[0]); }, $strArticle); // Default PDF export using TCPDF $arrSearch = array('@<span style="text-decoration: ?underline;?">(.*)</span>@Us', '@(<img[^>]+>)@', '@(<div[^>]+block[^>]+>)@', '@[\\n\\r\\t]+@', '@<br( /)?><div class="mod_article@', '@href="([^"]+)(pdf=[0-9]*(&|&)?)([^"]*)"@'); $arrReplace = array('<u>$1</u>', '<br>$1', '<br>$1', ' ', '<div class="mod_article', 'href="$1$4"'); $strArticle = preg_replace($arrSearch, $arrReplace, $strArticle); // TCPDF configuration $l['a_meta_dir'] = 'ltr'; $l['a_meta_charset'] = \Config::get('characterSet'); $l['a_meta_language'] = substr($GLOBALS['TL_LANGUAGE'], 0, 2); $l['w_page'] = 'page'; // Include library require_once __DIR__ . '/../config/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($this->title); $pdf->SetSubject($this->title); $pdf->SetKeywords($this->keywords); // 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($strArticle, true, 0, true, 0); // Close and output PDF document $pdf->lastPage(); $pdf->Output(\StringUtil::standardize(ampersand($this->title, false)) . '.pdf', 'D'); // Stop script execution exit; }
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 039'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 039', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // add a page $pdf->AddPage(); // set font $pdf->SetFont('helvetica', 'B', 20); $pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0); // create some HTML content $html = '<span style="text-align:justify;">a <u>abc</u> abcdefghijkl (abcdef) abcdefg <b>abcdefghi</b> a ((abc)) abcd <img src="tests/images/logo_example.png" border="0" height="41" width="41" /> <img src="tests/images/tcpdf_box.svg" alt="test alt attribute" width="80" height="60" border="0" /> abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a <u>abc</u> abcd abcdef abcdefg <b>abcdefghi</b> a abc \\(abcd\\) abcdef abcdefg <b>abcdefghi</b> a abc \\\\(abcd\\\\) abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg abcdefghi a abc abcd <a href="http://tcpdf.org">abcdef abcdefg</a> start a abc before <span style="background-color:yellow">yellow color</span> after a abc abcd abcdef abcdefg abcdefghi a abc abcd end abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi<br />abcd abcdef abcdefg abcdefghi<br />abcd abcde abcdef</span>'; // set core font $pdf->SetFont('helvetica', '', 10); // output the HTML content $pdf->writeHTML($html, true, 0, true, true); $pdf->Ln(); // set UTF-8 Unicode font $pdf->SetFont('dejavusans', '', 10); // output the HTML content $pdf->writeHTML($html, true, 0, true, true); // reset pointer to the last page $pdf->lastPage(); $this->comparePdfs($pdf); }
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'); }