简体   繁体   English

PDF JavaScript:将变量的值插入表单字段

[英]PDF JavaScript: Insert value of variable into form field

I have a PDF with JavaScipt, all end users running Adobe Acrobat Pro DC.我有一个带有 JavaScipt 的 PDF,所有最终用户都运行 Adobe Acrobat Pro DC。 I have successfully figure out how to get it to fill a form field with values from other form fields:我已经成功地弄清楚如何让它用其他表单字段的值填充表单字段:

// Assuming FormFieldB has a value of "somewhere" and FormFieldA is a text box

this.getField("FormFieldA").value = "Fills a sentence and adds a string from " + this.getField("FormFieldB").value + " successfully.";

// This fills the box with "Fills a sentence and adds a string from somewhere successfully.

But what I'm trying to do is basically the same thing but I'm trying to take the value of a variable and add it into the form field.但是我想做的基本上是一样的,但我试图获取一个变量的值并将其添加到表单字段中。

var my_variable = "somewhere";

this.getField("FormFieldA").value = "Fills a sentence and adds a string from <How do I insert from my_variable> successfully";

// I want it do write the same example sentence as before

Any ideas?有任何想法吗? Thanks!谢谢!

Just concatenate the strings...只需连接字符串...

var my_variable = "somewhere";

this.getField("FormFieldA").value = "Fills a sentence and adds a string from "+my_variable+" successfully";

If you are using ES6 syntax you can use it this way:如果你使用 ES6 语法,你可以这样使用它:

let my_variable = "somewhere";
this.getField("FormFieldA").value = `Fills a sentence and adds a string from ${my_variable} successfully`;

" ` " is the backtick/string literal operator introduced in ES6 it stands just before the 1 key. “ `” 是 ES6 中引入的反引号/字符串文字运算符,它位于 1 键之前。

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

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