public final class FormBarCode extends FormElement
A type of form element representing a BarCode. Barcode fields were added to Acrobat 7 as part of the XFA standard, and although they only became an official part of PDF as of PDF 2.0 (ISO-32000-2) they should be usable in Acrobat 7 or later (although they may not be usable in other PDF viewers).
Barcode fields are typically used to represent the contents
of other fields in the form, the idea being that if the form
is printed rather than electronically submitted, the BarCode
can be scanned to retrieve the form contents. The way to do
this is by adding an Event.OTHERCHANGE
action to the
field to recalculate its value based on the other fields
(although there should be other ways to do this, they're
unlikely to work in Acrobat so this is the only recommended
approach).
Here's a very simple example:
// create main form elements and add to form form.put("Name", namefield); form.put("Address", addressfield); String js = "var fields = [ 'Name', 'Address' ]; \ var val = ''; \ for (var f=0;f<fields.length;f++) { \ val = this.getField(fields[i]).value + '\t'; \ } \ event.value = val;"; FormBarCode barcode = new FormBarCode(); barcode.setSymbology("QRCode"); barcode.setECC(1); barcode.setSymbolSize(0.5f); barcode.addAnnotation(page, 100, 100, 150, 150); barcode.setAction(Event.OTHERCHANGE, PDFAction.formJavaScript(js)); barcode.setValue(namefield.getValue()+"\t"+addressfield.getValue()); form.put("BarCode", barcode);
Modifier and Type | Field and Description |
---|---|
static int |
COMPRESSION_ADOBE
Barcode is Flate-compressed, with Adobe's "special sauce" - a two byte prefix
of unknown purpose.
|
static int |
COMPRESSION_FLATE
Barcode is Flate-compressed, without any prefix.
|
static int |
COMPRESSION_NONE
Barcode is encoded with a value that is not compressed.
|
Constructor and Description |
---|
FormBarCode()
Create a new BarCode field
|
FormBarCode(PDFPage page,
float x1,
float y1,
float x2,
float y2)
Create a new BarCode field and add an annotation for it to the page
|
Modifier and Type | Method and Description |
---|---|
WidgetAnnotation |
addAnnotation(PDFPage page,
float x1,
float y1,
float x2,
float y2)
Create and add a new widget annotation for this field.
|
int |
getCompression()
Returns the type of compression the field is stored with, as
specified by
setCompression(int) |
int |
getECC()
Return the error correction level, as set by
setECC(int) |
String |
getSymbology()
Return the BarCode symbology as set by
setSymbology(java.lang.String) |
float |
getSymbolSize()
Return the symbol size, as set by
setSymbolSize(float) |
static String |
getTabDelimiteredJavaScript(Collection<String> names,
boolean includenames)
Return the JavaScript used by Acrobat to set a BarCode to a tab-delimetered
list of field names.
|
static String |
getTabDelimiteredJavaScriptSetup()
If using the JavaScript returned by
getTabDelimiteredJavaScript(java.util.Collection<java.lang.String>, boolean) ,
you must apply the JavaScript return by this method to the PDF, as in the
following example:
String js = FormBarCode.getTabDelimiteredJavaScript(Arrays.asList(new String[] { "Name", "Address" }), true); barcode.setAction(Event.OTHERCHANGE, PDFAction.formJavaScript(js)); form.addElement("BarCode", barcode); pdf.setJavaScript(pdf.getJavaScript() + FormBarCode.getTabDelimiteredJavaScriptSetup()); |
String |
getValue()
Returns the value of this field
|
void |
rebuild()
Cause the annotation list to be rebuilt.
|
void |
setCompression(int compression)
Set whether the BarCode value should be compressed by Flate compreesion
first.
|
void |
setECC(int ecc)
Sets the error correction coefficient (PDF417 and QRCode only).
|
void |
setSymbology(String symbology)
Sets the type of BarCode symbology
|
void |
setSymbolSize(float mm)
Set the symbol size in mm - this is the size of the smallest
unit in the BarCode, and is typically in the region of 0.5 to 1.
|
void |
setValue(String value)
Sets the value of this field
|
String |
toString() |
addPropertyChangeListener, duplicate, flatten, getAction, getAnnotation, getAnnotations, getDescription, getForm, isReadOnly, isRequired, isSubmitted, removePropertyChangeListener, setAction, setDescription, setReadOnly, setRequired, setSubmitted
public static final int COMPRESSION_NONE
public static final int COMPRESSION_ADOBE
public static final int COMPRESSION_FLATE
public FormBarCode()
public FormBarCode(PDFPage page, float x1, float y1, float x2, float y2)
page
- the page for the widgetx1
- the left-most X co-ordinate of the annotationy1
- the bottom-most Y co-ordinate of the annotationx2
- the right-most X co-ordinate of the annotationy2
- the top-most Y co-ordinate of the annotationpublic WidgetAnnotation addAnnotation(PDFPage page, float x1, float y1, float x2, float y2)
page
- the page for the widgetx1
- the left-most X co-ordinate of the annotationy1
- the bottom-most Y co-ordinate of the annotationx2
- the right-most X co-ordinate of the annotationy2
- the top-most Y co-ordinate of the annotationpublic String getValue()
getValue
in class FormElement
public void setValue(String value)
value
- the new valuepublic void setCompression(int compression)
COMPRESSION_NONE
,
COMPRESSION_FLATE
,
COMPRESSION_ADOBE
public void setSymbology(String symbology)
symbology
- one of PDF417
, QRCode
, or DataMatrix
public void setSymbolSize(float mm)
BarCode
class, whereas Acrobat's UI asks for the
units in points: for conversion, 2.8mm = 1pt.mm
- the size of the smallest unit in the BarCode, in mmgetSymbolSize()
public void setECC(int ecc)
ecc
- the error correction coefficientpublic String getSymbology()
setSymbology(java.lang.String)
public int getECC()
setECC(int)
public float getSymbolSize()
setSymbolSize(float)
setSymbolSize(float)
public int getCompression()
setCompression(int)
public void rebuild()
FormElement
rebuild
in class FormElement
public static String getTabDelimiteredJavaScript(Collection<String> names, boolean includenames)
FormBarCode barcode = new FormBarCode(); String js = FormBarCode.getTabDelimiteredJavaScript(Arrays.asList(new String[] {"Name, "Address"}), false); barcode.setAction(Event.OTHERCHANGE, PDFAction.formJavaScript(code)); pdf.setJavaScript(pdf.getJavaScript() + FormBarCode.getTabDelimiteredJavaScriptSetup());Note that although this is the approach used by Acrobat, the generated JavaScript is a mess and you could probably do better yourself - there's no reason to rely on this JavaScript, and it's here for convenience only.
names
- the list of field names to include in the barcode value, or null for all fieldsincludenames
- whether to include the list of field names in the valuegetTabDelimiteredJavaScriptSetup()
public static String getTabDelimiteredJavaScriptSetup()
getTabDelimiteredJavaScript(java.util.Collection<java.lang.String>, boolean)
,
you must apply the JavaScript return by this method to the PDF, as in the
following example:
String js = FormBarCode.getTabDelimiteredJavaScript(Arrays.asList(new String[] { "Name", "Address" }), true); barcode.setAction(Event.OTHERCHANGE, PDFAction.formJavaScript(js)); form.addElement("BarCode", barcode); pdf.setJavaScript(pdf.getJavaScript() + FormBarCode.getTabDelimiteredJavaScriptSetup());
public String toString()
Copyright © 2001-2017 Big Faceless Organization