How to display floating textfield depending on the text content?

北城以北 提交于 2019-12-11 03:33:30

问题


I have a PDF template (designed using Adobe Livecycle designer), that has a subform and a textfield. The properties of those two objects is set to float. And the height of those objects is set to Autofit. All the enclosing parents heights of these objects were set to AutoFit.

My intention here is to increase the textfield height depending on the text content we enter into the textfield.

When I preview the template from the Adobe designer, the generated preview PDF, displays the textfield as floating (based on the test data I entered).

For our application purposes, we use iText.

Basically, we load these predefined templates, and fill in the data into those fields using iText API.

The current version of iText we use is iText 5.1.3

...

Document document = new Document();
document.open();
PdfReader reader = new PdfReader(<inputTemplate>);
ByteArrayOutputStream aStream2 = new ByteArrayOutputStream();
PdfStamper stamper2 = new PdfStamper(reader, aStream2);
AcroFields form = stamper2.getAcroFields();
form.setField("<fieldname>", "<fieldvalue>");

... 

and so on.

The PDF thus generated displays only text that fits into the size of the textbox, basically ignoring to overflow.

Hopefully, I have given enough description of the problem I am encountering. I want to dynamically embed the content and make rest of the PDF floatable. I wonder how else I can acheive this using iText?


回答1:


You're mixing different things.

There are two types of form technology in PDF: - AcroForm technology: the form is described using PDF syntax, such as PDF dictionaries to describe a field using key/value pairs, and such as PDF arrays to store the coordinates of a field, and so on. If you use AcroForm technology, your requirement can't be met. You're using the wrong technology. Typically these forms are created using Adobe Acrobat, LibreOffice,... - the XML Forms Architecture (XFA): the form is described using XML. The PDF acts as a container for the XML. Typically, these forms are created using Adobe LiveCycle Designer.

Sometimes a form uses both technologies (hybrid forms) in which case the form is defined using PDF syntax as well as XML syntax.

The only way to achieve what you want, is to use pure, dynamix XFA forms. In that case, you can't use the setField() method. Instead, you either have to use fillXfaForm() as is done in this example: http://itextpdf.com/examples/iia.php?id=165 Or you have to use XFA Worker for which you can find a demo here: http://demo.itextsupport.com/xfademo/



来源:https://stackoverflow.com/questions/12270556/how-to-display-floating-textfield-depending-on-the-text-content

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