通过mpdf下载html

时间:2015-02-05 16:05:20

标签: php mpdf

在使用mPDF将HTML转换为PDF时遇到问题。我已经完成了以下代码:

    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"/>

我只是破坏了我的头脑,为什么这会产生问题

1 个答案:

答案 0 :(得分:0)

最后我已经弄明白了......问题出在HEADER ......我已经在样式表声明之前放了代码块。

<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>