问题
Here I am in a problem while converting HTML to PDF using mPDF. I have done the following code:
if(isset($_POST['imp1']))
{
require_once 'mpdf60/mpdf.php';
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; //
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$test= "<html><body><table><tr><td>Hello</td></tr></table></body></html>";
$mpdf->WriteHTML($test, 2);
$mpdf->Output();
exit();
}
?>
This code is working fine but while am adding the following stylesheet in the header...the code is not working...
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="/test7/assets/css/bootstrap.css" rel="stylesheet"/>
<link href="/test7/assets/css/datepicker.css" rel="stylesheet"/>
<link href="/test7/assets/css/bootstrap-flat.css" rel="stylesheet"/>
<link href="/test7/assets/css/invoiceform.css" rel="stylesheet"/>
I am simply wrecking my head why this is creating the issue
回答1:
Finally I have figured it out...the issue is in HEADER...I have put the code block in before the stylesheet declaration.
<head>
<?
if(isset($_POST['imp1']))
{
require_once 'mpdf60/mpdf.php';
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; //
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$test= "<html><body><table><tr><td>Hello</td></tr></table></body></html>";
$mpdf->WriteHTML($test, 2);
$mpdf->Output();
exit();
}
?>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="/test7/assets/css/bootstrap.css" rel="stylesheet"/>
<link href="/test7/assets/css/datepicker.css" rel="stylesheet"/>
<link href="/test7/assets/css/bootstrap-flat.css" rel="stylesheet"/>
<link href="/test7/assets/css/invoiceform.css" rel="stylesheet"/>
</head>
来源:https://stackoverflow.com/questions/28348607/downloading-html-through-mpdf