如何使用IText在PDF的页面中间插入内容 [英] How to insert content in the middle of a page in a PDF using IText

查看:521
本文介绍了如何使用IText在PDF的页面中间插入内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以PDF格式将内容插入页面中间。

I have a requirement to insert Content into the middle of the page in a PDF.

内容可以是动态表格或图像。

The Content may be a Dynamic Table or an Image.

我的概念是首先将PDF分成两部分,然后通过替换占位符字段来获取要添加和追加的新内容。

My Concept was to first split the PDF into 2 parts, then get the new Content that is to be added and append by replacing a place holder field.

根据IText,Splitting称为Tiling,这是一个相同的示例。
http://itextpdf.com/examples/iia.php?id=116

the Splitting is called Tiling as per IText and here is an example for the same. http://itextpdf.com/examples/iia.php?id=116

上面的代码有两个缺点:$ b​​ $ b 1.它将页面拆分为16个部分。但这是示例的一部分。我仍然无法找到一种方法将文件分成两部分。
2.其次,拆分页面将转换为完整页面,从而扰乱其比例。

The Code above has 2 drawbacks: 1. It splits the page into 16 parts. but that is part of the example. Still i cant figure out a way to split the file into 2 parts only. 2. secondly the split page is converted to a complete page thus disturbing its proportions.

重新排列代码是另一个问题。

The Rearranging code is the another problem.

剩余的内容应该在追加模式下重新排序。但直到我找到代码才能添加完整的新页面而不仅仅是内容。

The remaining Content should be re-ordered in append mode. but till yet i have only found codes to add complete new pages rather than just the content.

我找到了一个代码,通过替换占位符来附加PDF内容: / p>

I have found a code that appends the PDF content by replacing a placeholder:

float[] fieldPosition= pdfTemplate.getAcroFields().getFieldPositions("tableField");
PdfPTable table = buildTable();
PdfContentByte cb = stamper.getOverContent(1);
table.writeSelectedRows(0, -1, fieldPosition[1],fieldPosition[4],cb);






请帮我解决此要求。


Please help me to solve this requirement.

推荐答案

PDF是一种表示格式,而不是一种编辑格式。换句话说,它不是为了允许内容插入而设计的,原始内容优雅地回流。因此,没有工具(至少,我所知道的,肯定不是iText)将使您能够实现您的要求。

PDF is a presentation format, not an edition format. In other words, it is not designed to allow content insertion, with the original content reflowing gracefully. As a consequence, no tool (at least, none that I know of, and surely not iText) will enable you to achieve what you were given as a requirement.

My建议:


  • 拒绝分配,因为它不可行,或者

  • 抓住原来的文档,插入所需的额外内容,然后转换为PDF。

  • refuse the assignment since it's not feasible, or
  • get your hands on the original document, insert the desired extra content, and then convert to PDF.

这篇关于如何使用IText在PDF的页面中间插入内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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