pdf Java-PDFBox 中文本的占位符? [英] Placeholders for a text in a pdf Java-PDFBox?

查看:132
本文介绍了pdf Java-PDFBox 中文本的占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能否为 pdf 中的文本制作占位符并用 id(类似于 html 标签)标记它们,然后使用 PdfBox 用我们的文本填充该占位符,无论在 Java 中的长度如何?

Can we make placeholders for a text in a pdf and mark them with an id (similar to html tags) and just fill that placeholder with our text, of whichever length in Java, using PdfBox?

推荐答案

我们可以为 pdf 中的文本制作占位符并用 id 标记它们(类似于 html 标签),然后用我们的文本填充该占位符,无论长度是多少

Can we make placeholders for a text in a pdf and mark them with an id (similar to html tags) and just fill that placeholder with our text, of whichever length

不,至少在没有大量编码的情况下不会.

No, at least not without a great deal of coding around it.

原因是 PDF 是一种用于已完成布局的文档格式.

The reason is that PDF is a format for documents with a finished layout.

如果您用您的文本填充该占位符,无论长度,尤其是在填充长文本的情况下,文档的内容将不得不重新排列,文本跟随占位符必须向下移动,页面正文底部的文本必须移动到下一页,等等.

If you fill that placeholder with your text, of whichever length, in particular in case of filling with a long text, the contents of the document would have to be re-flowed, text following the placeholder would have to be moved down, text already at the bottom of the page body would have to be moved to the next page, etc.

由于 PDF 文档通常不包含有关边距、文本对齐等内容的信息,因此这项任务非常重要.

As PDF documents in general don't contain information on stuff like margins, text alignments, etc., that task is severely non-trivial.

(还有其他问题,例如嵌入的字体子集没有替换文本的字形或背景或边框,没有与背景"或有边框"文本的链接.)

(There also are other issues, e.g. embedded font subsets without the glyphs of your replacement text or backgrounds or borders without linkage to the "backgrounded" or "bordered" text.)

我不知道该任务的自动化通用实现,尤其是在免费的 PDF 库中.

I'm not aware of an automatized general purpose implementation of that task, in particular not in free PDF libraries.

这篇关于pdf Java-PDFBox 中文本的占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆