/** * Creates a PDF document and sends this pricelist to the client * * Unfortunately, ezpdf does not return anything after printing the * document, so there's no way to tell whether it has succeeded. * Thus, you should not rely on the return value, except when it is * false -- in that case, loading of some data failed. * @return boolean False on failure, true on supposed success */ function send_as_pdf() { global $objInit, $_ARRAYLANG; if (!$this->load()) { return \Message::error($_ARRAYLANG['TXT_SHOP_PRICELIST_ERROR_LOADING']); } $objPdf = new \Cezpdf('A4'); $objPdf->setEncryption('', '', array('print')); $objPdf->selectFont(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseLibraryPath() . '/ezpdf/fonts/' . $this->font); $objPdf->ezSetMargins(0, 0, 0, 0); // Reset margins $objPdf->setLineStyle(0.5); $marginTop = 30; $biggerCountTop = $biggerCountBottom = 0; $arrHeaderLeft = $arrHeaderRight = $arrFooterLeft = $arrFooterRight = array(); if ($this->header) { // header should be shown $arrHeaderLeft = explode("\n", $this->header_left); $arrHeaderRight = explode("\n", $this->header_right); $countLeft = count($arrHeaderLeft); $countRight = count($arrHeaderRight); $biggerCountTop = $countLeft > $countRight ? $countLeft : $countRight; $marginTop = $biggerCountTop * 14 + 36; } // Bottom margin $marginBottom = 20; $arrFooterRight = array(); if ($this->footer) { // footer should be shown // Old, obsolete: $this->footer_left = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left); $this->footer_right = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right); // New: $this->footer_left = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left); $this->footer_right = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right); $arrFooterLeft = explode("\n", $this->footer_left); $arrFooterRight = explode("\n", $this->footer_right); $countLeft = count($arrFooterLeft); $countRight = count($arrFooterRight); $biggerCountBottom = $countLeft > $countRight ? $countLeft : $countRight; $marginBottom = $biggerCountBottom * 20 + 20; } // Borders if ($this->border) { $linesForAllPages = $objPdf->openObject(); $objPdf->saveState(); $objPdf->setStrokeColor(0, 0, 0, 1); $objPdf->rectangle(10, 10, 575.28, 821.89); $objPdf->restoreState(); $objPdf->closeObject(); $objPdf->addObject($linesForAllPages, 'all'); } // Header $headerArray = array(); $startpointY = 0; if ($this->header) { $objPdf->ezSetY(830); $headerForAllPages = $objPdf->openObject(); $objPdf->saveState(); for ($i = 0; $i < $biggerCountTop; ++$i) { $headerArray[$i] = array('left' => isset($arrHeaderLeft[$i]) ? $arrHeaderLeft[$i] : '', 'right' => isset($arrHeaderRight[$i]) ? $arrHeaderRight[$i] : ''); } $tempY = $objPdf->ezTable($headerArray, '', '', array('showHeadings' => 0, 'fontSize' => $this->font_size_header, 'shaded' => 0, 'width' => 540, 'showLines' => 0, 'xPos' => 'center', 'xOrientation' => 'center', 'cols' => array('right' => array('justification' => 'right')))); $tempY -= 5; if ($this->border) { $objPdf->setStrokeColor(0, 0, 0); $objPdf->line(10, $tempY, 585.28, $tempY); } $startpointY = $tempY - 5; $objPdf->restoreState(); $objPdf->closeObject(); $objPdf->addObject($headerForAllPages, 'all'); } // Footer $pageNumbersX = $pageNumbersY = $pageNumbersFont = 0; if ($this->footer) { $footerForAllPages = $objPdf->openObject(); $objPdf->saveState(); $tempY = $marginBottom - 5; if ($this->border) { $objPdf->setStrokeColor(0, 0, 0); $objPdf->line(10, $tempY, 585.28, $tempY); } // length of the longest word $longestWord = 0; foreach ($arrFooterRight as $line) { if ($longestWord < strlen($line)) { $longestWord = strlen($line); } } for ($i = $biggerCountBottom - 1; $i >= 0; --$i) { if (empty($arrFooterLeft[$i])) { $arrFooterLeft[$i] = ''; } if (empty($arrFooterRight[$i])) { $arrFooterRight[$i] = ''; } if ($arrFooterLeft[$i] == '<--PAGENUMBER-->' || $arrFooterLeft[$i] == '[PAGENUMBER]') { $pageNumbersX = 65; $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer; $pageNumbersFont = $this->font_size_list; } else { $objPdf->addText(25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterLeft[$i]); } if ($arrFooterRight[$i] == '<--PAGENUMBER-->' || $arrFooterRight[$i] == '[PAGENUMBER]') { $pageNumbersX = 595.28 - 25; $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer; $pageNumbersFont = $this->font_size_list; } else { // Properly align right $width = $objPdf->getTextWidth($this->font_size_footer, $arrFooterRight[$i]); $objPdf->addText(595.28 - $width - 25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterRight[$i]); } } $objPdf->restoreState(); $objPdf->closeObject(); $objPdf->addObject($footerForAllPages, 'all'); } // Page numbers if (isset($pageNumbersX)) { $objPdf->ezStartPageNumbers($pageNumbersX, $pageNumbersY, $pageNumbersFont, '', $_ARRAYLANG['TXT_SHOP_PRICELIST_FORMAT_PAGENUMBER'], 1); } // Margins $objPdf->ezSetMargins($marginTop, $marginBottom, 30, 30); // Product table if (isset($startpointY)) { $objPdf->ezSetY($startpointY); } $objInit->backendLangId = $this->lang_id; $_ARRAYLANG = $objInit->loadLanguageData('Shop'); Currency::setActiveCurrencyId($this->currency_id); $currency_symbol = Currency::getActiveCurrencySymbol(); $category_ids = $this->category_ids(); if ($category_ids == '*') { $category_ids = null; } $count = 1000; // Be sensible! // Pattern is "%" because all-empty parameters will result in an // empty array! $arrProduct = Products::getByShopParams($count, 0, null, $category_ids, null, '%', null, null, '`category_id` ASC, `name` ASC'); $arrCategoryName = ShopCategories::getNameArray(); $arrOutput = array(); foreach ($arrProduct as $product_id => $objProduct) { $categoryIds = explode(',', $objProduct->category_id()); $arrCategoryNames = array(); foreach ($categoryIds as $categoryId) { $arrCategoryNames[] = $arrCategoryName[$categoryId]; } //$objProduct = new Product(); $arrOutput[$product_id] = array('product_name' => self::decode($objProduct->name()), 'category_name' => self::decode(implode(', ', $arrCategoryNames)), 'product_code' => self::decode($objProduct->code()), 'product_id' => self::decode($objProduct->id()), 'price' => ($objProduct->discount_active() ? "S " . Currency::formatPrice($objProduct->discountprice()) : Currency::formatPrice($objProduct->price())) . ' ' . $currency_symbol); } $objPdf->ezTable($arrOutput, array('product_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_NAME']) . '</b>', 'category_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_CATEGORY_NAME']) . '</b>', 'product_code' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_CODE']) . '</b>', 'product_id' => '<b>' . self::decode($_ARRAYLANG['TXT_ID']) . '</b>', 'price' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRICE']) . '</b>'), '', array('showHeadings' => 1, 'fontSize' => $this->font_size_list, 'width' => 530, 'innerLineThickness' => 0.5, 'outerLineThickness' => 0.5, 'shaded' => 2, 'shadeCol' => array(hexdec(substr($this->row_color_1, 0, 2)) / 255, hexdec(substr($this->row_color_1, 2, 2)) / 255, hexdec(substr($this->row_color_1, 4, 2)) / 255), 'shadeCol2' => array(hexdec(substr($this->row_color_2, 0, 2)) / 255, hexdec(substr($this->row_color_2, 2, 2)) / 255, hexdec(substr($this->row_color_2, 4, 2)) / 255), 'cols' => array('product_name' => array('width' => 255), 'category_name' => array('width' => 130), 'product_code' => array('width' => 50), 'product_id' => array('width' => 40, 'justification' => 'right'), 'price' => array('width' => 55, 'justification' => 'right')))); $objPdf->ezStream(); // Never reached return true; }
} $pdf->setStrokeColor(0, 0, 0); $pdf->setLineStyle(1); $pdf->roundedRectangle(10, 5, 170, 90, 10, $f = 0); $pos = $y - 2 * GENERAL_LEADING; // $address_array=explode('<br>', str_replace("\r\n", "<br>", STORE_NAME_ADDRESS)); foreach ($store_address_array as $key => $value) { // echo $value.'<br>' ; $pdf->addText(LEFT_MARGIN, $pos -= SMALL_LEADING, SENDER_SMALL_FONT_SIZE, $value); } $pdf->addText(LEFT_MARGIN, $pos -= LABEL_LINE_SPACING, ORDERIDFONTSIZE, 'Order ' . $orders['orders_id']); $pos = $y; if ($billing == true) { $address_array = explode('<br>', tep_address_format($order->delivery['format_id'], $order->billing, 1, '', '<br>')); } else { $address_array = explode('<br>', tep_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>')); } if (SHIP_FROM_COUNTRY == $address_array[count($address_array) - 1]) { $address_array[count($address_array) - 1] = ''; } $print_address_array = array(); foreach ($address_array as $key => $value) { if (!is_null($value) && $value !== "") { $fontsize = LABEL_FONT_SIZE; while ($pdf->getTextWidth($fontsize, $value) > 160) { $fontsize--; } $pdf->addText($x, $pos -= LABEL_LINE_SPACING, $fontsize, '<b>' . $value . '</b>'); } } }
$pdf->ezSetCmMargins(2, 1.5, 1.4, 1.4); //(top, bottom, left, right) /* * Define page header to be displayed on top of each page */ $pdf->saveState(); if ($skip_page) { $pdf->ezNewPage(); } $skip_page++; $page_header = $pdf->openObject(); $pdf->selectFont("{$font_dir}/Helvetica-Bold.afm"); $ypos = $pdf->ez['pageHeight'] - (30 + $pdf->getFontHeight(12)); $doc_title = strEzPdf($projects[$project_id]['project_name'], UI_OUTPUT_RAW); $pwidth = $pdf->ez['pageWidth']; $xpos = round(($pwidth - $pdf->getTextWidth(12, $doc_title)) / 2, 2); $pdf->addText($xpos, $ypos, 12, $doc_title); $pdf->selectFont("{$font_dir}/Helvetica.afm"); $date = new w2p_Utilities_Date(); $xpos = round($pwidth - $pdf->getTextWidth(10, $date->format($df)) - $pdf->ez['rightMargin'], 2); $doc_date = strEzPdf($date->format($df)); $pdf->addText($xpos, $ypos, 10, $doc_date); $pdf->closeObject($page_header); $pdf->addObject($page_header, 'all'); $gpdfkey = W2P_BASE_DIR . '/modules/tasks/images/ganttpdf_key.png'; $gpdfkeyNM = W2P_BASE_DIR . '/modules/tasks/images/ganttpdf_keyNM.png'; $pdf->ezStartPageNumbers(802, 30, 10, 'left', 'Page {PAGENUM} of {TOTALPAGENUM}'); for ($i = 0; $i < count($ganttfile); $i++) { $gf = $ganttfile[$i]; $pdf->ezColumnsStart(array('num' => 1, 'gap' => 0)); $pdf->ezImage($gf, 0, 765, 'width', 'left');
$offsetRow = 2; foreach ($people as $person) { if ($pageCount > 0 && $offsetRow == 2) { $pdf->ezNewPage(); } for ($columnOffset = 0; $columnOffset <= 1; $columnOffset++) { $left_edge = $left_margin + $badge_width * $columnOffset + $margin; $right_edge = $left_edge + $badge_width - $margin * 2; $top_edge = $top_margin + ($offsetRow + 1) * $badge_height - $margin; $bottom_edge = $top_edge - $badge_height + $margin * 2; $center = $left_edge + ($badge_width - $margin - $base_height / 2) / 2; $logoY = $top_edge - $logo_height - $base_height * 1.5; $pdf->addPngFromFile($logo_file, $left_edge + $badge_width / 2 - $logo_width / 2 - 12, $logoY, $logo_width, $logo_height); $nameString = ucfirst($person["FIRSTNAME"]) . " " . ucfirst($person["LASTNAME"]); $nameSize = 32; while ($pdf->getTextWidth($nameSize, $nameString) > $badge_width - $margin * 4) { $nameSize -= 2; } $nameX = $center - $pdf->getTextWidth($nameSize, $nameString) / 2; $nameY = $logoY - $pdf->getFontHeight($nameSize) + 6; $pdf->addText($nameX, $nameY, $nameSize, $nameString); $institutionString = $person["INSTITUTION"]; $institutionSize = 18; // while ($pdf->getTextWidth($institutionSize, $institutionString) > 568) { // $institutionSize-=2; // } // new "guesstimated" cutoff width for resizing text while ($pdf->getTextWidth($institutionSize, $institutionString) > 300) { $institutionSize -= 2; } $institutionX = $center - $pdf->getTextWidth($institutionSize, $institutionString) / 2;