aspose.barcode
Version:
barcode generation and recognition component
1,862 lines (1,663 loc) • 279 kB
JavaScript
const fs = require("fs");
const java = require('java');
const joint = require("./Joint");
/**
* BarcodeGenerator for backend barcode images generation.
* supported symbologies:
* 1D:
* Codabar, Code11, Code128, Code39Standard, Code39Extended
* Code93Standard, Code93Extended, EAN13, EAN8, Interleaved2of5,
* MSI, Standard2of5, UPCA, UPCE, ISBN, GS1Code128, Postnet, Planet
* EAN14, SCC14, SSCC18, ITF14, SingaporePost ...
* 2D:
* Aztec, DataMatrix, PDf417, QR code ...
* @example
* // This sample shows how to create and save a barcode image.
* let encode_type = EncodeTypes.CODE_128;
* let generator = new BarcodeGenerator(encode_type);
* generator.setCodeText("123ABC");
*/
class BarcodeGenerator extends joint.BaseJavaClass
{
parameters;
static get javaClassName()
{
return "com.aspose.mw.barcode.generation.MwBarcodeGenerator";
}
/**
* BarcodeGenerator constructor.
* @param encodeType Barcode symbology type. Use EncodeTypes class to setup a symbology
* @param codeText Text to be encoded.
* @code
* let barcodeGenerator = new BarcodeGenerator(EncodeTypes.EAN_14, "332211");
* @encode
* @throws BarcodeException
*/
constructor(encodeType, codeText)
{
let java_class_link = java.import(BarcodeGenerator.javaClassName);
let java_class = new java_class_link(encodeType, codeText);
super(java_class);
this.init();
}
static construct(javaClass)
{
let barcodeGenerator = new BarcodeGenerator(0, "");
barcodeGenerator.setJavaClass(javaClass);
return barcodeGenerator;
}
init()
{
this.parameters = new BaseGenerationParameters(this.getJavaClass().getParametersSync());
}
/**
* Generation parameters.
* @return BaseGenerationParameters
*/
getParameters()
{
return this.parameters;
}
/**
* Barcode symbology type.
*/
getBarcodeType()
{
return this.getJavaClass().getBarcodeTypeSync();
}
/**
* Barcode symbology type.
*/
setBarcodeType(value)
{
this.getJavaClass().setBarcodeTypeSync(value);
}
/**
* Generate the barcode image under current settings.
* This sample shows how to create and save a barcode image.
* @param {BarCodeImageFormat} format BarCodeImageFormat value (PNG, BMP, JPEG, GIF)
* @example
* let generator = new BarCodeGenerator(EncodeTypes.CODE_128);
* let image = generator.generateBarCodeImage(BarCodeImageFormat.GIF);
* @return {String} base64 representation of image.
*/
generateBarCodeImage(format)
{
try {
let base64Image = this.getJavaClass().generateBarCodeImageSync(format);
return (base64Image);
} catch (e) {
throw new joint.BarcodeException(e)
}
}
/**
* Save barcode image to specific file in specific format.
* @param {String} filePath Path to save to.
* @param {BarCodeImageFormat} format BarCodeImageFormat value (PNG, BMP, JPEG, GIF)
* @example
* let generator = new BarCodeGenerator(EncodeTypes.CODE_128);
* generator.save("file path", BarCodeImageFormat.GIF);
*/
save(filePath, format)
{
let image64 = this.generateBarCodeImage(format);
let buff = Buffer.from(image64, 'base64');
fs.writeFileSync(filePath, buff);
}
/**
* Text to be encoded.
*/
getCodeText()
{
return this.getJavaClass().getCodeTextSync();
}
/**
* <p>
* <p>
* Encodes the Unicode {@code <b>codeText</b>} into a byte sequence using the specified {@code <b>encoding</b>}.
* UTF-8 is the most commonly used encoding.
* If the encoding supports it and {@code <b>insertBOM</b>} is set to {@code true}, the function includes a
* {@code <a href="https://en.wikipedia.org/wiki/Byte_order_mark#Byte-order_marks_by_encoding">byte order mark (BOM)</a>}.
* </p>
* <p>
* This function is intended for use with 2D barcodes only (e.g., Aztec, QR, DataMatrix, PDF417, MaxiCode, DotCode, HanXin, RectMicroQR, etc.).
* It enables manual encoding of Unicode text using national or special encodings; however, this method is considered obsolete in modern applications.
* For modern use cases, {@code <a href="https://en.wikipedia.org/wiki/Extended_Channel_Interpretation">ECI</a>} encoding is recommended for Unicode data.
* </p>
* <p>
* Using this function with 1D barcodes, GS1-compliant barcodes (including 2D), or HIBC barcodes (including 2D) is not supported by the corresponding barcode standards and may lead to unpredictable results.
* </p>
* </p><p><hr><blockquote><pre>
* <p>This example shows how to use {@code SetCodeText} with or without a BOM for 2D barcodes.</p>
* <pre>
* //Encode codetext using UTF-8 with BOM
* let gen = new BarcodeGenerator(EncodeTypes.QR, null);
* gen.setCodeText("車種名", "UTF-8", true);
* gen.save("barcode.png", BarCodeImageFormat.PNG);
*
* let reader = new BarCodeReader("barcode.png", null, DecodeType.QR);
* let results = reader.readBarCodes();
* for(let i = 0; i < results.length; i++)
* {
* let result = results[i];
* console.log("BarCode CodeText: " + result.getCodeText());
* }
* //Encode codetext using UTF-8 without BOM
* let gen = new BarcodeGenerator(EncodeTypes.QR, null);
* gen.setCodeText("車種名", "UTF-8", false);
* gen.save("barcode.png", BarCodeImageFormat.PNG);
* let reader = new BarCodeReader("barcode.png", null, DecodeType.QR);
* let results = reader.readBarCodes();
* for(let i = 0; i < results.length; i++)
* {
* let result = results[i];
* console.log("BarCode CodeText: " + result.getCodeText());
* }
* </pre>
* </pre></blockquote></hr></p>
* @param codeText CodeText string
* @param encoding Applied encoding
* @param insertBOM
* Indicates whether to insert a byte order mark (BOM) when the specified encoding supports it (e.g., UTF-8, UTF-16, UTF-32).
* If set to {@code true}, the BOM is added; if {@code false}, the BOM is omitted even if the encoding normally uses one.
*
*/
setCodeText(codeText, encoding, BoM)
{
if (Array.isArray(codeText)) {
this.getJavaClass().setCodeBytesSync(Buffer.from(codeText));
}
else
{
let adaptedBoMStr = BoM == null ? null : BoM.toString();
this.getJavaClass().setCodeTextSync(codeText, encoding, adaptedBoMStr);
}
}
/**
* Exports BarCode properties to the xml file specified
* @param filePath The xml file
* @return Whether or not export completed successfully. Returns <b>True</b> in case of success; <b>False</b> Otherwise </para>
* @throws IOException
*/
exportToXml(filePath)
{
try {
let xmlData = this.getJavaClass().exportToXmlSync();
let isSaved = xmlData != null;
if (isSaved) {
fs.writeFileSync(filePath, Buffer.from(xmlData, 'base64').toString('utf-8'));
}
return isSaved;
} catch (ex) {
throw new joint.BarcodeException(ex);
}
}
/**
* <p>
* Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.
* </p>
* @return BarcodeGenerator instance
* @param filePath The name of the file
*/
static importFromXml(filePath)
{
try {
let xmlData = joint.convertImageResourceToBase64(filePath);
// let offset = 6;
// xmlData = xmlData.substr(offset);
let java_class_link = java.import(BarcodeGenerator.javaClassName);
return BarcodeGenerator.construct(java_class_link.importFromXmlSync(xmlData));
} catch (ex) {
throw new joint.BarcodeException(ex);
}
}
}
/**
* Barcode generation parameters.
*/
class BarcodeParameters extends joint.BaseJavaClass
{
xDimension;
barHeight;
codeTextParameters;
postal;
australianPost;
codablock;
dataBar;
gs1CompositeBar;
dataMatrix;
code16K;
itf;
qr;
pdf417;
maxiCode;
aztec;
code128;
codabar;
coupon;
hanXin;
supplement;
dotCode;
padding;
patchCode;
barWidthReduction;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.xDimension = new Unit(this.getJavaClass().getXDimensionSync());
this.barWidthReduction = new Unit(this.getJavaClass().getBarWidthReductionSync());
this.barHeight = new Unit(this.getJavaClass().getBarHeightSync());
this.codeTextParameters = new CodetextParameters(this.getJavaClass().getCodeTextParametersSync());
this.postal = new PostalParameters(this.getJavaClass().getPostalSync());
this.australianPost = new AustralianPostParameters(this.getJavaClass().getAustralianPostSync());
this.codablock = new CodablockParameters(this.getJavaClass().getCodablockSync());
this.dataBar = new DataBarParameters(this.getJavaClass().getDataBarSync());
this.gs1CompositeBar = new GS1CompositeBarParameters(this.getJavaClass().getGS1CompositeBarSync());
this.dataMatrix = new DataMatrixParameters(this.getJavaClass().getDataMatrixSync());
this.code16K = new Code16KParameters(this.getJavaClass().getCode16KSync());
this.itf = new ITFParameters(this.getJavaClass().getITFSync());
this.qr = new QrParameters(this.getJavaClass().getQRSync());
this.pdf417 = new Pdf417Parameters(this.getJavaClass().getPdf417Sync());
this.maxiCode = new MaxiCodeParameters(this.getJavaClass().getMaxiCodeSync());
this.aztec = new AztecParameters(this.getJavaClass().getAztecSync());
this.code128 = new Code128Parameters(this.getJavaClass().getCode128Sync());
this.codabar = new CodabarParameters(this.getJavaClass().getCodabarSync());
this.coupon = new CouponParameters(this.getJavaClass().getCouponSync());
this.hanXin = new HanXinParameters(this.getJavaClass().getHanXinSync());
this.supplement = new SupplementParameters(this.getJavaClass().getSupplementSync());
this.dotCode = new DotCodeParameters(this.getJavaClass().getDotCodeSync());
this.padding = new Padding(this.getJavaClass().getPaddingSync());
this.patchCode = new PatchCodeParameters(this.getJavaClass().getPatchCodeSync());
}
/**
* x-dimension is the smallest width of the unit of BarCode bars or spaces.<br>
* Increase this will increase the whole barcode image width.<br>
* Ignored if AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
*/
getXDimension()
{
return this.xDimension;
}
/**
* x-dimension is the smallest width of the unit of BarCode bars or spaces.<br>
* Increase this will increase the whole barcode image width.<br>
* Ignored if AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
* @throws BarcodeException
*/
setXDimension(value)
{
this.getJavaClass().setXDimensionSync(value.getJavaClass());
this.xDimension = value;
}
/**
* Height of 1D barcodes' bars in Unit value.<br>
* Ignored if AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
* @throws BarcodeException
*/
getBarHeight()
{
return this.barHeight;
}
/**
* Height of 1D barcodes' bars in Unit value.<br>
* Ignored if AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
* @throws BarcodeException
*/
setBarHeight(value)
{
this.getJavaClass().setBarHeightSync(value.getJavaClass());
this.barHeight = value;
}
/**
* Bars color.
* @return value of Bar color
* Default value: #000000
*/
getBarColor()
{
let intColor = this.getJavaClass().getBarColorSync();
let hexColor = ((intColor) >>> 0).toString(16).slice(-6).toUpperCase()
while (hexColor.length < 6) {
hexColor = "0" + hexColor;
}
hexColor = "#" + hexColor;
return hexColor;
}
/**
* Bars color.
* @param {String} value for Bar color
* Default value: #000000.
*/
setBarColor(value)
{
this.getJavaClass().setBarColorSync((parseInt(value.substr(1), 16) << 8) / 256);
}
/**
* Barcode paddings.<br>
* Default value: 5pt 5pt 5pt 5pt.
*/
getPadding()
{
return this.padding;
}
/**
* Barcode paddings.<br>
* Default value: 5pt 5pt 5pt 5pt.
*/
setPadding(value)
{
this.getJavaClass().setPaddingSync(value.getJavaClass());
this.padding = value;
}
/**
* Always display checksum digit in the human readable text for Code128 and GS1Code128 barcodes.
*/
getChecksumAlwaysShow()
{
return this.getJavaClass().getChecksumAlwaysShowSync();
}
/**
* Always display checksum digit in the human readable text for Code128 and GS1Code128 barcodes.
*/
setChecksumAlwaysShow(value)
{
this.getJavaClass().setChecksumAlwaysShowSync(value);
}
/**
* Enable checksum during generation 1D barcodes.<br>
* Default is treated as Yes for symbology which must contain checksum, as No where checksum only possible.<br>
* Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN, Codabar<br>
* Checksum always used: Rest symbology
*/
isChecksumEnabled()
{
return this.getJavaClass().isChecksumEnabledSync();
}
/**
* Enable checksum during generation 1D barcodes.<br>
* Default is treated as Yes for symbology which must contain checksum, as No where checksum only possible.<br>
* Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN, Codabar<br>
* Checksum always used: Rest symbology
*/
setChecksumEnabled(value)
{
this.getJavaClass().setChecksumEnabledSync(value);
}
/**
* Indicates whether explains the character "\" as an escape character in CodeText property. Used for Pdf417, DataMatrix, Code128 only<br>
* If the EnableEscape is true, "\" will be explained as a special escape character. Otherwise, "\" acts as normal characters.<br>
* Aspose.BarCode supports inputing decimal ascii code and mnemonic for ASCII control-code characters. For example, \013 and \\CR stands for CR.
*/
getEnableEscape()
{
return this.getJavaClass().getEnableEscapeSync();
}
/**
* Indicates whether explains the character "\" as an escape character in CodeText property. Used for Pdf417, DataMatrix, Code128 only<br>
* If the EnableEscape is true, "\" will be explained as a special escape character. Otherwise, "\" acts as normal characters.<br>
*<hr>Aspose.BarCode supports the decimal ascii code and mnemonic for ASCII control-code characters. For example, \013 and \\CR stands for CR.</hr>
*/
setEnableEscape(value)
{
this.getJavaClass().setEnableEscapeSync(value);
}
/**
* Wide bars to Narrow bars ratio<br>.
* Default value: 3, that is, wide bars are 3 times as wide as narrow bars<br>.
* Used for ITF, PZN, PharmaCode, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, IATA2of5, VIN, DeutschePost, OPC, Code32, DataLogic2of5, PatchCode, Code39Extended, Code39Standard<br>
*
* The WideNarrowRatio parameter value is less than or equal to 0.
*/
getWideNarrowRatio()
{
return this.getJavaClass().getWideNarrowRatioSync();
}
/**
* Wide bars to Narrow bars ratio.<br>
* Default value: 3, that is, wide bars are 3 times as wide as narrow bars.<br>
* Used for ITF, PZN, PharmaCode, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, IATA2of5, <br>
* VIN, DeutschePost, OPC, Code32, DataLogic2of5, PatchCode, Code39Extended, Code39Standard<br>
* <br>
* The WideNarrowRatio parameter value is less than or equal to 0.
*/
setWideNarrowRatio(value)
{
this.getJavaClass().setWideNarrowRatioSync(value);
}
/**
* Codetext parameters.
*/
getCodeTextParameters()
{
return this.codeTextParameters;
}
/**
* Gets a value indicating whether bars filled.<br>
* Only for 1D barcodes.<br>
* Default value: true.
*/
getFilledBars()
{
return this.getJavaClass().getFilledBarsSync();
}
/**
* Sets a value indicating whether bars filled.<br>
* Only for 1D barcodes.<br>
* Default value: true.
*/
setFilledBars(value)
{
this.getJavaClass().setFilledBarsSync(value);
}
/**
* Get bars reduction value that is used to compensate ink spread while printing.<br>
* @return Unit value of BarWidthReduction
*/
getBarWidthReduction()
{
return this.barWidthReduction;
}
/**
* Sets bars reduction value that is used to compensate ink spread while printing.
*/
setBarWidthReduction(value)
{
this.getJavaClass().setBarWidthReductionSync(value.getJavaClass());
this.barWidthReduction = value;
}
/**
* Postal parameters. Used for Postnet, Planet.
*/
getPostal()
{
return this.postal;
}
/**
* PatchCode parameters.
*/
getPatchCode()
{
return this.patchCode;
}
/**
* AustralianPost barcode parameters.
*/
getAustralianPost()
{
return this.australianPost;
}
/**
* Databar parameters.
*/
getDataBar()
{
return this.dataBar;
}
/**
* GS1 Composite Bar parameters.<br>
* <br>
* This sample shows how to create and save a GS1 Composite Bar image.<br>
* Note that 1D codetext and 2D codetext are separated by symbol '/'
*
* @example
* let codetext = "(01)03212345678906/(21)A1B2C3D4E5F6G7H8";
* let generator = new BarcodeGenerator(EncodeTypes.GS_1_COMPOSITE_BAR, codetext);
*
* generator.getParameters().getBarcode().getGS1CompositeBar().setLinearComponentType(EncodeTypes.GS_1_CODE_128);
* generator.getParameters().getBarcode().getGS1CompositeBar().setTwoDComponentType(TwoDComponentType.CC_A);
*
* // Aspect ratio of 2D component
* generator.getParameters().getBarcode().getPdf417().setAspectRatio(3);
*
* // X-Dimension of 1D and 2D components
* generator.getParameters().getBarcode().getXDimension().setPixels(3);
* ///
* // Height of 1D component
* generator.getParameters().getBarcode().getBarHeight().setPixels(100);
* ///
* generator.save("test.png", BarcodeImageFormat.PNG);
*
* @return GS1CompositeBarParameters GS1 Composite Bar parameters.
*/
getGS1CompositeBar()
{
return this.gs1CompositeBar;
}
/**
* GS1 Composite Bar parameters.<br>
* <br>
* This sample shows how to create and save a GS1 Composite Bar image.<br>
* Note that 1D codetext and 2D codetext are separated by symbol '/'
*
* @example
* let codetext = "(01)03212345678906/(21)A1B2C3D4E5F6G7H8";
* let generator = new BarcodeGenerator(EncodeTypes.GS_1_COMPOSITE_BAR, codetext);
*
* generator.getParameters().getBarcode().getGS1CompositeBar().setLinearComponentType(EncodeTypes.GS_1_CODE_128);
* generator.getParameters().getBarcode().getGS1CompositeBar().setTwoDComponentType(TwoDComponentType.CC_A);
*
* // Aspect ratio of 2D component
* generator.getParameters().getBarcode().getPdf417().setAspectRatio(3);
*
* // X-Dimension of 1D and 2D components
* generator.getParameters().getBarcode().getXDimension().setPixels(3);
*
* // Height of 1D component
* generator.getParameters().getBarcode().getBarHeight().setPixels(100);
*
* generator.save("test.png", BarcodeImageFormat.PNG);
*/
setGS1CompositeBar(value)
{
this.gs1CompositeBar = value;
this.getJavaClass().setGS1CompositeBarSync(value.getJavaClass());
}
/**
* Codablock parameters.
*/
getCodablock()
{
return this.codablock;
}
/**
* DataMatrix parameters.
*/
getDataMatrix()
{
return this.dataMatrix;
}
/**
* Code16K parameters.
*/
getCode16K()
{
return this.code16K;
}
/**
* DotCode parameters.
*/
getDotCode()
{
return this.dotCode;
}
/**
* ITF parameters.
*/
getITF()
{
return this.itf;
}
/**
* PDF417 parameters.
*/
getPdf417()
{
return this.pdf417;
}
/**
* QR parameters.
*/
getQR()
{
return this.qr;
}
/**
* Supplement parameters. Used for Interleaved2of5, Standard2of5, EAN13, EAN8, UPCA, UPCE, ISBN, ISSN, ISMN.
*/
getSupplement()
{
return this.supplement;
}
/**
* MaxiCode parameters.
*/
getMaxiCode()
{
return this.maxiCode;
}
/**
* Aztec parameters.
*/
getAztec()
{
return this.aztec;
}
/**
* <p>
* Code128 parameters.
* </p>
*/
getCode128()
{
return this.code128;
}
/**
* Codabar parameters.
*/
getCodabar()
{
return this.codabar;
}
/**
* Coupon parameters. Used for UpcaGs1DatabarCoupon, UpcaGs1Code128Coupon.
*/
getCoupon()
{
return this.coupon;
}
/**
* HanXin parameters.
*/
getHanXin()
{
return this.hanXin;
}
}
/**
* Barcode image generation parameters.
*/
class BaseGenerationParameters extends joint.BaseJavaClass
{
captionAbove;
captionBelow;
barcodeParameters;
borderParameters;
image;
imageWidth;
imageHeight;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.captionAbove = new CaptionParameters(this.getJavaClass().getCaptionAboveSync());
this.captionBelow = new CaptionParameters(this.getJavaClass().getCaptionBelowSync());
this.barcodeParameters = new BarcodeParameters(this.getJavaClass().getBarcodeSync());
this.borderParameters = new BorderParameters(this.getJavaClass().getBorderSync());
this.imageWidth = new Unit(this.getJavaClass().getImageWidthSync());
this.imageHeight = new Unit(this.getJavaClass().getImageHeightSync());
this.image = new ImageParameters(this.getJavaClass().getImageSync());
}
/**
* Gets a value indicating whether is used anti-aliasing mode to render image
*/
getUseAntiAlias()
{
return this.getJavaClass().getUseAntiAliasSync();
}
/**
* Sets a value indicating whether is used anti-aliasing mode to render image
*/
setUseAntiAlias(value)
{
this.getJavaClass().setUseAntiAliasSync(value);
}
/**
* Background color of the barcode image.<br>
* Default value: #FFFFFF<br>
*/
getBackColor()
{
let intColor = this.getJavaClass().getBackColorSync();
let hexColor = ((intColor) >>> 0).toString(16).slice(-6).toUpperCase()
while (hexColor.length < 6) {
hexColor = "0" + hexColor;
}
hexColor = "#" + hexColor;
return hexColor;
}
/**
* Background color of the barcode image.<br>
* Default value: #FFFFFF<br>
*/
setBackColor(colorValue)
{
let hexValue = colorValue.substring(1, colorValue.length)
if (!(/^[0-9A-Fa-f]+$/.test(hexValue))) {
throw new joint.BarcodeException("Illegal color value: " + hexValue);
}
this.getJavaClass().setBackColorSync((parseInt(hexValue, 16) << 8) / 256);
}
/**
* <p>
* Gets the resolution of the BarCode image.<br>
* One value for both dimensions.<br>
* Default value: 96 dpi.<br>
* </p>
* The Resolution parameter value is less than or equal to 0.
*/
getResolution()
{
return this.getJavaClass().getResolutionSync();
}
/**
* <p>
* Sets the resolution of the BarCode image.<br>
* One value for both dimensions.<br>
* Default value: 96 dpi.<br>
* </p>
*
* The Resolution parameter value is less than or equal to 0.
*/
setResolution(value)
{
this.getJavaClass().setResolutionSync(java.newFloat(value));
}
/**
* Image parameters. See ImageParameters.
* @return ImageParameters
*/
getImage()
{
return this.image;
}
/**
* BarCode image rotation angle, measured in degree, e.g. RotationAngle = 0 or RotationAngle = 360 means no rotation.<br>
* If RotationAngle NOT equal to 90, 180, 270 or 0, it may increase the difficulty for the scanner to read the image<br>.
* Default value: 0.<br>
* @example
* //This sample shows how to create and save a BarCode image.
* let generator = new BarcodeGenerator( EncodeTypes.DATA_MATRIX);
* generator.getParameters().setRotationAngle(7);
* generator.save("test.png", BarcodeImageFormat.PNG);
*/
getRotationAngle()
{
return this.getJavaClass().getRotationAngleSync();
}
/**
* BarCode image rotation angle, measured in degree, e.g. RotationAngle = 0 or RotationAngle = 360 means no rotation.<br>
* If RotationAngle NOT equal to 90, 180, 270 or 0, it may increase the difficulty for the scanner to read the image.<br>
* Default value: 0.<br>
* @example
* //This sample shows how to create and save a BarCode image.
* let generator = new BarcodeGenerator( EncodeTypes.DATA_MATRIX);
* generator.getParameters().setRotationAngle(7);
* generator.save("test.png", BarcodeImageFormat.PNG);
*/
setRotationAngle(value)
{
this.getJavaClass().setRotationAngleSync(java.newFloat(value));
}
/**
* Caption Above the BarCode image. See CaptionParameters.
*/
getCaptionAbove()
{
return this.captionAbove;
}
/**
* Caption Below the BarCode image. See CaptionParameters.
*/
getCaptionBelow()
{
return this.captionBelow;
}
/**
* Specifies the different types of automatic sizing modes.<br>
* Default value: AutoSizeMode.NONE.
*/
getAutoSizeMode()
{
return this.getJavaClass().getAutoSizeModeSync();
}
/**
* Specifies the different types of automatic sizing modes.<br>
* Default value: AutoSizeMode.NONE.
*/
setAutoSizeMode(value)
{
this.getJavaClass().setAutoSizeModeSync(value);
}
/**
* BarCode image height when AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
*/
getImageHeight()
{
return this.imageHeight;
}
/**
* BarCode image height when AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
*/
setImageHeight(value)
{
this.getJavaClass().setImageHeight(value.getJavaClass());
this.imageHeight = value;
}
/**
* BarCode image width when AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
*/
getImageWidth()
{
return this.imageWidth;
}
/**
* BarCode image width when AutoSizeMode property is set to AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.
*/
setImageWidth(value)
{
this.getJavaClass().setImageWidth(value.getJavaClass());
this.imageWidth = value;
}
/**
* Gets the BarcodeParameters that contains all barcode properties.
*/
getBarcode()
{
return this.barcodeParameters;
}
/**
* Gets the BorderParameters that contains all configuration properties for barcode border.
*/
getBorder()
{
return this.borderParameters;
}
}
/**
* Barcode image border parameters
*/
class BorderParameters extends joint.BaseJavaClass
{
width;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.width = new Unit(this.getJavaClass().getWidthSync());
}
/**
* Border visibility. If false than parameter Width is always ignored (0).<br>
* Default value: false.
*/
getVisible()
{
return this.getJavaClass().getVisibleSync();
}
/**
* Border visibility. If false than parameter Width is always ignored (0).<br>
* Default value: false.
*/
setVisible(value)
{
this.getJavaClass().setVisibleSync(value);
}
/**
* Border width.<br>
* Default value: 0.<br>
* Ignored if Visible is set to false.
*/
getWidth()
{
return this.width;
}
/**
* Border width.<br>
* Default value: 0.<br>
* Ignored if Visible is set to false.
*/
setWidth(value)
{
this.getJavaClass().setWidthSync(value.getJavaClass());
this.width = value;
}
/**
* Returns a human-readable string representation of this BorderParameters.<br>
* @return A string that represents this BorderParameters.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
/**
* Border dash style.<br>
* Default value: BorderDashStyle.SOLID.
*/
getDashStyle()
{
return this.getJavaClass().getDashStyleSync();
}
/**
* Border dash style.<br>
* Default value: BorderDashStyle.SOLID.
*/
setDashStyle(value)
{
this.getJavaClass().setDashStyleSync(value);
}
/**
* Border color.<br>
* Default value: #000000
*/
getColor()
{
let intColor = this.getJavaClass().getColorSync();
let hexColor = ((intColor) >>> 0).toString(16).slice(-6).toUpperCase()
while (hexColor.length < 6) {
hexColor = "0" + hexColor;
}
hexColor = "#" + hexColor;
return hexColor;
}
/**
* Border color.<br>
* Default value: #000000
*/
setColor(hexValue)
{
this.getJavaClass().setColorSync((parseInt(hexValue.substr(1), 16) << 8) / 256);
}
}
/**
* Caption parameters.
*/
class CaptionParameters extends joint.BaseJavaClass
{
font;
padding;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.padding = new Padding(this.getJavaClass().getPaddingSync());
this.font = new FontUnit(this.getJavaClass().getFontSync());
}
/**
* Caption text.<br>
* Default value: empty string.
*/
getText()
{
return this.getJavaClass().getTextSync();
}
/**
* Caption text.<br>
* Default value: empty string.
*/
setText(value)
{
this.getJavaClass().setTextSync(value);
}
/**
* Caption font.<br>
* Default value: Arial 8pt regular.
*/
getFont()
{
return this.font;
}
/**
* Caption text visibility.<br>
* Default value: false.
*/
getVisible()
{
return this.getJavaClass().getVisibleSync();
}
/**
* Caption text visibility.<br>
* Default value: false.
*/
setVisible(value)
{
this.getJavaClass().setVisibleSync(value);
}
/**
* Caption text color.<br>
* Default value BLACK.
*/
getTextColor()
{
let intColor = this.getJavaClass().getTextColorSync();
let hexColor = ((intColor) >>> 0).toString(16).slice(-6).toUpperCase()
while (hexColor.length < 6) {
hexColor = "0" + hexColor;
}
hexColor = "#" + hexColor;
return hexColor;
}
/**
* Caption text color.<br>
* Default value BLACK.
*/
setTextColor(hexValue)
{
this.getJavaClass().setTextColorSync((parseInt(hexValue.substr(1), 16) << 8) / 256);
}
/**
* Captions paddings.<br>
* Default value for CaptionAbove: 5pt 5pt 0 5pt.<br>
* Default value for CaptionBelow: 0 5pt 5pt 5pt.
*/
getPadding()
{
return this.padding;
}
/**
* Captions paddings.<br>
* Default value for CaptionAbove: 5pt 5pt 0 5pt.<br>
* Default value for CaptionBelow: 0 5pt 5pt 5pt.
*/
setPadding(value)
{
this.getJavaClass().setPaddingSync(value.getJavaClass());
this.padding = value;
}
/**
* Caption test horizontal alignment.<br>
* Default TextAlignment.CENTER.
*/
getAlignment()
{
return this.getJavaClass().getAlignmentSync();
}
/**
* Caption test horizontal alignment.<br>
* Default TextAlignment.CENTER.
*/
setAlignment(value)
{
this.getJavaClass().setAlignmentSync(value);
}
/**
* Specify word wraps (line breaks) within text.<br>
* Default value: false.
*/
getNoWrap()
{
return this.getJavaClass().getNoWrapSync();
}
/**
* Specify word wraps (line breaks) within text.<br>
* Default value: false.
*/
setNoWrap(value)
{
this.getJavaClass().setNoWrapSync(value);
}
/**
* Specify word wraps (line breaks) within text.<br>
* Default value: false.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* Specifies the size value in different units (Pixel, Inches, etc.).
* @example
* //This sample shows how to create and save a BarCode image.
* let generator = new BarcodeGenerator(EncodeTypes.CODE_128);
* generator.getParameters().getBarcode().getBarHeight().setMillimeters(10);
* generator.save("test.png", BarcodeImageFormat.PNG);
*/
class Unit extends joint.BaseJavaClass
{
constructor(source)
{
super(Unit.initUnit(source));
this.init();
}
static initUnit(source)
{
if (source instanceof Unit) {
return source.getJavaClass();
}
return source;
}
init()
{
}
/**
* Gets size value in pixels.
*/
getPixels()
{
return this.getJavaClass().getPixelsSync();
}
/**
* Sets size value in pixels.
*/
setPixels(value)
{
this.getJavaClass().setPixelsSync(value);
}
/**
* Gets size value in inches.
*/
getInches()
{
return this.getJavaClass().getInchesSync();
}
/**
* Sets size value in inches.
*/
setInches(value)
{
this.getJavaClass().setInchesSync(value);
}
/**
* Gets size value in millimeters.
*/
getMillimeters()
{
return this.getJavaClass().getMillimetersSync();
}
/**
* Sets size value in millimeters.
*/
setMillimeters(value)
{
this.getJavaClass().setMillimetersSync(value);
}
/**
* Gets size value in point.
*/
getPoint()
{
return this.getJavaClass().getPointSync();
}
/**
* Sets size value in point.
*/
setPoint(value)
{
this.getJavaClass().setPointSync(value);
}
/**
* Gets size value in document units.
*/
getDocument()
{
return this.getJavaClass().getDocumentSync();
}
/**
* Sets size value in document units.
*/
setDocument(value)
{
this.getJavaClass().setDocumentSync(value);
}
/**
* Returns a human-readable string representation of this Unit.<br>
* @return A string that represents this Unit.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
/**
* Determines whether this instance and a specified object,<br>
* which must also be a Unit object, have the same value.<br>
* @param obj The Unit to compare to this instance.
* @return true if obj is a Unit and its value is the same as this instance;
* otherwise, false. If obj is null, the method returns false.
*/
equals(obj)
{
return this.getJavaClass().equalsSync(obj.getJavaClass());
}
}
/**
* Paddings parameters.
*/
class Padding extends joint.BaseJavaClass
{
top;
bottom;
right;
left;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.top = new Unit(this.getJavaClass().getTopSync());
this.bottom = new Unit(this.getJavaClass().getBottomSync());
this.right = new Unit(this.getJavaClass().getRightSync());
this.left = new Unit(this.getJavaClass().getLeftSync());
}
/**
* Top padding.
*/
getTop()
{
return this.top;
}
/**
* Top padding.
*/
setTop(value)
{
this.getJavaClass().setTopSync(value.getJavaClass());
this.top = value;
}
/**
* Bottom padding.
*/
getBottom()
{
return this.bottom;
}
/**
* Bottom padding.
*/
setBottom(value)
{
this.getJavaClass().setBottomSync(value.getJavaClass());
this.bottom = value;
}
/**
* Right padding.
*/
getRight()
{
return this.right;
}
/**
* Right padding.
*/
setRight(value)
{
this.getJavaClass().setRightSync(value.getJavaClass());
this.right = value;
}
/**
* Left padding.
*/
getLeft()
{
return this.left;
}
/**
* Left padding.
*/
setLeft(value)
{
this.getJavaClass().setLeftSync(value.getJavaClass());
this.left = value;
}
/**
* Returns a human-readable string representation of this Padding.
* @return A string that represents this Padding.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* Codetext parameters.
*/
class CodetextParameters extends joint.BaseJavaClass
{
font;
space;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.font = new FontUnit(this.getJavaClass().getFontSync());
this.space = new Unit(this.getJavaClass().getSpaceSync());
}
/**
* Text that will be displayed instead of codetext in 2D barcodes.<br>
* Used for: Aztec, Pdf417, DataMatrix, QR, MaxiCode, DotCode
*/
getTwoDDisplayText()
{
return this.getJavaClass().getTwoDDisplayTextSync();
}
/**
* Text that will be displayed instead of codetext in 2D barcodes.<br>
* Used for: Aztec, Pdf417, DataMatrix, QR, MaxiCode, DotCode
*/
setTwoDDisplayText(value)
{
this.getJavaClass().setTwoDDisplayTextSync(value);
}
/**
* Specify FontMode. If FontMode is set to Auto, font size will be calculated automatically based on xDimension value.<br>
* It is recommended to use FontMode.AUTO especially in AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.<br>
* Default value: FontMode.AUTO.
*/
getFontMode()
{
return this.getJavaClass().getFontModeSync();
}
/**
* Specify FontMode. If FontMode is set to Auto, font size will be calculated automatically based on xDimension value.<br>
* It is recommended to use FontMode.AUTO especially in AutoSizeMode.NEAREST or AutoSizeMode.INTERPOLATION.<br>
* Default value: FontMode.AUTO.
*/
setFontMode(value)
{
this.getJavaClass().setFontModeSync(value);
}
/**
* Specify the displaying CodeText's font.<br>
* Default value: Arial 5pt regular.<br>
* Ignored if FontMode is set to FontMode.AUTO.
*/
getFont()
{
return this.font;
}
/**
* Specify the displaying CodeText's font.<br>
* Default value: Arial 5pt regular.<br>
* Ignored if FontMode is set to FontMode.AUTO.
*/
setFont(value)
{
this.getJavaClass().setFontSync(value.getJavaClass());
this.font = value;
}
/**
* Space between the CodeText and the BarCode in Unit value.<br>
* Default value: 2pt.<br>
* Ignored for EAN8, EAN13, UPCE, UPCA, ISBN, ISMN, ISSN, UpcaGs1DatabarCoupon.
*/
getSpace()
{
return this.space;
}
/**
* Space between the CodeText and the BarCode in Unit value.<br>
* Default value: 2pt.<br>
* Ignored for EAN8, EAN13, UPCE, UPCA, ISBN, ISMN, ISSN, UpcaGs1DatabarCoupon.
*/
setSpace(value)
{
this.getJavaClass().setSpaceSync(value.getJavaClass());
this.space = value;
}
/**
* Gets the alignment of the code text.<br>
* Default value: TextAlignment.CENTER.
*/
getAlignment()
{
return this.getJavaClass().getAlignmentSync();
}
/**
* Sets the alignment of the code text.<br>
* Default value: TextAlignment.CENTER.
*/
setAlignment(value)
{
this.getJavaClass().setAlignmentSync(value);
}
/**
* Specify the displaying CodeText's Color.<br>
* Default value BLACK.
*/
getColor()
{
let intColor = this.getJavaClass().getColorSync();
let hexColor = ((intColor) >>> 0).toString(16).slice(-6).toUpperCase()
while (hexColor.length < 6) {
hexColor = "0" + hexColor;
}
hexColor = "#" + hexColor;
return hexColor;
}
/**
* Specify the displaying CodeText's Color.<br>
* Default value BLACK.
*/
setColor(value)
{
this.getJavaClass().setColorSync((parseInt(value.substr(1), 16) << 8) / 256);
}
/**
* Specify the displaying CodeText Location, set to CodeLocation.NONE to hide CodeText.<br>
* Default value: CodeLocation.BELOW.
*/
getLocation()
{
return this.getJavaClass().getLocationSync();
}
/**
* Specify the displaying CodeText Location, set to CodeLocation.NONE to hide CodeText.<br>
* Default value: CodeLocation.NONE.
*/
setLocation(value)
{
this.getJavaClass().setLocationSync(value);
}
/**
* Specify word wraps (line breaks) within text.<br>
* Default value: false.
*/
getNoWrap()
{
return this.getJavaClass().getNoWrapSync();
}
/**
* Specify word wraps (line breaks) within text.<br>
* Default value: false.
*/
setNoWrap(value)
{
this.getJavaClass().setNoWrapSync(value);
}
/**
* Returns a human-readable string representation of this CodetextParameters.<br>
* @return A string that represents this CodetextParameters.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* Postal parameters. Used for Postnet, Planet.
*/
class PostalParameters extends joint.BaseJavaClass
{
postalShortBarHeight;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.postalShortBarHeight = new Unit(this.getJavaClass().getPostalShortBarHeightSync());
}
/**
* Short bar's height of Postal barcodes.
*/
getPostalShortBarHeight()
{
return this.postalShortBarHeight;
}
/**
* Short bar's height of Postal barcodes.
*/
setPostalShortBarHeight(value)
{
this.getJavaClass().setPostalShortBarHeightSync(value.getJavaClass());
this.postalShortBarHeight = value;
}
/**
* Returns a human-readable string representation of this PostalParameters.<br>
* @return A string that represents this PostalParameters.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* AustralianPost barcode parameters.
*/
class AustralianPostParameters extends joint.BaseJavaClass
{
australianPostShortBarHeight;
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
this.australianPostShortBarHeight = new Unit(this.getJavaClass().getAustralianPostShortBarHeightSync());
}
/**
* Short bar's height of AustralianPost barcode.
*/
getAustralianPostShortBarHeight()
{
return this.australianPostShortBarHeight;
}
/**
* Short bar's height of AustralianPost barcode.
*/
setAustralianPostShortBarHeight(value)
{
this.getJavaClass().setAustralianPostShortBarHeightSync(value.getJavaClass());
this.australianPostShortBarHeight = value;
}
/**
* Interpreting type for the Customer Information of AustralianPost, default to CustomerInformationInterpretingType.Other"
*/
getAustralianPostEncodingTable()
{
return this.getJavaClass().getAustralianPostEncodingTableSync();
}
/**
* Interpreting type for the Customer Information of AustralianPost, default to CustomerInformationInterpretingType.Other"
*/
setAustralianPostEncodingTable(value)
{
this.getJavaClass().setAustralianPostEncodingTableSync(value);
}
/**
* Returns a human-readable string representation of this AustralianPostParameters.<br>
* @return {string} Value that represents this AustralianPostParameters.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* Codablock parameters.
*/
class CodablockParameters extends joint.BaseJavaClass
{
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
}
/**
* Columns count.
*/
getColumns()
{
return this.getJavaClass().getColumnsSync();
}
/**
* Columns count.
*/
setColumns(value)
{
this.getJavaClass().setColumnsSync(value);
}
/**
* Rows count.
*/
getRows()
{
return this.getJavaClass().getRowsSync();
}
/**
* Rows count.
*/
setRows(value)
{
this.getJavaClass().setRowsSync(value);
}
/**
* Height/Width ratio of 2D BarCode module.
*/
getAspectRatio()
{
return this.getJavaClass().getAspectRatioSync();
}
/**
* Height/Width ratio of 2D BarCode module.
*/
setAspectRatio(value)
{
this.getJavaClass().setAspectRatioSync(java.newFloat(value));
}
/**
* Returns a human-readable string representation of this CodablockParameters. <br>
* @return {string} value that represents this CodablockParameters.
*/
toString()
{
return this.getJavaClass().toStringSync();
}
}
/**
* Databar parameters.
*/
class DataBarParameters extends joint.BaseJavaClass
{
constructor(javaClass)
{
super(javaClass);
this.init();
}
init()
{
}
/**
* Enables flag of 2D composite component with DataBar barcode
*/
is2DCompositeComponent()
{
return this.getJavaClass().is2DCompositeComponentSync();
}
/**
* Enables flag of 2D composite component with DataBar barcode
*/
set2DCompositeComponent(value)
{
this.getJavaClass().set2DCompositeComponentSync(value);
}
/**
* If this flag is set, it allows only GS1 encoding standard for Databar barcode types
*/
isAllowOnlyGS1Encoding()
{
return this.getJavaClass().isAllowOnlyGS1EncodingSync();
}
/**
* If this flag is set, it allows only GS1 encoding standard for Data