cancel
Showing results for 
Search instead for 
Did you mean: 

Pdf generation for own page

SOLVED

Pdf generation for own page

I created new module in admin side.

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.
Tags (1)
1 REPLY

Re: Pdf generation for own page

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.

If Issue Solved, Click Kudos/Accept As solutions.