How to insert content in the middle of a page in a PDF using IText

ε祈祈猫儿з 提交于 2019-12-10 10:45:17

问题


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.

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.


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

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.

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.


回答1:


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 advice :

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


来源:https://stackoverflow.com/questions/12073135/how-to-insert-content-in-the-middle-of-a-page-in-a-pdf-using-itext

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