【问题标题】:MPDF how can i delete the white space marginMPDF如何删除空白边距
【发布时间】:2014-09-27 03:34:58
【问题描述】:
$style='<style>@page *{
margin-top: 0cm;
margin-bottom: 0cm;
margin-left: 0cm;
margin-right: 0cm;
}</style>';

$html ='<img src="temppng/'.$_GET['memid'].'.png"  width="325.03937" height="204.094488"  `/>';   

include("MPDF54/mpdf.php");

$mpdf = new mPDF('utf-8', 'Letter', 0, '', 1, 1, 1, 1, 8, 8);
$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
`$mpdf->SetMargins(0);
$mpdf->WriteHTML('<pagebreak sheet-size="86mm  54mm" />');
$mpdf->WriteHTML($style);


$mpdf->WriteHTML($html);
$mpdf->WriteHTML('<tocentry content="150mm square" />')

$mpdf->DeletePages(1,1);
$mpdf->Output();

嗨,谁知道如何删除pdf的底部空白,这里是图像'http://tinypic.com/view.php?pic=xfdixj&s=8',我想删除底部空白,任何人都知道 怎么办?THX

【问题讨论】:

    标签: mpdf


    【解决方案1】:

    使用 0 边距或任何您想要的相应内容创建它

    $mpdf=new mPDF('utf-8', 'Letter', 0, '', 0, 0, 0, 0, 0, 0);
    
    
    
    
    class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
    

    【讨论】:

    【解决方案2】:

    mpdf页面布局可以通过以下方式自定义

    对于 mpdf 6.0 版我们可以使用

    $mpdf=new mPDF('utf-8', 'A4', 0, '', 0, 0, 0, 0, 0, 'L'); // use this customization
    

    6.0 版本中 mPDf 的默认设置以及参数如下所示

    function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P')
    

    对于 mpdf 7.0 或更高版本,我们可以使用

    $mpdf= new \Mpdf\Mpdf(['mode' => 'utf-8','format' => 'A4','margin_left' => 0,'margin_right' => 0,'margin_top' => 0,'margin_bottom' => 0,'margin_header' => 0,'margin_footer' => 0]); //use this customization
    

    7.0 版本中 mPDf 的默认设置以及参数如下所示

    $constructor = [
            'mode' => '',
            'format' => 'A4',
            'default_font_size' => 0,
            'default_font' => '',
            'margin_left' => 15,
            'margin_right' => 15,
            'margin_top' => 16,
            'margin_bottom' => 16,
            'margin_header' => 9,
            'margin_footer' => 9,
            'orientation' => 'P',
        ];
    

    关于 mPDF 类的可用选项的更多细节可以从官方文档https://mpdf.github.io/reference/mpdf-functions/construct.html获得

    【讨论】:

      【解决方案3】:

      您可以通过以下设置参数来调整边距

      new Pdf([
            'mode' => '', // leaner size using standard fonts
            'format' => Pdf::FORMAT_A4,
            'orientation' => Pdf::ORIENT_LANDSCAPE,
            'marginTop' => 0,
            'marginBottom' => 0,
            'marginLeft' => 0,
            'marginRight' => 0,
            'destination' => Pdf::DEST_BROWSER,
            'content' => $this->renderPartial('certificate_pdf', ['']),
            'options' => [
              // any mpdf options you wish to set
            ],
            'methods' => [
              'SetTitle' => '',
              'SetSubject' => '',
              'SetHeader' => [''],
              'SetFooter' => [''],
              'SetAuthor' => 'Ajira Tracking',
              'SetCreator' => 'Ajira Tracking',
              'SetKeywords' => 'Ajira Tracking',
            ]
          ]);
      

      【讨论】: