标签: dompdf

将 CSS 添加到 DomPDF

我有这段代码可以将一些数据导出到 pdf 中。我想从外部 css 文件添加 css (在使用的 html 中没有提到)

/*********************************** Export PDF ****************************************************/
if($request->query->get('exportPDF')!= null){
    // Configure Dompdf according to your needs
    $pdfOptions = new Options();
    $pdfOptions->set('defaultFont', 'Arial');
    // Instantiate Dompdf with our options
    $dompdf = new Dompdf($pdfOptions);
    // Retrieve the HTML generated in our twig file
    $html = $this->renderView('dashboard/user_table.html.twig', [
        'users' => $users
    ]);
    // Load HTML to Dompdf
    $dompdf->loadHtml($html);
    // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
    $dompdf->setPaper('A3', 'landscape');
    // Render the HTML as PDF …
Run Code Online (Sandbox Code Playgroud)

php dompdf symfony

3
推荐指数
1
解决办法
4万
查看次数

使用 inline-block 在 dompdf 中的元素下方添加空间

当有两个或多个带有 的元素时display:inline-block,这些元素在渲染为 pdf 后似乎在下方有一个边距:

<div style="background-color:pink;">
    <div style="background-color:red;float:left;width:25%;">Hello</div>
    <div style="background-color:orange;float:left;width:25%;">Hello</div>
    <div style="background-color:yellow;float:left;width:25%;">Hello</div>
    <div style="background-color:green;float:left;width:25%;position:relative;">
        <div style="background-color:red;display:inline-block;width:25%;">Hello</div><!--
        --><div style="background-color:orange;display:inline-block;width:25%;">Hello</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

多个内联块元素

但当只有一个时,它显示正常:

<div style="background-color:pink;">
    <div style="background-color:red;float:left;width:25%;">Hello</div>
    <div style="background-color:orange;float:left;width:25%;">Hello</div>
    <div style="background-color:yellow;float:left;width:25%;">Hello</div>
    <div style="background-color:green;float:left;width:25%;position:relative;">
        <div style="background-color:red;display:inline-block;width:25%;">Hello</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

单个内联块元素

已经尝试clear:both在同级元素上使用并作为inline-block元素的包装器,但这只会导致它低于绿色 div

也已经尝试过使用float:left,就像它的父级一样,但是使用它会导致元素重叠

是否有其他方法可以使浮动元素的子元素水平对齐?

html css php dompdf

3
推荐指数
1
解决办法
2141
查看次数

laravel-dompdf | 像 Flex 一样将 div 显示为列

我正在创建用于以 PDF 形式导出会议详细信息的布局。布局时出现问题。我想将 div 显示为一列。例如图像 display: flex不起作用,我正在尝试 table、table-cell、table-flex 和 table-grid 但不起作用。主要内容下移侧边栏长度。

\n\n

我的所有刀片 html 代码;

\n\n
<!DOCTYPE html>\n<html lang="en">\n<head>\n    <meta charset="UTF-8">\n    <title>Document</title>\n    <link href="https://fonts.googleapis.com/css?family=Roboto:300,500,700&display=swap" rel="stylesheet">\n    <style media="screen">\n        @font-face {font-family: "Roboto-Light"; font-style: normal; font-weight: 300; src: url({{ url(\'fonts/Roboto-Light.ttf\') }})}\n        @font-face {font-family: "Roboto-Regular"; font-style: normal; font-weight: normal; src: url({{ url(\'fonts/Roboto-Regular.ttf\') }})}\n        @font-face {font-family: "Roboto-Bold"; font-style: normal; font-weight: bold; src: url({{ url(\'fonts/Roboto-Bold.ttf\') }})}\n\n        body { font-family: \'Roboto-Regular\'; }\n        * { margin: 0; padding: 0; }\n\n        .sidebar {\n            position: relative;\n            left: 0.9cm;\n …
Run Code Online (Sandbox Code Playgroud)

php dompdf laravel

3
推荐指数
1
解决办法
2万
查看次数

DOMPDF:内联PHP脚本无法正常工作

我有DOMPDF的问题.我正在运行PHP 5.3.3并拥有最新的DOMPDF 0.6.0 beta2.

我已经创建了这个HTML模板:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Printed document</title>
</head>
<body>

<script type="text/php">
echo "test";
if ( isset($pdf) ) {
    echo $PAGE_NUM;
}
</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这个文件用于呈现PDF:

<?php
require_once("dompdf/dompdf_config.inc.php");

$templateFile = 'template.html';
$content = file_get_contents($templateFile); 
if ($content !== false) {
    $dompdf = new DOMPDF();
    $dompdf->load_html($content);
    $dompdf->render();
    $dompdf->stream("test.pdf");
}
?>
Run Code Online (Sandbox Code Playgroud)

在dompdf_config.inc.php中,我将DOMPDF_ENABLE_PHP设置为true,但仍然在我呈现的PDF中显示测试字符串或页数.为什么?

我在这里压缩了我的小例子:http: //uploads.dennismadsen.com/pdf.zip

如果您需要更多信息,请告诉我.

php dompdf

2
推荐指数
1
解决办法
8949
查看次数

DOMPDF,给我带来了一个错误

这是我在PdfHtml类中的代码:

public function createTable($result){

    $html = "<html>
                    <body>
                        <table>
                            <th>
                                <td>Descripción</td>
                                <td>Artículo</td>
                                <td>Precio</td>
                            </th>
                        ";
    while($row = mysql_fetch_array($result)){
        $html .= "<tr>";
        $html .= "<td>".$row["producto"]."</td>";
        $html .= "<td>".$row["idProducto"]."</td>";
        $html .= "<td>".$row["precio"]."</td>";
        $html .= "</tr>";
    }

    $html .= "</table>
                </body>
                    </html>";

    return $html;
}
</i>
Run Code Online (Sandbox Code Playgroud)

我执行以下操作:

$pdfHtml = new PdfHTML();
$result = $pdfHtml->getProductosPorMarca($idMarca);
$html = $pdfHtml->createTable($result);

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->output();
Run Code Online (Sandbox Code Playgroud)

抛出这个:

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in …
Run Code Online (Sandbox Code Playgroud)

html php mysql dompdf

2
推荐指数
1
解决办法
8597
查看次数

在dompdf中创建pdf后如何打开打印窗口?

我使用dompdf将html转换为Pdf,我想打印它。我的问题是如何在打印窗口中打开pdf文件而不是打开下载对话框?

include('dompdf/dompdf_config.inc.php');

$savein = 'pdfdirectory/';  

$html = " my htmlcode here " 

$dompdf = new DOMPDF();
$dompdf->load_html($html);            
$dompdf->render();      

$pdf = $dompdf->output();             
file_put_contents(($savein.'file.pdf'), $pdf);           

$dompdf->stream('file.pdf'); 
Run Code Online (Sandbox Code Playgroud)

php pdf dompdf

2
推荐指数
1
解决办法
4749
查看次数

无法打开使用dompdf生成的pdf文件

我正在尝试使用dompdf从smarty模板生成pdf文件:代码如下: -

require_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($smarty->fetch(CURRENT_TEMPLATE.'/module/shopping_cart.html'));
$dompdf->render();
$dompdf->stream("sample.pdf");
Run Code Online (Sandbox Code Playgroud)

生成pdf文件,但是当我尝试打开pdf文件时,显示如下错误消息"Acrobat无法打开'sample.pdf',因为它不支持文件类型或因为文件已损坏"HTML页面是当我尝试时正确地浸渍

echo $smarty->fetch(CURRENT_TEMPLATE.'/module/shopping_cart.html')
Run Code Online (Sandbox Code Playgroud)

所以请帮我解决这个错误...提前谢谢

php pdf-generation smarty dompdf

2
推荐指数
3
解决办法
9076
查看次数

PHP致命错误:第30行找不到类'DOMPDF'

我正在使用DOMPDF从HTML生成PDF.我已经从github(编码分支)复制了所有必需的文件.但是它说类DOMPDF没有错误,如下所示.

链接为gitbub中的dompdf_config.inc.php:https://github.com/dompdf/dompdf/tree/encoding

这是我的代码:

require_once("APIs/dompdf-encoding/dompdf_config.inc.php");     
$cart_body='<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>New Order Placed</title></head><body><p>Test Printing...</p></body></html>';
        $dompdf = new DOMPDF();
        $dompdf->load_html($cart_body);//body -> html content which needs to be converted as pdf..
        $dompdf->render();
        $dompdf->stream("sample.pdf"); //To popup pdf as download
Run Code Online (Sandbox Code Playgroud)

实际产出是:

致命错误:第30行/home/web/www/test_dompdf.php中找不到"DOMPDF"类

30号线是 $dompdf = new DOMPDF();

注意:其他Master Branch工作正常.我需要这个编码分支,因为它解决了编码字体相关的问题.

php pdf dompdf

2
推荐指数
1
解决办法
2万
查看次数

如何在WordPress中使用domPDF

所以我希望在我的WordPress帖子上有一个按钮,将帖子转换为PDF.我找到了domPDF,但我不确定如何使用WordPress实现它?

我知道使用插件会更容易,但我想在没有插件的情况下这样做.

有人可以向我解释如何实现这一点吗?谢谢

html css php wordpress dompdf

2
推荐指数
2
解决办法
5206
查看次数

如何使用DOMPDF和Laravel将pdf精确设置为10CM宽度?

我正在使用DOMPDF和laravel 创建PDF 。

将使用特殊的打印机打印pdf,该打印机仅接受宽度为10CM和高度为20CM的文件。

我已经试过了:

$customPaper = array(0,0,720,1440);
$pdf = PDF::loadView('pdf.retourlabel',compact('retour','barcode'))->setPaper($customPaper);
Run Code Online (Sandbox Code Playgroud)

由于11X17是

"11x17" => array(0, 0, 792.00, 1224.00),
Run Code Online (Sandbox Code Playgroud)

我认为10X20为0,0720,1440

但这不起作用。

任何帮助表示赞赏。

提前致谢

php pdf dompdf laravel

2
推荐指数
2
解决办法
6207
查看次数

标签 统计

dompdf ×10

php ×10

html ×3

pdf ×3

css ×2

laravel ×2

mysql ×1

pdf-generation ×1

smarty ×1

symfony ×1

wordpress ×1