是否可以在DOMpdf中添加新页面?与mPDF AddPage()类似; functionaly.我似乎无法在文档中找到任何内容,是否有任何解决方法?
我似乎无法在文档中找到任何内容.
版本:0.6.0 beta 3
我试着以各种方式让dompdf设置页面的边距.我有一个很长的页面,有很多文字,分为章节......
我的css是这样的:
#wrapper{
padding:8px;
}
/* other styles... */
@page{margin: 0.2in 0.5in 0.2in 0.5in;}
Run Code Online (Sandbox Code Playgroud)
当PHP是
<?php
ob_start(); // begin collecting output
include 'makemypdf.php'; // this page output the html
$html = ob_get_clean(); // retrieve output from makemypdf.php and stop buffering
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf", array("Attachment" => false));
?>
Run Code Online (Sandbox Code Playgroud)
但我得到的是一个没有利润的页面!只应用#wrapper的填充...并且它们仅在整个PDF的开头和结尾应用...
我做错了什么?
PS - 似乎只应用了底部保证金...但我不确定......
PPS - 我试过这个css:body {margin-top:40px; } html {margin-top:40px; } @page {margin-top:40px; }
我正在努力让用户能够生成发票和其他表格数据的PDF副本.为此,我将dompdf包装到一个可以与CI一起使用的库中,并创建了一个方法,该方法将根据CI的返回值生成PDF output->get_output().包装器类似于Github上的这个包装器.
问题是,我无法找到一种方法来将视图(以及PDF所需的HTML/CSS)转换为CI的输出类load->view(),而不是写入浏览器.
我唯一的另一个选择是使用curl来请求页面,但这似乎很愚蠢,因为我可以从输出缓冲区得到它.我只是不希望HTML发送到浏览器,因为我设置标题告诉浏览器期望PDF.
要清楚,这就是我想要完成的事情(按照我想要完成的顺序):
output->get_output()给我的dompdf库我没有看到基于输出类文档执行第2步的任何方法.
是否可以在不显示输出类的情况下获取视图?如果是这样,怎么样?我正在使用CI 2.0.3.
编辑
非常有帮助的Anthony Sterling指出,我可以通过设置第三个参数告诉它返回一个字符串而不是将视图渲染为TRUE来从loader类中得到我想要的东西.例如:
$lotsaHtml = $this->load->view('fooview', $somearray, TRUE);
Run Code Online (Sandbox Code Playgroud)
这在我的特定实例中会更好,因为我不需要加载部分.然而,这仍然是一个有效的(我认为)有趣的问题,知道我是否可以从OB得到相同的东西也是很方便的,也许如果我确实有一堆偏.那些可以连接起来,但是很糟糕.
看起来我应该能够让输出类不呈现任何东西(否则,为什么get_output()存在?)所以我可以用它知道的所有东西做其他事情.我找不到让这种情况发生的方法.
编辑2
一些伪(但不远离现实)的代码说明我希望做什么,通过展示我做了什么,然后解释我实际想做什么.
假设我genpdf($id)在使用名为invoice的模型命名的控制器中有一个公共方法inv:
public function genpdf($invoiceId) {
$this->load->library('dompdflib');
$this->pagedata['invoice_data'] = $this->inv->getInvoice($invoiceId);
$html = $this->load->view('pdfgen', $this->pagedata, TRUE);
$this->dompdflib->sendPdf($html);
}
Run Code Online (Sandbox Code Playgroud)
这几乎与我现在使用的代码相同.在那里,我要求加载器解析并将pdfgen视图的结果作为字符串给我,我将其传递给我的dompdf包装器中的函数,该函数设置标头并将PDF发送到浏览器.
只是通过获取输出缓冲区本身(在正确设置标头/等之后),这似乎很容易做到.
或者我只需要append_output()在每次加载部分时连续调用输出类?
加载过多模型的多个方法需要一起工作才能生成这些(它们是作为事后的想法进行的),所以我希望只收集它并直接从输出类中检索它.可能是我必须逐渐谈谈 …
我试图使用dompdf生成pdf,如何在浏览器的新选项卡中打开pdf?比如,我单击PDF的链接,它应该在新选项卡中打开,而不是自动保存.我想让用户在首先看到文件后选择保存文件.我怎么做?
每当我在文件末尾使用$ pdf-> output时,它不会改变任何东西,文件仍会自动下载.请帮忙.谢谢.
我不知道为什么但是html页面显示得很好但是dompdf没有使用浮点数.
代码是2300 +线长,所以要在这里发布....但它是所有内联css.
<div style="float:left;"> </div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试将css包装在样式标记中并且内联没有运气.
这是html页面
http://www.ems-complete.com/ccems/ccems_reports/daily_vehicle_check_sheet.php?id=5
这是dompdf链接
http://www.ems-complete.com/ccems/ccems_reports/form_daily_vehicle_check.php?id=5
我不知道为什么但是html页面显示得很好但是dompdf没有使用浮点数...
代码是2300 +线长,所以要在这里发布....但它是所有内联css ...
我试图用正确的字符创建pdf,但有"?" 字符.我创建了一个测试php文件,我试图找到最好的解决方案.如果我在浏览器中打开html我看起来没问题
UTF-8 --> UTF-8 : X Ponuka ?íslo € ?erný ?ešký
Run Code Online (Sandbox Code Playgroud)
但是当我查看pdf时,我看到了这一点
UTF-8 --> UTF-8 : X Ponuka ?íslo € ?erný ?ešký
Run Code Online (Sandbox Code Playgroud)
这是我的所有代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>? s š Š</title>
</head>
<body>
<?php
require_once("dompdf/dompdf_config.inc.php");
$tab = array("UTF-8", "ASCII", "Windows-1250", "ISO-8859-2", "ISO-8859-1", "ISO-8859-6", "CP1256");
$chain = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style></style><title>? s š Š</title></head><body>';
foreach ($tab as $i)
{
foreach ($tab as $j)
{
$chain .= "<br> $i --> $j : ".iconv($i, $j, 'X Ponuka ?íslo € …Run Code Online (Sandbox Code Playgroud) 我试图使用DomPDF获取PDF,但我遇到了一个奇怪的问题.所有数据和其他东西都很好但是当它以PDF格式呈现时,表格的第一行总是不合时宜.首先,我可能是表格正在下一页导致风格脱离上下文但我试图将表限制为一页,并发现问题仍然存在.所以,每一页上的第一行表都很疯狂.以下是我的PDF代码和屏幕截图.
调节器
$dompdf = new DOMPDF();
$dompdf->load_html($listing);
$dompdf->set_paper('a4', 'landscape');
$dompdf->render();
$dompdf->stream("sample.pdf");
Run Code Online (Sandbox Code Playgroud)
视图
<table class="table table-bordered">
<tr>
<th width="150">Client </th>
<td>Client Name </td>
</tr>
<tr>
<th>Site </th>
<td><?php print $site->title; ?></td>
</tr>
<tr>
<th>Address </th>
<td>
<?php
print $site->unit.' '.
$site->street.' '.
$site->suburb.' '.
$site->state.' '.
$site->location;
?>
</td>
</tr>
<tr>
<th>Post Code </th>
<td><?php print $site->postcode; ?></td>
</tr>
<tr>
<th colspan="2"> Site Information</th>
</tr>
<tr>
<td colspan="2" height="150"> <?php print $site->site_information; ?></td>
</tr>
<tr>
<th colspan="2">Work Instruction</th>
</tr>
<tr>
<td …Run Code Online (Sandbox Code Playgroud) 我有三个单独的部分header,body并footer创建PDF格式.
标题部分将始终位于每个页面的顶部,它将被修复.
______________________
| header |
|______________________|
Run Code Online (Sandbox Code Playgroud)
问题在于身体内容,如果内容很大,则会转到第二页.
______________________
| |
| |
| body |
| |
| |
|______________________|
Run Code Online (Sandbox Code Playgroud)
页脚部分将始终位于每页的底部,它也将修复.
______________________
| footer |
|______________________|
Run Code Online (Sandbox Code Playgroud)
所以,如果内容很大,如果创建了两个页面,那么我应该得到两个页面:
______________________
| header |
|______________________|
| |
| |
| Body Part1 |
| |
| |
|______________________|
| footer |
|______________________|
Run Code Online (Sandbox Code Playgroud)
和
______________________
| header |
|______________________|
| |
| |
| Body part2 |
| |
| |
|______________________|
| footer |
|______________________|
Run Code Online (Sandbox Code Playgroud)
我尝试使用 …
在我的服务器上,通过dompdf生成的pdf没有显示图像.因为它们是远程网址图像.(本地图像工作正常)然后我才知道它需要一些设置来渲染远程图像.
allow_url_fopen = true => i can not as server control is not in my hand.(and no one will suggest to do this due to security reasons)
read/write access to the DOMPDF_TEMP_DIR (already have this)
DOMPDF_ENABLE_REMOTE = true (already have this)
Run Code Online (Sandbox Code Playgroud)
所以为了确定allow_url_fopen的问题,我在localhost中设置false,现在提供与服务器相同的输出.
所以,现在问题是我想用allow_url_fopen = false显示PDF格式的远程图像
是否有人可以建议我如何以pdf格式显示图像.我一直得到的错误是......
Image not found
http://localhost/dompdf/image.php
Run Code Online (Sandbox Code Playgroud)
和
Image not found
http://localhost/dompdf/image.jpg
Run Code Online (Sandbox Code Playgroud) 我使用dompdf库生成了一个PDF并使用了这个:
$dompdf->stream('my.pdf',array('Attachment'=>0));
Run Code Online (Sandbox Code Playgroud)
在下载之前强制浏览器让用户查看PDF.但它不起作用.谷歌搜索也没有提出任何答案.有人可以帮忙吗?