Skip to main content
Participant
May 6, 2022
Question

how to pass user input from app.response() to the pdf page

  • May 6, 2022
  • 1 reply
  • 2997 views

Good afternoon.

I am creating an action that will print x number of labels.

i am able to prompt the user for the number of labels needed but i am so far unable to pass that input to the pdf page, i am capturing and running a for loop with the input but i need to 'print it' to the page.

here is the code that i have so far, i added some style hoping that would do the trick but it did not.

 

i am using this.getField() (like the adobe guide suggests) but it returns 0.

 

var labels = app.response("How many labels?");

var f = this.getField("labels").value;

console.println("the number is " + labels);

for (var i = 1; i <= labels; i++){
console.println(i);
}

f.textSize = 16;
f.textColor = color.red;
f.textFont = font.Times;
f.display = display.visible;
console.println("f is " + f);

 

Do you have any suggestions?

 

Thanks.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
May 6, 2022

The doc.getField() function returns the field object. The code you've posted gets the "value" property of the field object. Change it to:

 

var f = this.getField("labels");

 

You'll find this article helpful:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

You're question has nothing to do with the app.response() function.  You're code is using the return value just fine.  

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
May 9, 2022

Thom.

I am able to see in the console that  i am capturing the user input, what I have not figured out how to do is display that input to the acrobat page.

I am not using forms, i have written the code in an action because i also need to create a pdf document with x number of pages, i am able to create that document but i need to display the user input to the page.

 

here is what i have so far:

 

/* Put script title here */

var number = app.response("How many labels?");

var labels = parseInt(number);

console.println("labels type of is " + typeof(labels));

this.createTemplate({cName: "myTemplate", nPage: 0});

// Obtain the template name "myTemplate":
var t = this.getTemplate("myTemplate");
// Prevent file size inflation:
var XO = t.spawn(number, true, true);
// Spawn the remaining pages:
for (var i = 2; i <= number-1; i++)
t.spawn(i, true, true, XO);

for (var counter = 1; counter <= number; counter++){
console.println(counter);
}

var toDisplay = this.getField("labels");
this.getField("labels").textSize = 28;
toDisplay.textColor = color.red;

console.println("this is what labels has " + labels);

 

The this.getField() method returns null with or without the .value

 

Is there a way that for me to display the user input from app.response to the page?

 

greatly appreciated.

Bernd Alheit
Community Expert
Community Expert
May 9, 2022

Where does you set the value of the field?