php 如何在mpdf中添加css文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15519335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add css file in mpdf
提问by saad
I am trying to convert html into pdf using mpdf. Problem is that i am unable to apply css to pdf file..
我正在尝试使用 mpdf 将 html 转换为 pdf。问题是我无法将 css 应用于 pdf 文件..
Here is my code of php:
这是我的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..
它正在做的是在我的这个 php 页面上通过 ajax 获取 html。但是它提供的输出没有附带我为它编写的 css..
Please tell me that to do now?
请告诉我现在要做什么?
回答by Haseeb
<?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 $htmlthen include mpdf.phpfile.
1st 分配您的 html,$html然后包含 mpdf.php文件。

