在java中使用pdfbox将文本覆盖到先前创建的pdf文档上 [英] Using pdfbox in java to overlay text onto previously created pdf document
问题描述
我已经创建了多个 PDF 文档.我试图做的是使用 PDFBox.我需要将文本放在这些创建的文档上的多个位置,但我不想修改这些区域内的文本.例如,可能有一个部分如下 -
I already have several PDF documents that have been created. What I am attempting to do is by using PDFBox. I need to put text into several places on these created documents but I do NOT want to modify the text that is within those areas. For instance, there may be a a section as follows -
姓名:______________________________
NAME: ______________________________
我会将文本放入该区域,但我需要下划线保持相同的长度.我相信最好的解决方案是创建一个文本框或类似的文本框,使其位于该区域上方,以便线条保持相同的长度.
I will put text into that area, but I need the underline to remain the same length. I believe the best solution would be to just create a textbox or similar that goes above the area so the line remains the same length.
换句话说,我不想编辑内联文本,因此它会保持相同的长度.我没有这方面的代码,因为我只是想了解 pdfbox 包.我一直在网上寻找示例,但其中大多数只是展示了如何创建文档,而不是如何更新以前的文档.我该怎么做?
In other words, I do not want to edit the text inline so it will remain the same length. I have no code for this as I am just attempting to understand the pdfbox package. I have been looking for examples online, but most of them just show how to create a document and not how to update a previously document. How do I do this?
推荐答案
我找到了答案并想分享.
I found the answer and wanted to share.
在 pdfbox 包中有一个名为 Overlay 的类.
In the pdfbox package there is a class called Overlay.
PDDocument pdfDocument = new Overlay();
PDDocument final = pdfDocument.overlay(PDDocument firstDoc, PDDocument otherDoc);
firstDoc 将覆盖在 otherDoc 上.十分简单.我只是不知道去哪里看.
firstDoc will be overlaid onto otherDoc. Easy peasy. I just didn't know where to look.
这篇关于在java中使用pdfbox将文本覆盖到先前创建的pdf文档上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!