Placeholders for a text in a pdf Java-PDFBox?

喜你入骨 提交于 2019-12-11 05:02:53

问题


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?


回答1:


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.

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.

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.)

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



来源:https://stackoverflow.com/questions/49729775/placeholders-for-a-text-in-a-pdf-java-pdfbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!