如何在MPDF添加CSS文件 [英] how to add css file in mpdf

查看:646
本文介绍了如何在MPDF添加CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用MPDF到HTML转换成PDF格式。问题是,我无法应用CSS为PDF文件。这里是我的$ C $的PHP了C

 < PHP

$的HTML = $ divPrint;
$ MPDF =新MPDF();
$样式的file_get_contents =('pdf.css');
$ mpdf->的WriteHTML(样式表$ 1);
$ mpdf->的WriteHTML($ HTML,2);
$ mpdf->输出();
出口;

?>
 

它是什么做的是通过AJAX在我这个PHP页面以HTML。但它给输出不来,我已经为它编写CSS ..请告诉我,现在怎么办?

解决方案

 < PHP

$的HTML = $ divPrint;

包括('mpdf.php'); //包括mpdf.php
$ MPDF =新MPDF();
$样式的file_get_contents =('pdf.css'); //外部CSS
$ mpdf->的WriteHTML(样式表$ 1);
$ mpdf->的WriteHTML($ HTML,2);
$ mpdf->输出();
出口;

?>
 

1日在 $ HTML 分配你的HTML然后包括 mpdf.php 文件。

i am trying to convert html into pdf using mpdf. problem is that i am unable to apply css to pdf file.. here is my code of php

   <?php

$html = $divPrint;
$mpdf=new mPDF();
$stylesheet = file_get_contents('pdf.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;

?>

what it is doing is taking html through ajax on my this php page . but the output it gives doesn't come with css which i've written for it.. please tell me that to do now?

解决方案

 <?php

$html = $divPrint;

include('mpdf.php'); // including mpdf.php
$mpdf=new mPDF();
$stylesheet = file_get_contents('pdf.css'); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;

?>

1st assign your html in $html then include mpdf.php file.

这篇关于如何在MPDF添加CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆