这是请求和响应标头
http://www.example.com/get/pdf
GET /~get/pdf HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www.example.com
Cookie: etc
HTTP/1.1 200 OK
Date: Thu, 29 Apr 2010 02:20:43 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: Me
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Cache-Control: private
Content-Disposition: attachment; filename="File #1.pdf"
Content-Length: 18776
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: …Run Code Online (Sandbox Code Playgroud) 我正在使用Dompdf从html模板和Pdfnup(Pdfjam的一部分)生成A5 pdf文档,将它们组合成一张漂亮的单张A4纸,这有助于在打印时节省一些纸张:)
# Generate an a5 pdf
php dompdf.php mytemplate.html -p 'A5' -f a5doc.pdf
# combine two copies of the generated A5 into a single A4 page
pdfnup a5doc.pdf a5doc.pdf --nup '2x1'
Run Code Online (Sandbox Code Playgroud)
这很好用; 虽然第二步迫使我安装大量的依赖项(即Tex-Latex,pdftex,ecc.)并且会混乱我的生产服务器.我想知道是否有任何方法来组合生成的文件而不实际使用Pdfnup.例如,有没有办法用pdftk这样做?
先感谢您!
例如Page 1 of 5.
网上有一个如何获得Page 1部分但不是of 5部分的例子.就是这个:
.pagenum:before { content: "Page " counter(page); }
Run Code Online (Sandbox Code Playgroud)
我使用的是版本0.6,$PAGE_NUM并且$PAGE_COUNT不起作用.
我需要和DOMPDF同时做两件事.
我需要一起做以下事情 - 这可能吗?
//print the pdf file to the screen for saving
$dompdf->stream("pdf_filename_".rand(10,1000).".pdf", array("Attachment" => false));
//save the pdf file on the server
file_put_contents('/home/stsnew/public_html/pdf/file.pdf', $dompdf->output());
Run Code Online (Sandbox Code Playgroud)
上面的工作很好,如果$dompdf->stream和$dompdf->output()单独/单独完成,但当我尝试如上所示一起运行它们时,它只是崩溃.
任何帮助/建议将非常感激.
我正在使用Codeigniter,我成功实现了dompdf来生成PDF文件.现在我在生成的PDF中添加页眉和页脚时遇到问题.
这是我的dompdf_helper代码:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->set_paper("A4");
if ($stream) {
$dompdf->stream($filename.".pdf",1);
} else {
return $dompdf->output();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器调用PDF生成:
<?php
$data['store']=$res;
$this->load->helper(array('dompdf', 'file'));
$html = $this->load->view('store/sales_pdf', $data, true);
$html.= $this->load->view('footer');
$filename="salesbill".$id;
pdf_create($html, $filename);
$data = pdf_create($html, '', false);
write_file('name', $data);
?>
Run Code Online (Sandbox Code Playgroud)
我使用此脚本获取页码,但仅在第二页退出时打印,否则将无法打印.
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(500,10, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
}
</script> …Run Code Online (Sandbox Code Playgroud) 我正在使用DOMPDF(v 0.5.2)将html页面转换为pdf文件.
PHP脚本运行后(如预期的那样)显示pdf文件,但没有样式应用于任何内容.据我所知,浮动属性不适用于DOMPDF,所以我必须做一些工作来解决这个问题,但是甚至没有应用字体样式.
我尝试了包括样式的所有三种方法:附加样式表,
<link href="styles.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)
在标题中写样式,
<style>...</style>
Run Code Online (Sandbox Code Playgroud)
和内联样式.
<div class="..." style="...">
Run Code Online (Sandbox Code Playgroud)
用于创建pdf的php文件看起来像这样......
<?php
ob_start();
?>
<html>
<head>
<link href="flhaha.css" rel="stylesheet" type="text/css">
</head>
<body>
... content (divs, etc)
</body>
</html>
<?php
require_once("../../scripts/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_clean());
$dompdf->render();
$dompdf->stream('test.pdf');
?>
Run Code Online (Sandbox Code Playgroud)
内容中的图像可以正常加载并在pdf打开时正确显示,但仍然没有样式.
提前致谢!
编辑#1:上面的标签是"风格",而不是"风格".修正了错字.
我正在尝试将用于Laravel的DOMPDF包装器合并到我的项目中,但是我正在考虑如何将变量传递到PDF模板中.
根据说明,我的控制器中有:
//PrintController.php
$data = array('name'=>'John Smith', 'date'=>'1/29/15');
$pdf = PDF::loadView('contract', $data);
return $pdf->stream('temp.pdf');
Run Code Online (Sandbox Code Playgroud)
在我看来:
//contract.php
...
<p><?php echo $data->name ?><p>
<p>Signature</p>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试渲染页面时,我收到错误:
ErrorException (E_UNKNOWN)
Undefined variable: data
Run Code Online (Sandbox Code Playgroud)
我不确定为什么该loadView()方法没有将$data变量传递给视图.在控制器和/或视图中设置它时是否缺少一个步骤?
我的代码工作正常,直到今天.我没有改变任何东西,但突然我的PDF代码无法正常工作.我正在使用barryvdh/laravel-dompdf这个包laravel 5.2.
我删除了本地项目并从实时服务器下载但仍然在我的本地计算机上出现此问题.我的实时项目可以正常使用此代码.
这是我的代码
$pdf = App::make('dompdf.wrapper');
$pdf->loadView('back_end.pdf_template.make_invoice', ['order_info' =>$order_info, 'order_details' => $order_details]);
return $pdf->stream('inv-' . $order_info->invoice_id . '.pdf');
Run Code Online (Sandbox Code Playgroud)
我使用 dompdf 0.5.1 来生成 PDF 文件。但特殊字符没有正确显示。
\n\n\n\n它显示类似于\xc3\xa2\xe2\x82\xac\xe2\x80\x9c \xc3\xa2\xe2\x82\xac\xc5\x93生成的 PDF 文件中的内容。
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />我在由 dompdf 呈现的 HTML 页面中使用了 UTF-8 编码,如\n 。
我还在将其发送到 dompdf 之前使用了编码,例如 \n $dompdf->load_html(utf8_decode($html));。
但我得到的是?分数而不是上面的字符。
我该如何解决上述问题?
\n我正在尝试从视图生成 pdf,但样式就是不出来。我尝试过使用 3 个不同的库,但结果并没有太大不同。我错过了什么吗?
view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test View</title>
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset('css/app.css') }}">
<script src="{{ asset('js/app.js') }}" defer></script>
</head>
<body class="font-sans antialiased">
<div class="grid grid-cols-3">
<div class="bg-red-200 col-span-2 h-screen"></div>
<div class="bg-blue-200 h-screen">
<div class="grid grid-cols-8">
<div class="col-span-7">
<div class="rounded-t-full w-full h-screen flex items-center justify-center bg-green-600">
<div class="h-60 w-60 rounded-full bg-blue-500">TEST</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
appearance
dompdf export method
protected function dompdfImplementation()
{
$dompdf = new …Run Code Online (Sandbox Code Playgroud) dompdf ×10
php ×6
laravel ×3
pdf ×2
codeigniter ×1
css ×1
encoding ×1
ghostscript ×1
http-headers ×1
kohana ×1
laravel-5.2 ×1
mpdf ×1
pdftk ×1
styles ×1
stylesheet ×1
tailwind-css ×1
tcpdf ×1
utf-8 ×1