Add a Barcode to Your Own Form
You need the PixelBinary download and a PDF editor that can do three things: add form fields, use an installed font in a field, and add JavaScript to the document. The steps below name the places in Adobe Acrobat Pro; other editors have the same settings under other names.
1. Install the fonts
Unzip the download and install both files in the fonts folder (on Windows: right-click > Install). Restart your PDF editor so it sees them.
| Font | A filled square is | Used by |
|---|---|---|
| PixelBinary-010101 | 1.0 × 1.0 of the font size | Adobe Acrobat and Acrobat Reader |
| PixelBinary Tall135 | 1.35 × 1.35 of the font size | Viewers built on pdf.js (Firefox, DocuWrit) |
2. The field people type into
Any text field will do. In this guide it is called Text.
3. Two fields where the barcode goes
Add a text field named QR where the barcode should appear, 200 × 200 points (about 2.8 inches or 7 cm square):
| Setting | Value | In Acrobat Pro |
|---|---|---|
| Read only | on | General tab |
| Multi-line | on | Options tab |
| Scroll long text, check spelling | off | Options tab |
| Font | PixelBinary-010101 | Appearance tab |
| Font size | any fixed size, for example 5 (the script changes it; not “Auto”) | Appearance tab |
| Border and fill colour | none | Appearance tab |
| Alignment | left | Options tab |
Then add a second field of the same size in exactly the same place, named QRTall, with the same settings except: font PixelBinary Tall135, font size 2. Leave it empty.
The names are yours to choose, but the second field must be the first name plus Tall. Why two fields: see Which PDF programs run it.
4. Add the script to the document
Open PixelBinary-script.js from the download in a text editor and copy all of it. In Acrobat Pro open the JavaScript tool (All tools > Use JavaScript; in older versions Tools > JavaScript), choose Document JavaScripts, type a name such as PixelBinary, choose Add, replace everything Acrobat put into the editor with what you copied, and confirm.
5. Redraw the barcode when the text changes
Open the properties of the field Text. On the Validate tab choose Run custom validation script and enter one line:
| For a | Script |
|---|---|
| QR code | PixelBinary.show(this, "QR", PixelBinary.qr(event.value)); |
| Data Matrix code | PixelBinary.show(this, "QR", PixelBinary.datamatrix(event.value)); |
"QR" is the name of your barcode field. Save the form, type something into Text and leave the field: the barcode appears.
Good to know
- Size. The script picks the largest font size at which the whole code fits. It assumes fields of 200 points: for another size, change
box: 196near the top of the glue part of the script to your field size less 4. - Longer texts make smaller squares. Keep the text short, or make the field bigger. The example limits the text to 200 characters; set a character limit on your own text field too.
- White margin. The script adds the empty margin a scanner needs. Do not put anything right against the field.
- A barcode from several fields. Build the text yourself:
PixelBinary.show(this, "QR", PixelBinary.qr(this.getField("Name").value + "|" + this.getField("ID").value));— put the line into the Validate script of each field involved, usingevent.valuefor the field the script belongs to. - Starting barcode. A new form shows a barcode only after the text has been changed once. Type the starting text and save the form before you hand it out.
- Scan it. Before you rely on a form, scan what it produces with the scanner or the phone that will be used.
Next: Which PDF programs run it.