• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with combining fields and sequential numbering

New Here ,
May 04, 2018 May 04, 2018

Copy link to clipboard

Copied

Hello,

I need some help with a document I'm working on. I'm very much a novice when it comes to javascript and I can't seem to figure this one out.

Essentially I need to combine three fields and then add sequential numbering to the end so that each print would be increase numerically by 1.

Users would enter values into field#1, field#2 and field#3.

For example, field #1 would be two characters (AB), field #2 would be a sequence of six numbers (such as 050418), field #3 would be some other characters (CD).

At the end of the string, I'm looking to add sequential numbering, starting at 0001 and increasing by 1 for each printout.

The final result would be something like this: AB050418CD0001

The next printouts would be AB050418CD0002, AB050418CD0003, AB050418CD0004, etc...

I would typically end up printing a couple thousand of these hence the four spaces for the numbers.

It just makes it look more consistent but I can live without the four spaces if it isn't possible.

Also, it doesn't need to save the numbering as next time the document is opened it would need to reset to 0001. Fields 1, 2, and 3 would be changed by the user the next time it is opened so resetting the numbering would be best.

Is this possible?

Thank you for your help!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

294

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2018 May 05, 2018

Copy link to clipboard

Copied

You say you need to print the file thousands of times. Are you planning to do that by specifying the number of copies in the Print dialog to X, or by opening the Print dialog X times and printing the files once each time?

Because a script like that will only work in the latter scenario...

The alternative is to use a script to generate each print command, and then it will be possible to also change the field's value before each such command.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

LATEST

This will take care of what you describe.  Put it in the mousse up event of your button.  Also I figured you would want the sequential to display somewhere.  It will be displayed in a field named "sequential".  What it does is first prompt the user as to how many copies he wants.  Then it loops x time (the number entered) through a print function designed to process silently while  a thermometer keeps track of what page your are actually printing (tough it is not precise, mine locks after 3 even if the loop is still printing jobs).  The user needs to input a NUMBER when prompted or it will not work.

function printMe(rep){

var myField1 = this.getField("field#1").valueAsString

var myField2 = this.getField("field#2").valueAsString

var myField3 = this.getField("field#3").valueAsString

var prefix = myField1+myField2+myField3

//set print parameters

var pp = this.getPrintParams() ;

var fv = pp.constants.flagValues;

pp.flags |= fv.setPageSize;

pp.interactive = pp.constants.interactionLevel.silent;

//set a thermometer to keep track of what's happening

var t = app.thermometer

t.duration = rep

t.begin()

for (x=1;x<=rep;x++){

t.value = x

t.text = "Processing page "+x

var sRep = String(x)

var aRep = sRep.split("")

while (aRep.length < 4) aRep.unshift("0")

sRep = aRep.join("")

var seq = prefix+sRep

this.getField("sequential").value = seq

this.print(pp)

}

t.end()

}

var rep = Number(app.response({

cQuestion: "How many copies to you need?",

cTitle: "How many",

cLabel: "Number of copies:"

}))

printMe(rep)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines