domPDF背景图像未在PDF中呈现

时间:2011-12-27 18:09:51

标签: php pdf pdf-generation dompdf

<?php

include('../helper/app2.php');

$admin = new admin;

$preview = $admin->pdfPreview();

$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title> New Document </title><meta name="Generator" content="EditPlus"><meta name="Author" content=""><meta name="Keywords" content="">  <meta name="Description" content="">  <link href="../../css/style.css" rel="stylesheet" type="text/css" /></head><body><div class="biegeBox"><div class="cardContainer"><div class="cardImg" style="background-image:url(http://'.$_SERVER['SERVER_NAME'].'/demo/'. $preview[0]['image'].'); background-repeat:no-repeat;"><div class="cardQuote">'.$preview[0]['desc'].'</div></div></div></div></body></html>';

if ( isset( $html ) ) {

    require_once("dompdf_config.inc.php");

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
    $dompdf->render();

    $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

    exit(0);
}
?>

上面的代码我用来从dom创建pdf,但它不是在pdf中渲染图像。任何人都可以帮我解决它。在阅读此DOMPDF Page background (or alternatives?)问题和答案后,我更改了背景属性。

1 个答案:

答案 0 :(得分:0)

这可能不适用于您,但在我的共享托管环境中,我能够包含图像的唯一方法是将图像放在与HTML文件相同的目录中,并通过其相对路径引用它