Skip to main content
August 5, 2016
Answered

Adding flattenable text to a PDF through Javascript

  • August 5, 2016
  • 1 reply
  • 2876 views

Dear Adobe Experts,

I have been trying to add text to a PDF file through JavaScript for the past 4 hours. I have gotten the hang of multiple Adobe JavaScript guides. I have looked thorough fully but cannot solve this problem: adding a text box/text to a PDF page using JavaScript and then being able to flatten it successfully.

I have been using the addField with text as an option but when flattened the text box disappears. I will try to mess around with the button option and try to flatten it but I am weary of possible bugs

Here is my code:

var f = this.addField("info", "text", 0, [5,5, 250,25]);
f.delay = true;

f.alignment = "center";
f.fillColor = color.white;
f.lineWidth = 1;
f.strokeColor = color.red;
f.borderStyle = style.s;
f.textSize = 24;
f.textColor = color.black;
f.textFont = font.Arial;
f.defaultValue = "Receive Stamp";
f.editable = false;
f.multiline = false;
f.doNotScroll = true;

f.delay = false;

Any help would be appreciated,

Good day

This topic has been closed for replies.
Correct answer try67

There's a mistake in your code, which prevents the value from being set.

Are you running this code from the JS Console? If so, what happens when you run it?

Edit: There's more than one mistake, actually...

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 5, 2016

There's a mistake in your code, which prevents the value from being set.

Are you running this code from the JS Console? If so, what happens when you run it?

Edit: There's more than one mistake, actually...

August 5, 2016

I test it by executing an action that executes JS code. All of these lines of codes are validated by what I read on the Adobe JS documentation

When I execute it, everything works out but for the defaultValue and the fillColor. I have been trying to test what makes it go wrong by placing a specific line at different spots but to no avail

try67
Community Expert
Community Expert
August 5, 2016

Make the change I described to the preferences and then run the code from the JS Console. You'll see the errors I'm referring to.