dompdf水印、图像、页眉和页脚问题
我使用 dompdf 作为 codeigniter 中的插件。它完美地生成了pdf。但有些问题困扰了我好几天。
我想在生成的 pdf 的每一页中放置一个图像作为标题。我是根据此处给出的教程完成的。 但没有任何进展。我尝试在 pdf 脚本所在的同一文件夹中查找所有类型的图像(jpg、png、gif)。它不起作用。然后我尝试设置图像和CSS的路径变量,如
http://code.google.com/p/dompdf/wiki/Usage
所示。但我找不到很好的示例或教程为此。如果有人曾经使用过这个,请帮助我。我还想在每个页面上添加水印。为此我正在使用
$pdf->page_text(110, $h - 240, "试用", Font_Metrics::get_font("verdana", "bold"),110, 数组(0.92, 0.92, 0.92), 0 ,-58);
。
这工作正常并生成水印。但是水印覆盖了内容。有什么可以改变水印的不透明度吗?它不会通过改变数组中的参数而改变。
3.在每一页的末尾(最后一页除外)我想放置文本“继续..”。为此,我正在使用
$text = "Continued..";
$width = Font_Metrics::get_text_width($text, $font, $size);
$pdf->page_text($w - 16 - $width - 38, $y-15, $text, $font, $size, $color);
它将文本放入每个页面中(因为它应该)。有什么办法可以将文本放入除最后一页之外的所有页面中吗?
- 如何设置dompdf的lib文件中没有的字体?
i am using dompdf as a plugin in codeigniter. it generates the pdf perfectly. but some problem are eating up me for some days.
I want to put an image as header in every page of the generated pdf. i did it according to the tutorial given here.
but no progress. i tried for images of all types(jpg,png,gif) in the same folder wheresript for pdf resides. it did not work. then i tried for setting the path variable for image and css as shown athttp://code.google.com/p/dompdf/wiki/Usage
.but i could not get a good example or tutorial for that. if any body has ever used this please help me.i also want to add watermark on every page. for that i am using
$pdf->page_text(110, $h - 240, "TRIAL", Font_Metrics::get_font("verdana", "bold"),110, array(0.92, 0.92, 0.92), 0, -58);
.
This works fine and generates watermark.but watermark comes over content.is there any thing to change the opacity of watermark. it is not changed by changing parameters in array.
3.at the end of every page ( except the last one) i want to put the text "continued..". for that i am using
$text = "Continued..";
$width = Font_Metrics::get_text_width($text, $font, $size);
$pdf->page_text($w - 16 - $width - 38, $y-15, $text, $font, $size, $color);
it puts the text in every page(as it should). is there any way to put text in all pages except the last one?
- how to set font which are not available in the lib file of dompdf?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)您使用的代码到底是什么?听起来您在内联脚本方面取得了成功,但在图像方面却没有。所以你的代码可能有问题。
2)这是内联脚本的问题。它在 HTML 内容之后呈现,这意味着它显示在 HTML 内容之上。通过内联脚本添加文本时曾经有一个不透明度选项,但我不确定它是否可以正常工作。它已从 0.6.0 代码库中删除。
您可能需要等待下一个版本,其中将包含更多样式选项,可以实现您想要在 HTML 中执行的操作(特别是固定定位和 CSS 翻译)。
3)我不确定您是否可以在除最后一页之外的每个页面上显示标题。有一个选项可以停止对象的显示,但它似乎只影响后续页面。因此,您必须将相关代码添加到最后一页之前的页面。
4) 如果您想添加字体,您需要能够使用 load_font.php 解析它。您还需要访问可执行文件 ttf2afm (dompdf 0.5.1) 或 ttf2ufm (dompdf 0.6.0)。有有关如何加载字体的说明,或者您也可以尝试我开发的基于网络的字体准备工具。
1) What, exactly, is the code you're using? It sounds like you're having success with inline script, just not images. So there could be a problem with your code.
2) This is a problem with inline script. It is rendered after the HTML content meaning it displays on top of the HTML content. There used to be an opacity option when adding text via inline scripting, but I'm not sure it was ever working correctly. It has been removed from the 0.6.0 code base.
You may have to wait for the next release, which will include more styling options that would enable what you want to do in HTML (specifically, fixed positioning and CSS translate).
3) I'm not sure you can display a header on every page but the last. There is an option to stop an object from displaying, but it appears to only affect subsequent pages. So you'd have to add the relevant code to the page prior to the last page.
4) If you want to add a font you need to be able to parse it using load_font.php. You will also need access to the executable ttf2afm (dompdf 0.5.1) or ttf2ufm (dompdf 0.6.0). There are instructions on how to load fonts, or you can also try a web-based font prep tool I developed.
确保 dompdf_config.inc.php ~0.6.2 中第 173 行中的 DOMPDF_ENABLE_PHP 设置为 true
请注意,如果 pdf 中存在来自不受信任来源的任何未经过滤的内容,则存在潜在的安全风险。
Make sure that DOMPDF_ENABLE_PHP is set to true in dompdf_config.inc.php ~line 173 in 0.6.2
Be aware that this is a potential security risk if there is any unfiltered content coming from an untrusted source to the pdf.