These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript to set Barcode value during merge

Robin.Marshall
Registered: Sep 27 2011
Posts: 2

Hi,
 
I have a PDF which has some simple fields which are populated from a merge document (tab delimited txt file).
 
The issue I am having is that the barcode which is also on my form, is being set to the same value across each page (the second record from my file), where I require each page to have different barcodes using details obtained during the merge of each record.
 
I would really appreciate some help here, I am up against the wall and have tried to search the forums for assistance, but cannot get past this issue in my document.
 
Any help appreciated.
 
I am using Adobe Acrobat X
 
My PDF, JS file (which goes in C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Javascripts), and data file are found in this zip file
http://dl.dropbox.com/u/8187787/Test.zip
 
Robin

My Product Information:
Acrobat Standard 10.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Nice folder level code, but its got some issues.

1. On line 36 there is an if statement with this condition: (i=1)
Not going to work, this is an assignment statement. But its
not causing any problems, just an inefficiency in the code.

2. The fields in the template are renamed. The getField code must
use the new names. The right way to do this is to make the template
page invisible from the start. Spawn the template first, then
populate the field data.

3. Include a cover sheet for the doc so the new pages can be spawned
starting at page1.

3. Spawn all templates at (this.numPages-1),i.e., after the last page.

4. In a folder level function the keyword "this" is not guaranteed to be
the doc object. Pass the doc object into this function.

To get a feel for how this works, run your code in console window one line at a time. You'll be able to see exactly how the template fields are renamed and where the new pages are placed.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Robin.Marshall
Registered: Sep 27 2011
Posts: 2
Hi Thom,

Thanks for your feedback;

(1) - thanks;

(2) - how would I reference the field in my javascript for a subsequent page. I have tried playing round with this, but not solved it yet. Do I somehow get a reference to the new page as it is spawned and then set the fields within it each time I spawn?

thanks

Robin

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are a couple of ways to approach getting the spawned field names.

Do a test. Run your code, one line at a time from the console window to see what it does to a real document.
After it spawns each page, use the Select Object tool to examine the new field names.

This should give you the info you need to predict the new field names. Basically its based on the new page number. And you know the new page number because it's specified in the "spawn" function.

The second method is to include code in your script to acquire any of the fields on the new page and examine the field name prefix. It will be the same for all fields on the page. But this method is awkward and unnecessary. You can easily predict the new field names.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script