- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to generate pdf using magento defined pdf generation plugin in admin panel side.
Most of them suggest external libraries to generate pdf. Is there any way to generate pdf using magento module.
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can create your own pdf using below code,
Create one model file in your module and extends Abstractpdf.php file
<?php namespace Vendor\Modulename\Model\Pdf; use Magento\Sales\Model\Order\Pdf\AbstractPdf; class Custompage extends AbstractPdf { protected function _drawHeader(\Zend_Pdf_Page $page) { /* Add table head */ $this->_setFontRegular($page, 10); $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0)); //columns headers $lines[0][] = ['text' => __('column1'), 'feed' => 35]; $lines[0][] = ['text' => __('Column2'), 'feed' => 200, 'align' => 'right']; $lineBlock = ['lines' => $lines, 'height' => 10]; $this->drawLineBlocks($page, [$lineBlock], ['table_header' => true]); $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); } public function customPdf(){ $this->_beforeGetPdf(); $pdf = new \Zend_Pdf(); $this->_setPdf($pdf); $style = new \Zend_Pdf_Style(); $this->_setFontBold($style, 10); $this->_afterGetPdf(); return $pdf; } }
Using above way you can create your pdf customizer for your module. I have customized default invoice pdf file but dont try with custom pdf way.
So you can just check using above way.
You can also take reference from this post,
Basics of PDF customization in magento 2
Hope this will helpful to you.
if issue resolved Click Kudos/Accept as solutions.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can create your own pdf using below code,
Create one model file in your module and extends Abstractpdf.php file
<?php namespace Vendor\Modulename\Model\Pdf; use Magento\Sales\Model\Order\Pdf\AbstractPdf; class Custompage extends AbstractPdf { protected function _drawHeader(\Zend_Pdf_Page $page) { /* Add table head */ $this->_setFontRegular($page, 10); $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0)); //columns headers $lines[0][] = ['text' => __('column1'), 'feed' => 35]; $lines[0][] = ['text' => __('Column2'), 'feed' => 200, 'align' => 'right']; $lineBlock = ['lines' => $lines, 'height' => 10]; $this->drawLineBlocks($page, [$lineBlock], ['table_header' => true]); $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); } public function customPdf(){ $this->_beforeGetPdf(); $pdf = new \Zend_Pdf(); $this->_setPdf($pdf); $style = new \Zend_Pdf_Style(); $this->_setFontBold($style, 10); $this->_afterGetPdf(); return $pdf; } }
Using above way you can create your pdf customizer for your module. I have customized default invoice pdf file but dont try with custom pdf way.
So you can just check using above way.
You can also take reference from this post,
Basics of PDF customization in magento 2
Hope this will helpful to you.
if issue resolved Click Kudos/Accept as solutions.
Magento 2 Blogs/Tutorial