如何根据文本内容显示浮动文本字段? [英] How to display floating textfield depending on the text content?

查看:91
本文介绍了如何根据文本内容显示浮动文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PDF模板(使用Adobe Livecycle Designer设计),该模板具有一个子窗体和一个文本字段.这两个对象的属性设置为float.并将那些对象的高度设置为Autofit.这些对象的所有封闭父级高度都设置为AutoFit.

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.

当我从Adobe设计器中预览模板时,生成的预览PDF将文本字段显示为浮动(基于我输入的测试数据).

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

出于我们的应用目的,我们使用iText.

For our application purposes, we use iText.

基本上,我们加载这些预定义的模板,然后使用iText API将数据填写到这些字段中.

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

我们使用的iText的当前版本是iText 5.1.3

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>");

... 

以此类推.

这样生成的PDF仅显示适合文本框大小的文本,基本上忽略了溢出.

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

希望我已经对所遇到的问题给出了足够的描述.我想动态地嵌入内容并使其余的PDF浮动.我不知道我还能使用iText做到这一点吗?

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?

推荐答案

您正在混合不同的东西.

You're mixing different things.

PDF中有两种类型的表单技术: -AcroForm技术:使用PDF语法描述表单,例如使用字典/字典使用键/值对描述字段,以及使用PDF数组存储字段的坐标,等等.如果使用AcroForm技术,则无法满足您的要求.您使用了错误的技术.通常,这些表单是使用Adobe Acrobat,LibreOffice,...创建的. -XML表单体系结构(XFA):使用XML描述表单. PDF充当XML的容器.通常,这些表单是使用Adobe LiveCycle Designer创建的.

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.

有时表单同时使用两种技术(混合表单),在这种情况下,表单是使用PDF语法以及XML语法定义的.

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

实现所需目标的唯一方法是使用纯dynamix XFA形式.在这种情况下,您不能使用setField()方法.相反,您必须像在本示例中一样使用fillXfaForm(): http://itextpdf.com/examples/iia.php?id=165 或者,您必须使用XFA Worker,可以在此处找到一个演示: http://demo.itextsupport.com/xfademo/

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/

这篇关于如何根据文本内容显示浮动文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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