FPDF、FPDI - 使用源文档中嵌入的字体

发布于 2024-07-27 13:01:44 字数 353 浏览 6 评论 0原文

我正在使用 FPDF / FPDI 构建 PDF 模板系统。 一个 PDF 用作背景,并在其中定义了许多可编辑区域(存储在数据库中)。 可编辑区域可以是图像、文本或两者,但这不是我的问题,只是一些背景。

一些背景(FPDI 源 PDF)PDF 或“模板”包含嵌入字体,我希望能够实现两件事,并且想知道这是否可能。

  1. 我希望能够在输出文档中使用源文档中嵌入的任何字体。
  2. 我需要枚举这些字体,以便将它们包含在 UI 的字体列表中。

需要明确的是,我想重用这些字体,不仅仅是将它们应用于导入的页面,而且提供以其中一种嵌入字体呈现新文本的选项。

任何指示将不胜感激。

I am using FPDF / FPDI to build a PDF templating system. One PDF is used as the background and has a number of editable regions defined within it (stored in database). An editable region could be an image, a text, or both, however this is not my question, just a bit of background.

Some of the backgrounds (FPDI source PDF) PDFs or 'templates' contain embedded fonts, I want to be able to achieve two things and was wondering if this is possible.

  1. I want to be able to use any fonts embedded in the source document in the output document.
  2. I need to enumerate these fonts so that they can be included in the UI's font list.

To be clear I want to reuse these fonts, not just have them applied to the imported page, but offer the option to render new text in one of the embedded fonts.

Any pointers would be greatly appreciated.

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

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

发布评论

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

评论(3

旧情别恋 2024-08-03 13:01:44

首先是字体和 PDF。
如果我没记错的话,当一种字体包含在 PDF 中时,可以包含所有字体,或者可以嵌入覆盖实际使用的字符面孔的字体子集。 一些 PDF“压缩”工具可以从 pdf 文件中去除未使用的字体字形。 (有人可以确认/反驳这一点吗?)

至于FPDF(这是我使用的库),我认为它不能在“编辑”模式下打开PDF。 它可以简单地打开 PDF 并将其用作背景 - 实际上是文档的图像。 快速浏览一下所提供的脚本似乎没有显示任何可以真正打开 PDF 文件的脚本(除了只能获取文档元信息的脚本之外)。

PDF 库还有其他选项。 我在下面的演示中看到的 TCPDF 演示表明 TCPDF 可能比 FPDF 具有更多内置功能。 那个图书馆可能值得一看吗?
http://suburbanchicagophp.org/archives/75

First on fonts and PDFs.
If I remember correctly, when a font gets included into a PDF, all of the font can be included, or just a subset of the font covering the character faces actually being used can be embedded. Some of the PDF 'compression' tools can strip the unused font glyphs from the pdf file. (Can someone confirm/refute this?)

As for FPDF (it's the library I use), I don't think it can open a PDF in 'edit' mode. It can simply open a PDF and use it as a background - effectively an image of the document. A quick look through the contributed scripts appears to show no scripts that will open a PDF file for real (besides one that can just get the meta-info on the document).

There are other options for PDF libraries. The demonstration of TCPDF I saw at the following presentation, showed that TCPDF may have more in-built capabilities the FPDF. It may be worth a look into that library?
http://suburbanchicagophp.org/archives/75

溺渁∝ 2024-08-03 13:01:44

我是最初的提问者,但我丢失了临时帐户,因此无法发表评论(如果可以的话,请管理员合并)。

只是为了澄清。

由于 FPDI 网站上详细介绍了兼容性问题,我们选择使用 FPDF 而不是 TCPDF,因为 FPDI 是其中的核心组件,放弃 FPDI 不是一个选择。

我们使用 FPDI 从模板文档中提取页面,然后将文本和图像(使用 Web UI 在数据库中定义)放置在每个页面的顶部,因此用法与 FPDI 允许的完全一样。

我在这个板上发现了另一个问题,询问有关从 pdf 文件中提取嵌入字体的问题,提问者被认为有侵犯版权的活动,这是一个巨大的假设。

如何从 PDF 文件中提取字体Perl?

我们的模板将来自我们的设计师,我们希望在模板 pdf 中重新使用(而不是提取)字体。

这些就是我们的字体,我们只是不希望该 pdf 通过进行编辑的每台机器不仅必须具有可嵌入的字体,而且还必须选择并嵌入正确的字体。 它会导致对字体的双重甚至三重处理,并可能导致一些猜测工作。

上面帖子中的回复之一是一个非常有用的方向,它是一个可以枚举嵌入字体的 Perl 模块,这正是我在 UI 字体列表中显示嵌入字体所需要的。

现在我需要测试源(模板)pdf 中嵌入的字体是否会传递到新的 pdf 中,我认为它们一定是这样,因此必须有一种合理的方式来重用它们。

当我确定时,我会回复完整性,但如果有人对此有任何反馈或知识,我们将不胜感激。

ps,一些编辑器会创建压缩的 pdf 文档并删除一些未使用的字体,这是正确的,但是,对我们来说,这是一个简单的请求,不要使用执行此操作的编辑器,否则您将不得不重新嵌入字体。

I am the orginal question asker, but I lost my temp account so cant comment (admin please merge if you can).

Just to clarify.

We have chosen to use FPDF over over TCPDF due to compatibility problems detailed on the FPDI website as FPDI is the core component in this, dropping FPDI was not an option.

We use FPDI to pull pages from the template document, and we then place text and images (as defined in the database using a web UI) over the top of each page, so the usuage is exactly as FPDI allows.

I found another question on this board asking about pulling embedded fonts from pdf files, the asker was slated for copyright infringing activites which is a huge assumption.

How can I extract fonts from a PDF file with Perl?

Our templates will be coming from our designers, we want to resuse (rather than extract) fonts in the template pdf.

So these are our fonts, we just dont want every machine this pdf passes through for editing to have to not only have the font available to embed, but also to select and embed the correct font. It leads to double, even tripple handling of fonts, and possibly some guess work.

One of the replies in the above post is a very helpful direction, it is a Perl module that can enumurate embeded fonts, which is exctly what I need to display embeded fonts in the UI font list.

Now I need to test if the fonts embedded in a source (template) pdf are carried across to the new pdf, I presume they must be, so there must be a resonable way to reuse them.

Ill post back for completelness when I know for sure, still if anyone has any feedback or knowledge on this it would be greatly appreciated.

p.s. it is correct that some editors will create compressed pdf documents and strip some of the unused font, however it is a simple request for us to say dont use an editor that does this, or you will have to re-embed the font.

月光色 2024-08-03 13:01:44

为了进一步澄清这一点,Zend_PDF 将允许这种确切的功能,枚举然后重用嵌入 PDF 中的字体,但它不能与 v1.4 之后的 PDF 一起使用,但对于 v1.4 pdf,Zend 工作得很好:

例如以下在 Zend_PDF 中是可能的,然后可以通过名称重用字体:

public static function GetFontList($background)
{
     $pdf = Zend_Pdf::load($background);
     $fonts = array(); 
     // Get all document fonts
     $fontList = $pdf->extractFonts();

    foreach ($fontList as $font) 
    {
        $fontName = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
        $fonts[] = $fontName;
    }

    return $fonts;
}

希望这对某人有帮助,但是我需要比 1.4 更高的 pdf 版本,所以我想我正在考虑修改 FPDI。

To further clarify this, Zend_PDF will allow for this exact functionality, enumerating and then reusing fonts embeded in a PDF, but it will not work with PDF later than v1.4, with v1.4 pdf however Zend works very well:

e.g the following is possible in Zend_PDF and then a font can reused by name:

public static function GetFontList($background)
{
     $pdf = Zend_Pdf::load($background);
     $fonts = array(); 
     // Get all document fonts
     $fontList = $pdf->extractFonts();

    foreach ($fontList as $font) 
    {
        $fontName = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
        $fonts[] = $fontName;
    }

    return $fonts;
}

Hopefully this will be helpful to someone, however I need a higher pdf versions than 1.4 so I guess I am looking to modify FPDI.

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