php 动态创建带有背景图像的 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5006153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:31:16  来源:igfitidea点击:

Dynamically create a PDF with a background image

phppdf

提问by Daelan

I'm trying to dynamically create a PDF (on the server) with some text on top of a pre-defined background image. I'm using PHP and I can't seem to find anyway to do this.

我正在尝试动态创建一个 PDF(在服务器上),在预定义的背景图像顶部带有一些文本。我正在使用 PHP,但我似乎无法找到这样做的方法。

I've looked into http://www.fpdf.org/and a bunch of other options.

我查看了http://www.fpdf.org/和一堆其他选项。

I'm not opposed to using Flash either if it will do the trick.

我也不反对使用 Flash,如果它可以奏效的话。

Does anyone have any ideas on how to get this to work?

有没有人对如何让它发挥作用有任何想法?

回答by Sam

With FPDFyou can do it like this:

使用FPDF,您可以这样做:

$fpdf = new FPDF();
$fpdf->AddPage();
$fpdf->Image('background-image.png', 0, 0, $fpdf->w, $fpdf->h);
$fpdf->Output();

Old question I know, but this might help someone.

我知道老问题,但这可能对某人有所帮助。

回答by Tokk

You should take a look at thisclass, I really love it. It renders HTML to PDF, and if you define a Background-Image with CSS it will be in the created PDF.

你应该看看门课,我真的很喜欢它。它将 HTML 呈现为 PDF,如果您使用 CSS 定义背景图像,它将在创建的 PDF 中。

回答by wimvds

Another good alternative is TCPDF, it also supports (basic) HTML as output. Just look at the TCPDF Examplesfor a quick overview of what it can do (Example 51 might be helpful for you).

另一个不错的选择是TCPDF,它也支持(基本)HTML 作为输出。只需查看TCPDF 示例,即可快速了解其功能(示例 51 可能对您有所帮助)。

回答by BrianS

Also, dompdf.

另外,dompdf

You were thinking too hard about what you wanted to do ;) ... always start with something you're familiar with (PHP, HTML) and see if there's something that will create the desired result (PDF). For a full list of converters you could try see the community wiki List of HTML to PDF converters(it covers more than just PHP-based libraries).

你想得太多了;) ...总是从你熟悉的东西(PHP、HTML)开始,看看是否有什么东西可以创造出想要的结果(PDF)。有关转换器的完整列表,您可以尝试查看社区 wiki的 HTML 到 PDF 转换器列表(它不仅涵盖基于 PHP 的库)。