无法在横向mPDF v7.X

时间:2018-04-11 17:33:25

标签: php mpdf

无法在横向mPDF v7.X

中创建字符串PDF法律页面

省略说这个例子的旧版本:

$mpdf=new mPDF('utf-8', 'A4-L');

$mpdf=new mPDF('','', 0, '', 15, 15, 16, 16, 9, 9, 'L');
新版本7.X中的

$myMpdf = new Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4-L',
    'orientation' => 'L'
]

我正在嘲笑这个Construc:

function GenPDF2List($P) {
        try {
            $FNAME=$P['FNAME']; #filename.pdf
            $FSIZE=$P['FSIZE']; #Legal
            $FVIEW=$P['FVIEW']; #L
            $mpdf = new \Mpdf\Mpdf([ 
                'mode' => 'utf-8', 
                'format' => $FSIZE, 
                'orientation' => $FVIEW, 
                'margin_left'=> 5, 
                'margin_right'=> 5, 
                'margin_top'=> 5, 
                'margin_bottom'=> 5, 
                'margin_header'=> 5, 
                'margin_footer'=> 5 
            ]);
            $mpdf->SetAuthor($P['AUTOR']);
            $mpdf->SetTitle($P['TITTLE']);
            $mpdf->WriteHTML($P['CONT']);
            $P['DOC'] = $mpdf->Output($FNAME,\Mpdf\Output\Destination::STRING_RETURN);
            return $P;
        } catch (\Mpdf\MpdfException $e) {
            echo $e;
        }
    }

不要工作我明白了:

example

我没有得到任何人错误,警告或ETc ...... 使用其他HTML代码进行测试...

function GenPDF2List($P) {
            try {
                $FNAME=$P['FNAME']; #filename.pdf
                $FSIZE=$P['FSIZE']; #Legal
                $FVIEW=$P['FVIEW']; #L
                $mpdf = new \Mpdf\Mpdf([ 
                    'mode' => 'utf-8', 
                    'format' => $FSIZE, 
                    'orientation' => $FVIEW, 
                    'margin_left'=> 5, 
                    'margin_right'=> 5, 
                    'margin_top'=> 5, 
                    'margin_bottom'=> 5, 
                    'margin_header'=> 5, 
                    'margin_footer'=> 5 
                ]);
                $mpdf->SetAuthor($P['AUTOR']);
                $mpdf->SetTitle($P['TITTLE']);
                $mpdf->WriteHTML('<h1>hello world</h1>');
                $P['DOC'] = $mpdf->Output($FNAME,\Mpdf\Output\Destination::STRING_RETURN);
                return $P;
            } catch (\Mpdf\MpdfException $e) {
                echo $e;
            }
        }

Example 2

Chrome浏览器中的PDF查看器:

$info        = '<object data="data:application/pdf;base64,' . 
                base64_encode($P['DOC']) 
                . '" type="application/pdf" height="600px" width="100%"></object>';

1 个答案:

答案 0 :(得分:0)

对于我的设置,

Orientation param当前不起作用。 我不知道这是错误/错误还是什么。

我用以下方法解决了这个问题:

function GenPDF2List($P) {
            try {
                $FNAME=$P['FNAME']; #filename.pdf
                $FSIZE=$P['FSIZE']; #Legal
                $FVIEW=$P['FVIEW']; #L
                $mpdf = new \Mpdf\Mpdf([ 
                    'mode' => 'utf-8', 
                    'format' => $FSIZE, 
                    'orientation' => $FVIEW, 
                    'margin_left'=> 5, 
                    'margin_right'=> 5, 
                    'margin_top'=> 5, 
                    'margin_bottom'=> 5, 
                    'margin_header'=> 5, 
                    'margin_footer'=> 5 
                ]);
                $mpdf->AddPage('L');
                $mpdf->SetAuthor($P['AUTOR']);
                $mpdf->SetTitle($P['TITTLE']);
                $mpdf->WriteHTML('<h1>hello world</h1>');
                $P['DOC'] = $mpdf->Output($FNAME,\Mpdf\Output\Destination::STRING_RETURN);
                return $P;
            } catch (\Mpdf\MpdfException $e) {
                echo $e;
            }
        }