dtmsaqtly798322992 2017-04-13 16:07
浏览 89
已采纳

使用DomPDF创建日志文件

I'm having a problem getting font-awesome to work inside of a DomPDF document on my webserver. However, the same HTML does work when using eclecticgeek.com's DomPDF debug helper. Therefore, I know there is not problem with the HTML. Here's a link to the working code:

http://eclecticgeek.com/dompdf/debug.php?identifier=d0c3b30ed7fd65fabb5c64dda47decc5

I am trying to populate DomPDF's log file on my local webserver to help isolate the issue, but no file is generating for me. Here's my full code, I am trying to set the log file via DomPDF's options, but am not sure I am doing it right.

<?php

require_once "sites/all/libraries/dompdf/autoload.inc.php";
use Dompdf\Dompdf;

$HTML = <<<HTML
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
  <link href="https://fonts.googleapis.com/css?family=Macondo" rel="stylesheet">
  <style type="text/css">
  .fa {
    display: inline;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    font-size: 14px;
    line-height: 1;
    font-family: FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  </style>
</head>
<body>
  <p><span class="fa fa-envelope"></span> Font awesome doesn't work on my webserver</p>
   <p style='font-family: "FontAwesome"'> &#xf2b9; </p> <span> this also does not work </span>
  <p style='font-family: "Macondo", cursive;'> This font works</p>
</body>
</html>
HTML;

$dompdf = new \Dompdf\Dompdf(array(
    'tempDir' => 'sites/test.com/modules/CCPDF/',
    'isRemoteEnabled' => true,
    'isPhpEnabled' => true,
    'isJavascriptEnabled' => true,
    'pdfBackend' => "CPDF",
    'isHtml5ParserEnabled' => true,
    'logOutputFile' => 'sites/test.com/modules/CCPDF/test.log',
    'DOMPDF_UNICODE_ENABLED' => true
));
$dompdf->load_html($HTML);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream();

 ?>

Can anybody provide an example of how to properly set the DomPDF log file?

  • 写回答

1条回答 默认 最新

  • douyao6842 2017-04-22 16:44
    关注

    Here is a snippet of the PHP I use when I'm debugging locally.

    ini_set('display_errors', true);
    ini_set('error_log', 'output/tester.err.log');
    ini_set('log_errors', true);
    error_reporting(E_ALL);
    
    $dompdf_options = array(
        'chroot' => '/',
        'logOutputFile' => __DIR__ . '/dompdf.log.html',
        'isHtml5ParserEnabled' => true,
        'debugPng' => false,
        'debugKeepTemp' => false,
        'debugCss' => false,
        'debugLayout' => false,
        'debugLayoutLines' => false,
        'debugLayoutBlocks' => false,
        'debugLayoutInline' => false,
        'debugLayoutPaddingBox' => false
    );
    
    $_dompdf_show_warnings = true;
    $_dompdf_debug = false;
    $_DOMPDF_DEBUG_TYPES = [
       'page-break' => false
    ];
    
    $dompdf = new Dompdf\Dompdf($dompdf_options);
    echo 'Running with ' , $dompdf->version , "
    ";
    $_dompdf_warnings = array();
    echo 'Rendering '. $test_file . "
    ";
    $dompdf->load_html_file($test_file);
    $dompdf->render();
    file_put_contents(__DIR__ . '/' . basename($test_file) . (strtolower($dompdf_options['pdfBackend']) === 'gd' ? '.png' : '.pdf'), $dompdf->output(array('compress'=>0)));
    

    You can play around with the debug settings to get different types of debug information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型