【问题标题】:domPDF background image is not rendering in the PDFdomPDF 背景图像未在 PDF 中呈现
【发布时间】:2012-01-28 16:29:33
【问题描述】:
<?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?) 问答后,我更改了背景属性。

【问题讨论】:

  • 确保您访问远程资源的设置正确,特别是 DOMPDF_ENABLE_REMOTE 和 allow_url_fopen 都是 true。使用 dompdf 0.5.x 还是 0.6.x?在 0.6.x 中,您可以访问 dompdf/www/setup.php(通过您的 Web 服务器)以查找任何危险信号。
  • 是的,DOMPDF_ENABLE_REMOTE 和 allow_url_fopen 都为 true 且已启用。
  • 你能发布生成的 HTML+CSS 而不是生成它的 PHP 吗?您的包含 div 的样式是否具有宽度/高度?您使用的是哪个版本的 dompdf?
  • 就我而言,allow_url_fopen 需要从 PHP.ini 中打开。

标签: php pdf pdf-generation dompdf


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 2019-12-03
    • 2018-08-30
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多