MPDF如何删除空格边距

时间:2014-09-27 03:34:59

标签: mpdf

$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

3 个答案:

答案 0 :(得分:13)

使用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 ]]]]]])

答案 1 :(得分: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中获得

答案 2 :(得分:0)

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

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',
      ]
    ]);