简体   繁体   English

将文本在多行表单字段中的顶部对齐以动态生成PDF

[英]Align text to top in multiline form fields for dynamically generated PDF

I have a PDF form with text aligned in the middle for multiline fields, I am looking for a script that will execute when the file is opened to align those text to the top instead. 我有一个PDF表单,其中的文本在多行字段的中间对齐,我正在寻找一个脚本,该脚本将在打开文件时执行,以将这些文本与顶部对齐。

It has been created using this converter ( https://www.idrsolutions.com/online-pdf-to-html5-converter ) to generate an HTML version of a PDF form. 它是使用此转换器( https://www.idrsolutions.com/online-pdf-to-html5-converter )创建的,以生成PDF表单的HTML版本。 Then there is a function to convert it back to PDF. 然后有一个将其转换回PDF的功能。

For example with this: https://files.idrsolutions.com/Examples/FDFForms/CVData/form.html 例如: https : //files.idrsolutions.com/Examples/FDFForms/CVData/form.html

You can enter some text and then click the save icon to generate the PDF. 您可以输入一些文本,然后单击保存图标以生成PDF。

Here is the generated file too: https://devcn.000webhostapp.com/temp/sampleAlign.pdf 这也是生成的文件: https : //devcn.000webhostapp.com/temp/sampleAlign.pdf

In the PDF generated the text that appears in the multiline form fields is aligned to the middle. 在生成的PDF中,多行表单字段中显示的文本与中间对齐。 If you edit the text with changes it then aligns it to the top. 如果使用更改来编辑文本,则将其对齐到顶部。 Also if you select the field properties and change the multiline checkbox deselecting and selecting it again the text then too aligns to the top. 同样,如果您选择字段属性并更改多行复选框,则取消选中并再次选择它,则文本也将与顶部对齐。 Would like to automate this somehow so that when the user opens the PDF the texts are aligned to the top. 希望以某种方式自动执行此操作,以便当用户打开PDF时,文本与顶部对齐。

First, multiline text fields in Acrobat always align to the top unless the field is set to allow rich text and the user defines the field to vertically align the text to the middle; 首先,除非将Acrobat中的多行文本字段设置为允许富文本格式并且用户定义该字段以将文本垂直对齐到中间,否则多行文本字段始终对齐顶部。 there is no way to define vertically align center in a typical PDF field programmatically and have it stick through a user edit. 无法通过编程方式在典型的PDF字段中定义垂直对齐的中心,并使其停留在用户编辑中。

What you are seeing when you first open the file is the field appearance which was generated by the converter. 首次打开文件时看到的是转换器生成的字段外观 You can add a script at the document level that toggles the "delay" property which will cause the appearance to be regenerated by the viewer. 您可以在文档级别添加脚本,以切换“延迟”属性,这将导致查看器重新生成外观。 You'd add this to a document level script so it runs when the file is first opened. 您会将其添加到文档级脚本中,以便在首次打开文件时运行。 See code and warning below. 请参阅下面的代码和警告。

nFields = this.numFields;
for (var i = 0; i < nFields; i++) {
    var f = this.getField(this.getNthFieldName(i));
    f.delay = true;
    f.delay = false
}

However, this will only run in a JavaScript capable viewer the can edit PDF like Acrobat and Reader and a few others. 但是,这只能在具有JavaScript的查看器中运行,并且可以编辑Acrobat和Reader等其他PDF。 When I selected your link, it opened in Chrome first, which doesn't execute JavaScript. 选择链接后,该链接会先在Chrome中打开,但不会执行JavaScript。 Unfortunately, non-javascript capable viewers are built into most browsers now so the likelihood of the file first being opened by the user and having your script run is low. 不幸的是,现在大多数浏览器都内置了不支持JavaScript的查看器,因此用户首先打开文件并运行脚本的可能性很小。 You need to fix the appearance in the conversion process, not in the viewer. 您需要在转换过程中而不是在查看器中修复外观。

To do that, either preprocess the HTML so that the appearance generated by the converter matches the properties of the PDF field that will be generated or convince IDR to update their software to create appearances that reflect the properties of the field generated rather than the properties of the HTML field source. 为此,请预处理HTML,以使转换器生成的外观与要生成的PDF字段的属性相匹配,或者说服IDR更新其软件以创建反映所生成字段的属性而不是所生成字段的属性的外观。 HTML字段源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM