58 abstract public function getPdf();
141 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
147 $this->_paymentData = $paymentData;
148 $this->_localeDate = $localeDate;
150 $this->_scopeConfig = $scopeConfig;
153 $this->_pdfConfig = $pdfConfig;
154 $this->_pdfTotalFactory = $pdfTotalFactory;
155 $this->_pdfItemsFactory = $pdfItemsFactory;
157 parent::__construct(
$data);
176 $drawingString =
'"libiconv"' == ICONV_IMPL ? iconv(
187 for (
$i = 0;
$i < strlen($drawingString);
$i++) {
188 $characters[] = ord($drawingString[
$i++]) << 8 | ord($drawingString[
$i]);
190 $glyphs = $font->glyphNumbersForCharacters($characters);
191 $widths = $font->widthsForGlyphs($glyphs);
192 $stringWidth = array_sum($widths) / $font->getUnitsPerEm() * $fontSize;
210 return $x + $columnWidth - $width - $padding;
226 return $x + round(($columnWidth - $width) / 2);
239 $this->y = $this->y ? $this->y : 815;
240 $image = $this->_scopeConfig->getValue(
241 'sales/identity/logo',
242 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
246 $imagePath =
'/sales/store/logo/' .
$image;
247 if ($this->_mediaDirectory->isFile($imagePath)) {
255 $width =
$image->getPixelWidth();
256 $height =
$image->getPixelHeight();
259 $ratio = $width / $height;
260 if ($ratio > 1 && $width > $widthLimit) {
261 $width = $widthLimit;
262 $height = $width / $ratio;
263 }
elseif ($ratio < 1 && $height > $heightLimit) {
264 $height = $heightLimit;
265 $width = $height * $ratio;
266 }
elseif ($ratio == 1 && $height > $heightLimit) {
267 $height = $heightLimit;
268 $width = $widthLimit;
271 $y1 = $top - $height;
295 $page->setLineWidth(0);
296 $this->y = $this->y ? $this->y : 815;
300 $this->_scopeConfig->getValue(
301 'sales/identity/address',
302 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
309 foreach ($this->string->split(
$value, 45,
true,
true) as
$_value) {
320 $this->y = $this->y > $top ? $top :
$this->y;
332 foreach (explode(
'|',
$address) as $str) {
333 foreach ($this->string->split($str, 45,
true,
true) as $part) {
356 foreach ($this->string->split(
$value, 55,
true,
true) as
$_value) {
359 foreach (
$text as $part) {
388 $this->y = $this->y ? $this->y : 815;
393 $page->drawRectangle(25, $top, 570, $top - 55);
395 $this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
399 $page->drawText(
__(
'Order # ') .
$order->getRealOrderId(), 35, $top -= 30,
'UTF-8');
406 $this->_localeDate->formatDate(
407 $this->_localeDate->scopeDate(
412 \IntlDateFormatter::MEDIUM,
423 $page->setLineWidth(0.5);
424 $page->drawRectangle(25, $top, 275, $top - 25);
425 $page->drawRectangle(275, $top, 570, $top - 25);
433 $paymentInfo = $this->_paymentData->getInfoBlock(
$order->getPayment())->setIsSecureMode(
true)->toPdf();
437 if (strip_tags(trim(
$value)) ==
'') {
444 if (!
$order->getIsVirtual()) {
447 $this->addressRenderer->format(
$order->getShippingAddress(),
'pdf')
454 $page->drawText(
__(
'Sold to:'), 35, $top - 15,
'UTF-8');
456 if (!
$order->getIsVirtual()) {
457 $page->drawText(
__(
'Ship to:'), 285, $top - 15,
'UTF-8');
459 $page->drawText(
__(
'Payment Method:'), 285, $top - 15,
'UTF-8');
468 $page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
471 $this->y = $top - 40;
477 foreach ($this->string->split(
$value, 45,
true,
true) as
$_value) {
480 foreach (
$text as $part) {
481 $page->drawText(strip_tags(ltrim($part)), 35, $this->y,
'UTF-8');
489 if (!
$order->getIsVirtual()) {
490 $this->y = $addressesStartY;
494 foreach ($this->string->split(
$value, 45,
true,
true) as
$_value) {
497 foreach (
$text as $part) {
498 $page->drawText(strip_tags(ltrim($part)), 285, $this->y,
'UTF-8');
504 $addressesEndY = min($addressesEndY, $this->y);
505 $this->y = $addressesEndY;
508 $page->setLineWidth(0.5);
509 $page->drawRectangle(25, $this->y, 275, $this->y - 25);
510 $page->drawRectangle(275, $this->y, 570, $this->y - 25);
515 $page->drawText(
__(
'Payment Method'), 35, $this->y,
'UTF-8');
516 $page->drawText(
__(
'Shipping Method:'), 285, $this->y,
'UTF-8');
525 $yPayments = $this->y - 15;
527 $yPayments = $addressesStartY;
535 foreach ($this->string->split(
$value, 45,
true,
true) as
$_value) {
536 $page->drawText(strip_tags(trim(
$_value)), $paymentLeft, $yPayments,
'UTF-8');
542 if (
$order->getIsVirtual()) {
544 $yPayments = min($addressesEndY, $yPayments);
545 $page->drawLine(25, $top - 25, 25, $yPayments);
546 $page->drawLine(570, $top - 25, 570, $yPayments);
547 $page->drawLine(25, $yPayments, 570, $yPayments);
549 $this->y = $yPayments - 15;
556 $page->drawText(strip_tags(trim(
$_value)), 285, $this->y,
'UTF-8');
561 $totalShippingChargesText =
"(" 562 .
__(
'Total Shipping Charges')
567 $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin,
'UTF-8');
568 $yShipments -= $topMargin + 10;
576 $page->setLineWidth(0.5);
577 $page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
578 $page->drawLine(400, $yShipments, 400, $yShipments - 10);
584 $page->drawText(
__(
'Title'), 290, $yShipments - 7,
'UTF-8');
585 $page->drawText(
__(
'Number'), 410, $yShipments - 7,
'UTF-8');
591 $endOfTitle = strlen(
$track->getTitle()) > $maxTitleLen ?
'...' :
'';
592 $truncatedTitle = substr(
$track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
593 $page->drawText($truncatedTitle, 292, $yShipments,
'UTF-8');
594 $page->drawText(
$track->getNumber(), 410, $yShipments,
'UTF-8');
595 $yShipments -= $topMargin - 5;
598 $yShipments -= $topMargin - 5;
601 $currentY = min($yPayments, $yShipments);
604 $page->drawLine(25, $methodStartY, 25, $currentY);
606 $page->drawLine(25, $currentY, 570, $currentY);
608 $page->drawLine(570, $currentY, 570, $methodStartY);
611 $this->y = $currentY;
627 $docHeader = $this->getDocHeaderCoordinates();
628 $page->drawText(
$text, 35, $docHeader[1] - 15,
'UTF-8');
640 if (!isset($a[
'sort_order']) || !isset($b[
'sort_order'])) {
644 if ($a[
'sort_order'] == $b[
'sort_order']) {
648 return $a[
'sort_order'] > $b[
'sort_order'] ? 1 : -1;
658 $totals = $this->_pdfConfig->getTotals();
659 usort(
$totals, [$this,
'_sortTotalsList']);
661 foreach (
$totals as $totalInfo) {
662 $class = empty($totalInfo[
'model']) ? null : $totalInfo[
'model'];
663 $totalModel = $this->_pdfTotalFactory->create(
$class);
664 $totalModel->setData($totalInfo);
665 $totalModels[] = $totalModel;
682 $lineBlock = [
'lines' => [],
'height' => 15];
686 if ($total->canDisplay()) {
687 $total->setFontSize(10);
688 foreach ($total->getTotalsForDisplay() as $totalData) {
689 $lineBlock[
'lines'][] = [
691 'text' => $totalData[
'label'],
694 'font_size' => $totalData[
'font_size'],
698 'text' => $totalData[
'amount'],
701 'font_size' => $totalData[
'font_size'],
724 if (preg_match_all(
'/<li.*?>(.*?)<\/li>/i',
$description, $matches)) {
738 $this->inlineTranslation->suspend();
748 $this->inlineTranslation->resume();
762 if (isset(
$value[
'qty'])) {
763 $resultValue .= sprintf(
'%d',
$value[
'qty']) .
' x ';
766 $resultValue .=
$value[
'title'];
768 if (isset(
$value[
'price'])) {
769 $resultValue .=
" " .
$order->formatPrice(
$value[
'price']);
785 $rendererData = $this->_pdfConfig->getRenderersPerProduct(
$type);
786 foreach ($rendererData as $productType => $renderer) {
787 $this->_renderers[$productType] = [
'model' => $renderer,
'renderer' =>
null];
800 if (!isset($this->_renderers[
$type])) {
804 if (!isset($this->_renderers[
$type])) {
805 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We found an invalid renderer model.'));
808 if ($this->_renderers[
$type][
'renderer'] ===
null) {
809 $this->_renderers[
$type][
'renderer'] = $this->_pdfItemsFactory->get($this->_renderers[
$type][
'model']);
812 return $this->_renderers[
$type][
'renderer'];
841 $type =
$item->getOrderItem()->getProductType();
843 $renderer->setOrder(
$order);
844 $renderer->setItem(
$item);
845 $renderer->setPdf($this);
846 $renderer->setPage(
$page);
847 $renderer->setRenderedModel($this);
851 return $renderer->getPage();
864 $this->_rootDirectory->getAbsolutePath(
'lib/internal/GnuFreeFont/FreeSerif.ttf')
866 $object->setFont($font, $size);
880 $this->_rootDirectory->getAbsolutePath(
'lib/internal/GnuFreeFont/FreeSerifBold.ttf')
882 $object->setFont($font, $size);
896 $this->_rootDirectory->getAbsolutePath(
'lib/internal/GnuFreeFont/FreeSerifItalic.ttf')
898 $object->setFont($font, $size);
922 if (!$this->_pdf instanceof \
Zend_Pdf) {
923 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Please define the PDF object before using.'));
975 foreach ($draw as $itemsProp) {
976 if (!isset($itemsProp[
'lines']) || !is_array($itemsProp[
'lines'])) {
977 throw new \Magento\Framework\Exception\LocalizedException(
978 __(
'We don\'t recognize the draw line data. Please define the "lines" array.')
981 $lines = $itemsProp[
'lines'];
982 $height = isset($itemsProp[
'height']) ? $itemsProp[
'height'] : 10;
984 if (empty($itemsProp[
'shift'])) {
986 foreach ($lines as $line) {
988 foreach ($line as $column) {
989 $lineSpacing = !empty($column[
'height']) ? $column[
'height'] : $height;
990 if (!is_array($column[
'text'])) {
991 $column[
'text'] = [$column[
'text']];
994 foreach ($column[
'text'] as $part) {
995 $top += $lineSpacing;
998 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
1000 $shift += $maxHeight;
1002 $itemsProp[
'shift'] = $shift;
1005 if ($this->y - $itemsProp[
'shift'] < 15) {
1009 foreach ($lines as $line) {
1011 foreach ($line as $column) {
1012 $fontSize = empty($column[
'font_size']) ? 10 : $column[
'font_size'];
1013 if (!empty($column[
'font_file'])) {
1015 $page->setFont($font, $fontSize);
1017 $fontStyle = empty($column[
'font']) ?
'regular' : $column[
'font'];
1018 switch ($fontStyle) {
1031 if (!is_array($column[
'text'])) {
1032 $column[
'text'] = [$column[
'text']];
1035 $lineSpacing = !empty($column[
'height']) ? $column[
'height'] : $height;
1037 foreach ($column[
'text'] as $part) {
1038 if ($this->y - $lineSpacing < 15) {
1042 $feed = $column[
'feed'];
1043 $textAlign = empty($column[
'align']) ?
'left' : $column[
'align'];
1044 $width = empty($column[
'width']) ? 0 : $column[
'width'];
1045 switch ($textAlign) {
1048 $feed = $this->
getAlignRight($part, $feed, $width, $font, $fontSize);
1055 $feed = $this->
getAlignCenter($part, $feed, $width, $font, $fontSize);
1061 $page->drawText($part, $feed, $this->y - $top,
'UTF-8');
1062 $top += $lineSpacing;
1065 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
1067 $this->y -= $maxHeight;
insertTotals($page, $source)
_setFontBold($object, $size=7)
getAlignCenter($string, $x, $columnWidth, \Zend_Pdf_Resource_Font $font, $fontSize)
_drawItem(\Magento\Framework\DataObject $item, \Zend_Pdf_Page $page, \Magento\Sales\Model\Order $order)
insertAddress(&$page, $store=null)
const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID
elseif(isset( $params[ 'redirect_parent']))
_calcAddressHeight($address)
_parseItemDescription($item)
insertLogo(&$page, $store=null)
newPage(array $settings=[])
static fontWithPath($filePath, $embeddingOptions=0)
_formatOptionValue($value, $order)
$_option $_optionId $class
const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID
insertDocumentNumber(\Zend_Pdf_Page $page, $text)
drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSettings=[])
static imageWithPath($filePath)
__construct(\Magento\Payment\Helper\Data $paymentData, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, Config $pdfConfig, \Magento\Sales\Model\Order\Pdf\Total\Factory $pdfTotalFactory, \Magento\Sales\Model\Order\Pdf\ItemsFactory $pdfItemsFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Sales\Model\Order\Address\Renderer $addressRenderer, array $data=[])
widthForStringUsingFontSize($string, $font, $fontSize)
const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID
_setFontItalic($object, $size=7)
_setFontRegular($object, $size=7)
foreach($order->getItems() as $orderItem) $shipment
getAlignRight($string, $x, $columnWidth, \Zend_Pdf_Resource_Font $font, $fontSize, $padding=5)
insertOrder(&$page, $obj, $putOrderId=true)