FPDF.php 的文件大小比 TCPDF.php 小约 20 倍?为什么?

发布于 2024-12-05 08:31:51 字数 497 浏览 1 评论 0原文

我知道有很多关于这两个人的帖子,但我想我应该解决一个明显的问题。我们的一位设计师最近向我发送了一些已经绑定了 TCPDF 的文件,因为他的一个朋友说这“更好”。

过去,我们在 PHP 中使用 FPDF 来生成 PDF,但我立即注意到了一个巨大的明显差异:

fpdf.php 的文件大小:46KB

tcpdf.php 的文件大小:996 KB

注意:上面的文件大小是实际大小php 文件,而不是生成的 PDF。

我真的没有太多耐心坐下来查看两者之间的所有差异,但似乎不值得因为巨大的文件差异而进行切换。 SO 上的大多数人似乎真的很喜欢 TCPDF,但是有什么好处呢?

主要问题

为什么大小不同?我是否应该担心我的服务器每天必须加载 1MB 文件数百次或数千次,而 50KB 文件则执行几乎相同的操作?各位,我不是说我的 PDF 文件更大。 PHP 脚本本身的文件大小为 1MB 到 40Kb。

I know there have been a lot of posts about these two but figured I'd address a glaring question I have. A designer of ours recently sent me a few files with TCPDF already tied in because a friend of him said it was "better".

In the past we have used FPDF for everything PDF generation in PHP but right off the bat I noticed an enormous glaring difference:

Filesize of fpdf.php: 46KB

filesize of tcpdf.php: 996 KB

note: the file sizes above are of the actual php file, not the PDF's generated.

I don't really have too much patience to sit down and look at all of the differences between the two but it doesn't seem it is worth the switch really for the huge file difference. Most on SO seem to really like TCPDF but what gives?

Main Question

Why the difference in size and should I be worried for my server having to load a 1MB file hundreds or thousands of times a day versus a 50KB file that does nearly the same thing? I am NOT saying my PDF file larger here folks. The filesize of the PHP script itself is the 1MB to 40Kb.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谈场末日恋爱 2024-12-12 08:31:51

我避免使用 TCPDF,因为它的许可证不友好(您必须在生成的 PDF 文档中保留链接 + 徽标完整)。 (注:许可证似乎已更改,现在是标准 LGPLv3:http://www.tcpdf.org/ license.php

也就是说,文件大小较大的通常原因是嵌入字体。您可以通过多种不同的方式指定字体:

  • 指定字体但不嵌入它们(最小尺寸,但是文本可能无法正确显示)
  • 完全嵌入它们(FPDF 已经支持此功能)
  • 嵌入所使用的字符部分

仅 第一个选项生成最小的文件 - 我猜这就是您在 FPDF 中使用的。请注意,您的 PDF 在不同系统上的显示可能有所不同。

第二个选项会生成最大的文件。由于字体就在那里(理论上 - 我没有这方面的经验)可以编辑文件并添加相同字体的文本。

第三个选项是大多数情况下应该使用的选项,但是,它是最难在库中实现的,并且核心 FPDF 不支持它(但 TFPDF 支持)。它只嵌入所使用的字形,因此它生成的跨平台 PDF 非常小。

几年前,TCPDF 不支持第三个选项(但是,现在可能已经改变)。正如我所提到的,核心 FPDF 也不支持它 - 但是,MPDF 和 TFPDF (我已在许多项目中成功使用它们)支持它。

顺便说一句,我不使用 TCPDF 的另一个原因是 Mr. 的不友好和无助的态度。 Asani(开发人员)与 FPDF / MPDF / TFPDF 社区(Oliver、Ian...)在 FPDF 论坛上的帮助形成鲜明对比。在论坛上沟通了两周后,他才承认 TCPDF 不支持部分字体嵌入。然而,对我来说,真正的障碍是许可证。

因此,回答您的问题:您可以通过不嵌入字体来使 TCPDF 生成较小的文件。然而,许可证应该是从它切换的主要原因。 :)

I avoid TCPDF because of its unfriendly license (you must leave link + logo intact in generated PDF documents). (Note: it seems the license has changed and is now standard LGPLv3: http://www.tcpdf.org/license.php)

That said, the usual cause for larger file size is embedded fonts. You can specify fonts in several different ways:

  • specify them and do not embed them (smallest size, however, text might not display correctly)
  • embed them fully (FPDF already supports this)
  • embed just the parts of characters that are used

The first option produces smallest files - I guess this is what you use with FPDF. Note that your PDF might display differently on different systems.

The second option produces largest files. Since the font is there it is (in theory - I have no experience with this) possible to edit file and add text in the same font.

The third option is the one that should be used in most cases, however, it is the most difficult to implement in libraries and core FPDF does not support it (TFPDF however does). It only embeds glyphs that are used so it produces cross-platform PDFs which are quite small.

The third option was not supported with TCPDF a few years ago (however, this might have changed by now). As I mentioned, it is also not supported in core FPDF - however, it is supported in MPDF and TFPDF (which I have successfully used in many projects).

On a side note, another reason for me not using TCPDF was unfriendly and unhelping attitude of mr. Asani (developer) in contrast with FPDF / MPDF / TFPDF community (Oliver, Ian,...) help on FPDF forum. It took 2 weeks of correspondence on forum before he admitted that TCPDF does not support partial font embedding. However, it is the license that is a real deal-breaker to me.

So, to answer your question: you could make TCPDF produce smaller files by not embedding fonts. However the license should be the main reason for switching from it. :)

掌心的温暖 2024-12-12 08:31:51

我花了一点时间比较了这两个来源。

fpdf几乎没有评论。

tcpdf 有更多的方法,但也有完整的类似 phpDoc 的注释块,在每个方法和属性之前都有每个参数和用法的解释以及 html 格式的示例。我想说这是文件大小很大的主要原因。

i took an instant to compare both sources.

fpdf has almost no comments.

tcpdf has a few more methods but also has full blocks of phpDoc-like comments with explanations of every parameter and usage and examples in html format before every method and property. i'd say that's the main reason for the big file size.

抚你发端 2024-12-12 08:31:51

请注意,TCPDF 许可证上的“您不能从生成的 PDF 文档中删除任何 TCPDF 版权声明或链接”这句话仅指不可见的链接(元数据),而不是出现在默认示例中的标题徽标和链接上。
这意味着使用 TCPDF 生成的文档不包含任何干扰文档布局的可见工件。

然后,为了回答您的问题,文档大小取决于您正在使用的 FPDF 中不存在的新功能。如果您不需要某些功能并且想要减小文档大小,请禁用 Unicode,仅使用像 helvetica 这样的核心字体,并应用 http://www.tcpdf.org 网站。

Note that the sentence "YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS" on the TCPDF license, refers only to an INVISIBLE link (metadata) and not on the header logo and links that appears on the default examples.
This means that the documents produced with TCPDF doesn't contain any visible artifact that interfere with your document layout.

Then, to answer your question, the document size depends by the new features you are using that are not present in FPDF. If you don't need some features and you want to reduce the document size, then disable Unicode, use only core fonts like helvetica and apply the other tips at http://www.tcpdf.org website.

旧瑾黎汐 2024-12-12 08:31:51

TCPDF 比 FPDF 包含更多数百个功能,这就是它更大(更好)的原因。
与 TCPDF 的本质及其功能相比,FPDF 是一个非常原始的库。

TCPDF contains hundreds of features more than FPDF, that's why it's bigger (and better).
FPDF is a very primitive library compared to what TCPDF is and what it can does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文