-
1. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 3, 2014 7:36 AM (in response to MaxCO2012)It's certainly possible to do it with a script, but I'm not sure if it's possible to do it directly from Excel. My guess would be that it's not.
A barcode field in a PDF can be either a Barcode-type field, or it can be a plain-text field with a barcode font (typically 3-of-9) associate with it.
-
2. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 3, 2014 7:43 AM (in response to try67)Can you point me in the direction of some information related to how I can do it via Javascript? I already make sue of some embedded Javascript in my VBA code and it works nicely.
Thanks.
-
3. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 3, 2014 7:47 AM (in response to MaxCO2012)The JS API Reference can be found here: http://www.adobe.com/devnet/acrobat/javascript.html
Basically you need to use the addField method of the Doc object to add the form field, and then you set its properties to what you want (for example, textFont to set the font used by a text field).
-
4. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 3, 2014 8:01 AM (in response to try67)I've been through the JS API and am somewhat familiar with addField. As you probably know, the field types that can be added via addField do not include the barcode field, although I'm sure there is a "good" reason it's not supported. I was just hoping it was buried somewhere else and I just wasn't finding it.
I'll play around with doing what I need via a text field, but it was be so much more elegant and efficient if the bar code field was supported by addField.
Thanks.
-
5. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 3, 2014 8:05 AM (in response to MaxCO2012)It's not documented, but you can add a Barcode field using the addField
method. Just specify the cFieldType parameter as "barcode"... The rest of
the parameters are the same.
-
6. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 3, 2014 8:09 AM (in response to try67)If you are correct, and I'm sure you are, you have just made my life better. What a thing to leave undocumented Adobe.
Thank you again and have a great week!
-
7. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 3, 2014 1:49 PM (in response to MaxCO2012)Thanks again to Gilad D for pointing out the undocumented addField functionality.
Using Gilad's suggestion I have successfully added a barcode field to my PDF via Javascript (through Excel VBA no less); however, I can't seem to push a value to the barcode field like I can with a text field.
When I manually check the properties on the new barcode field, none of the properties (symbology, etc.) have been set as they are when you add a barcode field manually. No defaults roll in when one does thie via script. The field is basically a dead, grey box on the page.
Does anyone know where these properties are documented so I can address them? The JS API has no information and guessing at them seems like a hopeless task.
Thanks.
-
8. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 3, 2014 2:01 PM (in response to MaxCO2012)Yeah, I was afraid of that... This is probably the reason why it's not documented, because it's not fully implemented (yet?).
-
9. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 3, 2014 2:19 PM (in response to try67)So I'm probably back to using a text field and a 3-of-9 font, which might work for what I'm doing if I can find one that will install. Working on that.
-
10. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 4, 2014 12:26 AM (in response to MaxCO2012)The biggest problem with 2D barcode fields is they don't work with Reader unless the file is specially enabled with LiveCycle Reader Extensions with the corresponding usage right, so that would have been your next hurdle.
The tricks with using a 1D barcode font with a text field include finding one that allow at least editable embedding and the need to use JavaScript for including any needed start/stop characters and check digit, but at least the resulting field works with Reader (Win/Mac).
-
11. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 7:12 AM (in response to George_Johnson)Good points. That would certainly be my next obstacle if I used 2D. All I'm trying to do is add an identifying barcode to the top of my documents so they can be automatically filed when they come back. Using text field and a Code39 font is far more simple and probably the way to go.
Can't wait to see what gets in the way during Phase II, building the piece that picks them up and puts them away. Off the shelf might be a option, but anyone can do that. Ha.
Thanks for responding.
-
12. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 4, 2014 7:21 AM (in response to MaxCO2012)Another thing to consider is to generate the barcode using another application and then insert it to the PDF as an image.
-
13. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 7:42 AM (in response to try67)Great suggestion. An aquaintance actually emailed me that same suggestion late last night. Specifically, since my PDFs are generated on the fly from a set of MS Word templates, he suggested I create a static PDF with a barcode field on it and then copy that field from that static PDF after setting the correct value.
Not sure it'll let me do that, but I will give it a go and post back.
George's points cause me to reconsider (and use) a 1D solution, but I'd still like to figure this 2D thing out.
Thanks all.
-
14. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 1:32 PM (in response to MaxCO2012)So I think I have a workable strategy. And one that I can waste away the rest of my week on if I'm not careful.
I created a simple PDF that contains 2 fields; a 2D barcode field and a text field. I added the text field because it seems the simplest way to populate the 2D barcode field is to tie it to a text field. I see no other way to "set" its value. I also set the barcode field to PDF417 symbology.
So then I have my code open this existing PDF, set the value of the text field to whatever I want and save the file, which in turn causes (I believe) the barcode field to resolve itself to the text field value. Simple enough and it works just fine.
Now I would like to copy (via js script) the barcode field noted above to a newly created PDF. I think I may also have to copy the associated text field to the new PDF (and hide it) so the barcode field won't lose its value. Seems like the long way around the barn, but maybe not if it results in getting this 2D barcode into my "created-on-the-fly" PDFs with the correct value.
I promise I searched the API (and the forums, etc.) before asking this but, can anyone help me with the syntax of copying (and maybe pasting) a field from one document to another? I'm not asking anyone to write my code, just get me started in the write (see what I did there?) direction.
All I can seem to find is related to copying field "values". I need to copy the entire "field". And to a specific location.
Thank you Gentlemen.
-
15. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 4, 2014 1:52 PM (in response to MaxCO2012)You can't directly copy a field using code. You can create a field (using
addField) and then copy the properties of the old field into the new one,
but you can't copy the field object itself.
-
16. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 2:05 PM (in response to try67)Well, that's not good news since I doubt I'll be able to copy the barcode properties anymore than I can set them in the first place. And if I could set the field properties I wouldn't need to copy the field from somewhere else.
Back to square One-D.
Thanks for the clarification.
-
17. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 4, 2014 2:12 PM (in response to MaxCO2012)I think there's a better approach similar to what you're doing with your latest attempt. Instead of trying to add a 2D bar code field to the newly created PDF after setting the value of the 2D barcode and then flatten it (using the doc.flattenPages JavaScript method). You can then add a button to the newly created PDF and set its icon (field.buttonSetIcon JavaScript method) to the flattened PDF that contains the 2D barcode. I know this works because I've done it before.
-
18. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 4, 2014 2:12 PM (in response to MaxCO2012)Weren't you going to use images instead of a barcode field?
-
19. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 4, 2014 2:16 PM (in response to George_Johnson)Sigh! I didn't mean to post that without more editing. This is what I meant to say:
I think there might be a better approach similar to what you're doing with your latest attempt. Instead of trying to add a 2D bar code field to the newly created PDF, after setting the value of the 2D barcode you should then flatten the PDF (using the doc.flattenPages JavaScript method). You can then add a button to the newly created PDF and set its icon (field.buttonSetIcon JavaScript method) to the flattened PDF that contains the 2D barcode. I know this works because I've done it before.
You'll just need to set up the button that you create with the appropriate properties, such as "Icon Only" layout, read-only, no background/border color, etc.
-
20. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 2:39 PM (in response to George_Johnson)Yes, I think the image method may be the way to go. I just really wanted to figure this out.
What George suggested is interesting and reads somewhat like the "image" suggestion.
Questions:
Will the PDF file that becomes the button icon need to travel with the PDF containing the icon? I'm guessing (and hoping) not.
And will the barcode field need to be the size of the entire page? I assume it will and I'll no doubt get an answer to both in the process of trying this out.
Very creative!
Thanks.
-
21. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 4, 2014 2:48 PM (in response to MaxCO2012)Once an image has been set as the icon of a button it becomes embedded in the document and you don't need to have the source file anymore.
-
22. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 4, 2014 2:49 PM (in response to MaxCO2012)No, it won't need to travel with the PDF containing the button, and you can make the button any size you want, though it will need to be large enough for the bar code to scan successfully.
-
23. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 2:54 PM (in response to George_Johnson)Understood. The button size I get. I was curious about the size of the barcode field in the PDF I'm going to use the button icon so that there isn't a bunch of white space. I'll stop wondering and just go do it.
-
24. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 4, 2014 3:09 PM (in response to MaxCO2012)I don't mean to wear you guys out but, this button icon method is pretty slick.
I've got to mess around with the scaling to get it just, but this appears to be a really nice solution.
Back later with the results. I know you'll be waiting anxiously! -
25. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 4, 2014 3:35 PM (in response to MaxCO2012)Yes, buttons provide a solution for all types of tricky problems. Some suggestions:
set:
buttonFitBounds property to true
buttonScaleHow to proportionally so that the bar code Y/X ratio is maintained
buttonScaleWhen so that the bar code is always show with the maximum amount of text it will be encoding and the bar code X dimension is maintained.
-
26. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 5, 2014 4:07 PM (in response to George_Johnson)George (or others):
I'm trying to fully understand this button icon method, but I'm getting conflicting results. If you will, please help clarify:
When I create the PDF document that will become the button icon, all I have on the "page" is a reasonably-sized PDF417 barcode field, about 1/2 inch x 4 inches, and I have it centered. When I identify this document as the button icon in another PDF and set the properties of that button as you suggested (or any other way for that matter) the image is indeed there on the button face, but is very small. I would have expected Acrobat to fill the button face with the identified icon PDF using the limits of that documents content, if that makes sense.
When I use another regular PDF document as the icon image that is exactly what happens. It puts all the content on the button face. Any idea why it would not do this for my barcode-holding PDF?
Should I set up the document holding the barcode as something other than 8.5 x 11, or should that even matter?
Thanks.
-
27. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 5, 2014 4:22 PM (in response to MaxCO2012)Just crop the page to the extent of the bar code field.
-
28. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 11:53 AM (in response to George_Johnson)So I lost a few days, but finally found time to try and sort this out. I put the code below in the console and it all seems to work except the buttonSetIcon line, which is the last line. I know this isn't as elegant as it could be (yet), I'm just trying to get it to work. My intent is to make this a folder-level script in the end.
Can anyone tell me where I'm going wrong? Is it a privilege issue?
var bcCoords = ["324", "756", "540", "720"];
var iconFileName = "/C/_Holding Pen/Icon.pdf";
var t = this.addField("bcFormID", "button", 0, bcCoords);
t.display = display.visible;
t.buttonPosition = position.iconOnly;
t.buttonScaleHow = scaleHow.proportional;
t.buttonScaleWhen = scaleWhen.always;
t.buttonFitBounds = true;
var x = this.importIcon("myIcon", iconFileName, 0);
var f = this.getField("bcFormID");
var i = this.getIcon("myIcon")
var y = f.buttonSetIcon(i);
Thanks for any help you can provide.
-
29. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 19, 2014 12:44 PM (in response to MaxCO2012)First off, the rect property needs to be an array of numbers, not strings.
-
30. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 1:03 PM (in response to try67)Wow, thikans. Rookie mistake. Oddly, it puts the button field in the right place at the right size.
-
31. Re: Is there not a method to add a barcode field via Javascript?
try67 Jun 19, 2014 1:07 PM (in response to MaxCO2012)It probably makes the conversion behind the scenes.
So what exactly is going wrong? Does it create the button? Is the Icon object created?
Also, from which context are you running this code?
-
32. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 19, 2014 1:13 PM (in response to MaxCO2012)So what is the return value of the importIcon call? It would be simpler to just use the buttonImportIcon field method rather than creating a document icon and trying to use it.
-
33. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 1:35 PM (in response to George_Johnson)Gilad D:
I'm presently running this in the console. As best as I can tell, all is well until the last line. When I print the icon object (if I'm writng that right) to the console I get an affirmative response, and when I comment out the last line I get a "true", which I also assumed to be confirmation that all the other lines executed successfully. So I will say "yes", the icon object gets created. And the button field is there as well with the properties set correctly. Just no icon.
George:
The return value of the icon call is "0", No Error. And as I wrote above, I can "print" it to ther console and see an object. I agree that the buttonImportIcon method would be simpler, but I couldn't seem to get that to work in the wee hours of last night either. I'll give it another shot.
But, based on how I read the JS API, won't I be prohibited from executing this from a folder level script, or can I do so as long as make it a trusted function?
Thanks.
-
34. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 19, 2014 2:24 PM (in response to MaxCO2012)Yes, you can place it in a trusted function and it will work fine. The general problem with creating a document icon and then a button icon is it needlessly increases the file size since it means two separate icon are created in the document instead of just one. This probably isn't much of a concern for the type of icons you're using though as they should be fairly small.
I just tested your exact code (after correcting the array and specifying a different PDF), and it works just fine, at least in Acrobat Pro 9.5.5.
-
35. Re: Is there not a method to add a barcode field via Javascript?
George_Johnson Jun 19, 2014 2:29 PM (in response to George_Johnson)And Acrobat Pro 11.0.06
-
36. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 3:26 PM (in response to George_Johnson)Thanks George. I'll try it with another PDF and see what happens on this end. And thanks for the heads-up on the duplicative icon.
-
37. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 3:33 PM (in response to MaxCO2012)Well, all I did was use a different PDF and it works for me too. Go figure. Now I just need to figure out what's wrong with the PDF holding the barcode image. Thanks again.
-
38. Re: Is there not a method to add a barcode field via Javascript?
MaxCO2012 Jun 19, 2014 3:45 PM (in response to MaxCO2012)Probably time to wrap up this thread but, I flattened the original PDF holding the barcode and it works with that one too. George actually wrote than in his June 4, 3:16pm post and it just flew by me. Sorry.
All is well. Thanks again!


