Skip to main content
JR Boulay
Community Expert
Community Expert
Nov 8, 2019 1:03 PM UTC
Answered

Detect and create barcode fields with JavaScript

I'd like to know how to detect and create barcode fields with JavaScript.

 

The documentation does not mention a "type" barcode:

Valid types are:
button
checkbox
combobox
listbox
radiobutton
signature
text

 

And using this script in the console returns: "text"

console.println(this.getField("Barcode1").type);

 

How to know if a field is a "barcode" field, and how to create one?

 

Thank you

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Nov 8, 2019 5:48 PM UTC

Barcodes are one of those special (enterprise level) money makers for Adobe. If they really wanted to make a general purpose barcode field, they would have done just that, instead of perverting the text field and blocking use of it in Reader. 

 

But, because barcodes require a special diversion of the text field to a different field handler, several of the standard text field properties are missing from barcode fields, such as "multiline" and "comb". You can use this to detect barcode fields, i.e. a text field that throws an exception "InvalidGetError" for the "multiline" property.

 

Of course Adobe could change this at any time, so it is a rather tenous methodology, but so are most things in Acrobat JavaScript 😉  

 

There is of course, no way to create barcode fields with JavaScript. All Adobe would have to do is add a new values to the style property for the type of barcode, and you could reliably create and detect text fields.  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often

4 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
Nov 9, 2019 10:35 AM UTC

Detecting is not a real issue since I can read "barcode" or "codebarre" into field's name.

The main goal was to create a barcode field (QRcode). And so, too bad…

 

Many thanks to the 3T team (Test, Thom and Try67)

😉

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
Nov 8, 2019 10:27 PM UTC

Just a small addendum: If the kind of barcode you want to use has a 1D symbology then you can easily do it with a "normal" text field. You just need to install a font that contains this symbology (like 3-of-9), and then set it as the field's font, and apply a value to it. The nice thing about these fields is that they can be easily edited in Reader, unlike the built-in "barcode" fields, which require a very special (read: expensive) right to become editable in Reader.

Translate
Legend
Nov 8, 2019 1:25 PM UTC

A barcode field *is* a text field. Its additional properties (e.g. PMD dictionary) are  described in here: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf

 

I rather doubt that JavaScript can see or change the PMD properties needed.

Translate
Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Nov 8, 2019 5:48 PM UTC

Barcodes are one of those special (enterprise level) money makers for Adobe. If they really wanted to make a general purpose barcode field, they would have done just that, instead of perverting the text field and blocking use of it in Reader. 

 

But, because barcodes require a special diversion of the text field to a different field handler, several of the standard text field properties are missing from barcode fields, such as "multiline" and "comb". You can use this to detect barcode fields, i.e. a text field that throws an exception "InvalidGetError" for the "multiline" property.

 

Of course Adobe could change this at any time, so it is a rather tenous methodology, but so are most things in Acrobat JavaScript 😉  

 

There is of course, no way to create barcode fields with JavaScript. All Adobe would have to do is add a new values to the style property for the type of barcode, and you could reliably create and detect text fields.  

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often