Export and Import Barcode Generation State via XML in JavaScript
Overview
In Aspose.BarCode for JavaScript via C++, you can serialize the state of barcode generation and import it from XML using the BarcodeGenerator class. Serialization of a BarcodeGenerator instance can be done in two ways: exporting it to an XML file using the ExportToXml(String) method or exporting to a stream with the ExportToXml(Stream) method.
Similarly, you can load the barcode generation state from an XML source using the ImportFromXml(String) method for files or the ImportFromXml(Stream) method for streams.
Export Barcode Generation State to XML
You can save the state of a BarcodeGenerator instance to an XML file using the ExportToXml(String) method or to a stream with the ExportToXml(Stream) method. The following code example demonstrates how to serialize a BarcodeGenerator instance to an XML file.
// Generate a Macro PDF417 barcode with metadata and export settings
var gen = new BarCodeInstance.BarcodeGenerator("MacroPdf417", "Åspóse.Barcóde©");
gen.Parameters.Barcode.XDimension = "2px";
gen.Parameters.Barcode.Pdf417.Columns = 4;
// Set PDF417 metadata
gen.Parameters.Barcode.Pdf417.Pdf417MacroFileID = 12345678;
gen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentID = 12;
gen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentsCount = 20;
gen.Parameters.Barcode.Pdf417.Pdf417MacroFileName = "file01";
gen.Parameters.Barcode.Pdf417.Pdf417MacroChecksum = 1234;
gen.Parameters.Barcode.Pdf417.Pdf417MacroFileSize = 400000;
gen.Parameters.Barcode.Pdf417.Pdf417MacroTimeStamp = "1970-10-20T15:20:35.123Z";
gen.Parameters.Barcode.Pdf417.Pdf417MacroAddressee = "street";
gen.Parameters.Barcode.Pdf417.Pdf417MacroSender = "aspose";
// Export BarcodeGenerator settings to XML file
var xmlFile = gen.ExportToXml();
console.log(xmlFile);
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display barcode image
gen.delete();
Import Barcode Generation State from XML
You can import the state of a BarcodeGenerator instance from an XML file using the ImportFromXml(String) method or from a stream using the ImportFromXml(Stream) method. The code example below shows how to import the barcode generation state from an XML file.
// Load BarcodeGenerator from XML file
var gen = BarCodeInstance.BarcodeGenerator.ImportFromXml(xmlFile);
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display barcode image
gen.delete();