Jump to content


Photo

how to change Pdf top margin size in yii framework

yii

  • Please log in to reply
1 reply to this topic

#1 esaisijo

esaisijo

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 29 November 2013 - 12:58 AM

Hi,

This is esai, I’m newbie in PHP .Now I'm learning yii framework..I want to decrease the top margin header in my pdf document ..From my side i  made changes in  tcpdf extension file...but it didn't take any effect in top margin size. How to change the pdf margin in yii framework .

 

is there any other way to set the top margin header size?

I want to change the margin height of only specific pdf document...


Edited by esaisijo, 29 November 2013 - 01:06 AM.


#2 Petermichael703

Petermichael703

    Member

  • Members
  • PipPip
  • 21 posts

Posted 09 December 2013 - 01:52 PM

It me know if it helps

 

 

  • mPDF - manual and examples
  • HTML2PDF - Wiki and examples
  • Download and extract extension to the directory protected/extensions/yii-pdf
  • Download and extract library (mPDF and/or HTML2PDF) to own directory in catalog protected/vendors or set new value for 'librarySourcePath' parameter in 'params' array
  • Array 'defaultParams' - this is an array of constructor's default params of selected library. If you want to change default params - you can set them in config file (like shown below). If you do so - you must keep the order of array items!
  • In your protected/config/main.php, add the following:
  • //...
    'components'=>array(
        //...
        'ePdf' => array(
            'class'         => 'ext.yii-pdf.EYiiPdf',
            'params'        => array(
                'mpdf'     => array(
                    'librarySourcePath' => 'application.vendors.mpdf.*',
                    'constants'         => array(
                        '_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
                    ),
                    'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
                    /*'defaultParams'     => array( // More info: http://mpdf1.com/manual/index.php?tid=184
                        'mode'              => '', //  This parameter specifies the mode of the new document.
                        'format'            => 'A4', // format A4, A5, ...
                        'default_font_size' => 0, // Sets the default document font size in points (pt)
                        'default_font'      => '', // Sets the default font-family for the new document.
                        'mgl'               => 15, // margin_left. Sets the page margins for the new document.
                        'mgr'               => 15, // margin_right
                        'mgt'               => 16, // margin_top
                        'mgb'               => 16, // margin_bottom
                        'mgh'               => 9, // margin_header
                        'mgf'               => 9, // margin_footer
                        'orientation'       => 'P', // landscape or portrait orientation
                    )*/
                ),
                'HTML2PDF' => array(
                    'librarySourcePath' => 'application.vendors.html2pdf.*',
                    'classFile'         => 'html2pdf.class.php', // For adding to Yii::$classMap
                    /*'defaultParams'     => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
                        'orientation' => 'P', // landscape or portrait orientation
                        'format'      => 'A4', // format A4, A5, ...
                        'language'    => 'en', // language: fr, en, it ...
                        'unicode'     => true, // TRUE means clustering the input text IS unicode (default = true)
                        'encoding'    => 'UTF-8', // charset encoding; Default is UTF-8
                        'marges'      => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
                    )*/
                )
            ),
        ),
        //...
    )
    //...
    Usage
    ...
        public function actionIndex()
        {
            # mPDF
            $mPDF1 = Yii::app()->ePdf->mpdf();
     
            # You can easily override default constructor's params
            $mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
     
            # render (full page)
            $mPDF1->WriteHTML($this->render('index', array(), true));
     
            # Load a stylesheet
            $stylesheet = file_get_contents(Yii::getPathOfAlias('webroot.css') . '/main.css');
            $mPDF1->WriteHTML($stylesheet, 1);
     
            # renderPartial (only 'view' of current controller)
            $mPDF1->WriteHTML($this->renderPartial('index', array(), true));
     
            # Renders image
            $mPDF1->WriteHTML(CHtml::image(Yii::getPathOfAlias('webroot.css') . '/bg.gif' ));
     
            # Outputs ready PDF
            $mPDF1->Output();
     
            ////////////////////////////////////////////////////////////////////////////////////
     
            # HTML2PDF has very similar syntax
            $html2pdf = Yii::app()->ePdf->HTML2PDF();
            $html2pdf->WriteHTML($this->renderPartial('index', array(), true));
            $html2pdf->Output();
     
            ////////////////////////////////////////////////////////////////////////////////////
     
            # Example from HTML2PDF wiki: Send PDF by email
            $content_PDF = $html2pdf->Output('', EYiiPdf::OUTPUT_TO_STRING);
            require_once(dirname(__FILE__).'/pjmail/pjmail.class.php');
            $mail = new PJmail();
            $mail->setAllFrom('webmaster@my_site.net', "My personal site");
            $mail->addrecipient('mail_user@my_site.net');
            $mail->addsubject("Example sending PDF");
            $mail->text = "This is an example of sending a PDF file";
            $mail->addbinattachement("my_document.pdf", $content_PDF);
            $res = $mail->sendmail();
        }...
    
    • Version 0.3.2 (2013-04-05)

      • func_get_args() is using through a variable now (for PHP < 5.3.0)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com