文本不适合表单字段(iTextSharp) [英] Text not fitting into form fields (iTextSharp)

查看:154
本文介绍了文本不适合表单字段(iTextSharp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Adobe Acrobat Pro创建了一个.PDF文件.该文件有几个文本字段.使用iTextSharp,我可以填充所有字段并邮寄.PDF.

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.

有一件事困扰着我-下一件事不会适合"文本框.在Adobe中,如果我键入的值超过了分配的高度,滚动条会跳出来-当未将字体大小设置为自动且允许多行时会发生这种情况.

One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.

但是,当我尝试设置以下属性时:

However, when I attempt to set the following properties:

//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);

// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);

//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);

但是,在编译后和盖章后,滚动条不会出现在最终的.PDF中.

However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.

我不确定这是否是正确的选择.我在想,也许我应该创建一个表并在其中填充文本,但是文档很少或根本没有引用滚动条....

I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....

推荐答案

展平文档时,将删除所有交互性.期望以展平的形式工作的滚动条类似于期望在打印纸上的工作滚动条.这就是为什么您对这个问题的回答不多的原因:这有点荒谬.

When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.

当用文本填充矩形时,所有不合适的文本将被忽略.这就是为什么有人将字体大小设置为0的原因.在这种情况下,将调整字体大小以使文本合适.我不知道这是否适合您,因为您明确指出字体大小必须为15磅.

When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.

如果您不能更改字体大小,则不应期望AcroForm表单字段能够适应内容. ISO-32000-1很清楚:文本字段的坐标是固定的.

If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.

您唯一的选择是控制iText如何填充字段.我举了一个示例,展示了如何在我的的上下文中执行此操作: MovieAds.cs .在此示例中,我要求字段提供其坐标:

Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:

AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];

此对象为您提供页码f.page和矩形f.position.您可以将这些变量与ColumnText结合使用,以完全按照您想要的方式添加内容(并检查是否已添加所有内容).

This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).

希望您能理解:

  • 在扁平化的表单上没有滚动条是很正常的,
  • 填写字段的标准方法会裁剪不适合的内容,
  • 如果想要自定义结果,则需要做更多的编程.

有关更多信息,请参阅"iText in Action-Second Edition".

For more info: please consult "iText in Action - Second Edition".

这篇关于文本不适合表单字段(iTextSharp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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