←Select platform

SaveOptions(string) Method

Summary
Saves the default write options used for this BarcodeWriter from to the specified XML file.
Syntax
C#
C++/CLI
Python
public void SaveOptions( 
   string fileName 
) 
public: 
void SaveOptions(  
   String^ fileName 
)  
def SaveOptions(self,fileName): 

Parameters

fileName
Name of the XML file to create

Remarks

The load/save methods are provided as helper methods for the user. The BarcodeEngine, BarcodeWriter and BarcodeWriter do not use these methods internally.

The default write options can be retrieved using the GetDefaultOptions or GetAllDefaultOptions methods. You can then change the values of the BarcodeWriteOptions object returned (or cast it back to the appropriate derived class). These options are used by the WriteBarcode method when no explicit options are passed by the user.

To load the default options from an XML file, use BarcodeWriter.LoadOptions(string fileName).

To save and load data to an XML stream, use BarcodeWriter.SaveOptions(Stream stream) and BarcodeWriter.LoadOptions(Stream stream).

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeWriter_LoadSaveOptionsExample() 
{ 
   string xmlFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyWriteOptions.xml"); 
 
   BarcodeEngine engine1 = new BarcodeEngine(); 
   BarcodeWriter writer1 = engine1.Writer; 
 
   // Show a few of the default options 
   ShowWriterOptions("Default options 1:", writer1); 
 
   // Change some options 
   OneDBarcodeWriteOptions oneDWriteOptions = writer1.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; 
   oneDWriteOptions.UseXModule = true; 
   QRBarcodeWriteOptions qrWriteOptions = writer1.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; 
   qrWriteOptions.HorizontalAlignment = BarcodeAlignment.Far; 
 
   // Show them 
   ShowWriterOptions("New options 1:", writer1); 
 
   // Save the options to an XML file 
   writer1.SaveOptions(xmlFileName); 
 
   // Now create another BarcodeWriter 
   // We could use the same one, but this example will show that changing the options 
   // for one BarcodeWriter will not change it in any other in the application 
 
   BarcodeEngine engine2 = new BarcodeEngine(); 
   BarcodeWriter writer2 = engine2.Writer; 
 
   // Show a few of the default options, should be the same as the first default options 
   ShowWriterOptions("Default options 2:", writer2); 
 
   // Load the options we just saved 
   writer2.LoadOptions(xmlFileName); 
 
   // Show them, should be the same as the new options in wirter1 
   ShowWriterOptions("Loaded options 2:", writer2); 
} 
 
private void ShowWriterOptions(string message, BarcodeWriter writer) 
{ 
   Console.WriteLine(message); 
 
   OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; 
   Console.WriteLine("OneDBarcodeWriteOptions.UseXModule: {0}", oneDWriteOptions.UseXModule); 
   QRBarcodeWriteOptions qrWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; 
   Console.WriteLine("QRBarcodeWriteOptions.HorizontalAlignment: {0}", qrWriteOptions.HorizontalAlignment); 
   Console.WriteLine("---------------"); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Path; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
 
 
public void barcodeWriterLoadSaveOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String xmlFileName = combine(LEAD_VARS_IMAGES_DIR, "DocumentWriterOptions.xml"); 
   BarcodeEngine engine1 = new BarcodeEngine(); 
   BarcodeWriter writer1 = engine1.getWriter(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Show a few of the default options 
   showWriterOptions("Default options 1:", writer1); 
 
   // Change some options 
   OneDBarcodeWriteOptions oneDWriteOptions = (OneDBarcodeWriteOptions) writer1.getDefaultOptions(BarcodeSymbology.UPC_A); 
   oneDWriteOptions.setUseXModule(true); 
   QRBarcodeWriteOptions qrWriteOptions = (QRBarcodeWriteOptions) writer1.getDefaultOptions(BarcodeSymbology.QR); 
   qrWriteOptions.setHorizontalAlignment(BarcodeAlignment.FAR); 
 
   // Show them 
   showWriterOptions("New options 1:", writer1); 
 
   // Save the options to an XML file 
   codecs.saveOptions(xmlFileName); 
 
   // Now create another BarcodeWriter 
   // We could use the same one, but this example will show that changing the 
   // options 
   // for one BarcodeWriter will not change it in any other in the application 
   BarcodeEngine engine2 = new BarcodeEngine(); 
   BarcodeWriter writer2 = engine2.getWriter(); 
 
   // Show a few of the default options, should be the same as the first default 
   // options 
   showWriterOptions("Default options 2:", writer2); 
 
   // Load the options we just saved 
   codecs.loadOptions(xmlFileName); 
 
   // Show them, should be the same as the new options in wirter1 
   showWriterOptions("Loaded options 2:", writer2); 
 
   assertTrue("File unsuccessfully saved", (new File(xmlFileName)).exists()); 
   System.out.println("Loaded and saved to " + xmlFileName); 
} 
 
private void showWriterOptions(String message, BarcodeWriter writer) { 
 
   System.out.println(message); 
 
   OneDBarcodeWriteOptions oneDWriteOptions = (OneDBarcodeWriteOptions) writer 
         .getDefaultOptions(BarcodeSymbology.UPC_A); 
   System.out.printf("OneDBarcodeWriteOptions.UseXModule: %s%n", oneDWriteOptions.getUseXModule()); 
   QRBarcodeWriteOptions qrWriteOptions = (QRBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.QR); 
   System.out.printf("QRBarcodeWriteOptions.HorizontalAlignment: %s%n", qrWriteOptions.getHorizontalAlignment()); 
   System.out.println("---------------"); 
 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.