启用生成 pdf(它给我计划 html 文件中的文本)- dompdf

Enable to generate pdf (It give me plan html text in a file) - dompdf

$content['profile_data'] = file_get_contents(base64_decode($profile_data,true));
$pdf = PDF::loadHtml(htmlentities($content['profile_data']));
$pdf->setOptions(['setIsHtml5ParserEnabled'=>true]);
// $pdf->setPaper('A4','landscape');
$pdf->stream();
$pdf->save($path . '/' . $file_name.'.pdf');

整个代码看起来没问题。 html 来自 url。我正在尝试将其保存为 pdf 文件。

但是当我尝试打开时,它给了我一个计划文本 HTML。请帮助我

谢谢

您没有渲染 (->render())。

简短示例:

$html = ''; // Your html.
$size = 'A4';
$orientation = 'portrait';
$options = new Options(
    [
        'isHtml5ParserEnabled'    => true, // little faster
    ]
);
$domPdf = new Dompdf($options);
$domPdf->loadHtml($html);
$domPdf->setPaper($size, $orientation);
$domPdf->render();
$pdf = $domPdf->output();

这里我 post 我用 dompdf 做的所有事情 -
我搜索了很多,边做边学...也许它有帮助:

以下为版本v0.8.6

/**
 * Returns pdf from html.
 *
 * @param string $html
 * @param string $size
 * @param string $orientation
 *
 * @return string
 */
public function htmlToPdf($html, $size = 'A4', $orientation = 'portrait')
{
    $options = new Options(
        [
            //'logOutputFile'           => 'data/log.htm',
            'isPhpEnabled'            => false,
            'isRemoteEnabled'         => false,
            'isJavascriptEnabled'     => false,
            'isHtml5ParserEnabled'    => true, // little faster
            'isFontSubsettingEnabled' => false,
            'debugPng'                => false,
            'debugKeepTemp'           => false,
            'debugCss'                => false,
            'debugLayout'             => false,
            'debugLayoutLines'        => false,
            'debugLayoutBlocks'       => false,
            'debugLayoutInline'       => false,
            'debugLayoutPaddingBox'   => false,
            //'pdfBackend'              => 'CPDF',
        ]
    );
    $domPdf = new Dompdf($options);
    $domPdf->loadHtml($this->minimizeHtml($html));
    $domPdf->setPaper($size, $orientation);
    $domPdf->render();
    return $domPdf->output();
}

/**
 * Minimizes the html source.
 *
 * @see 
 *
 * @param string $html
 *
 * @return string
 */
public function minimizeHtml($html)
{
    return preg_replace(
        [
            '/\>[^\S ]+/s',  // strip whitespaces after tags, except space
            '/[^\S ]+\</s',  // strip whitespaces before tags, except space
            '/(\s)+/s'       // shorten multiple whitespace sequences
        ],
        [
            '>',
            '<',
            '\1'
        ],
        $html
    );
}