←Select platform

LoadOptions(string) Method

Summary
Loads the document options from an XML file on disk.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void LoadOptions( 
   string fileName 
) 
macOS Only: 
- (BOOL)loadOptionsFromFile:(NSString *)fileName error:(NSError **)error 
public void loadOptions(String fileName) 
public: 
void LoadOptions(  
   String^ fileName 
)  
def LoadOptions(self,fileName): 

Parameters

fileName
The name of XML file containing the options.

Remarks

This method will load the options saved to an XML file using the SaveOptions(string) method.

To load and save the options to an XML stream instead of a file, use LoadOptions(Stream) and SaveOptions(Stream).

Saving the options to an XML file allows you to set the options the required way once and then re-use them in multiple sessions (or multiple DocumentWriter instances). Each document format supported by the LEADTOOLS Document Writer contain extra functionality and options that can be accessed with the GetOptions and SetOptions methods. For more information, refer to DocumentOptions.

The following options are saved to the XML:

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Ocr; 
 
 
public void DocumentOptionsDiskExample() 
{ 
   var xmlFileName = Path.Combine(LEAD_VARS.ImagesDir, "DocumentWriterOptions.xml"); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   var docWriter1 = new DocumentWriter(); 
 
   // Show the default PDF and HTML options before 
   ShowOptions("Default options for docWriter1", docWriter1); 
 
   // Change the PDF options and HTML options 
   var pdfOptions = docWriter1.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
   pdfOptions.DocumentType = PdfDocumentType.PdfA; 
   pdfOptions.ImageOverText = true; 
   docWriter1.SetOptions(DocumentFormat.Pdf, pdfOptions); 
 
   var htmlOptions = docWriter1.GetOptions(DocumentFormat.Html) as HtmlDocumentOptions; 
   htmlOptions.UseBackgroundColor = true; 
   htmlOptions.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.LightBlue); 
   docWriter1.SetOptions(DocumentFormat.Html, htmlOptions); 
 
   // Show the options again 
   ShowOptions("New options for docWriter1", docWriter1); 
 
   // Save these options to disk 
   docWriter1.SaveOptions(xmlFileName); 
 
   // Create a new DocumentWriter object 
   var docWriter2 = new DocumentWriter(); 
 
   // Show its options, should be the defaults 
   ShowOptions("Default options for docWriter2", docWriter2); 
 
   // Load the options from disk to this object 
   docWriter2.LoadOptions(xmlFileName); 
 
   // Show the options now, should be the saved ones 
   ShowOptions("Options for docWriter2 after loading from the XML file", docWriter2); 
} 
 
private void ShowOptions(string message, DocumentWriter docWriter) 
{ 
   Debug.WriteLine(message); 
 
   var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
   Debug.WriteLine("  PDF options: "); 
   Debug.WriteLine("    DocumentType:  " + pdfOptions.DocumentType); 
   Debug.WriteLine("    FontEmbedMode: " + pdfOptions.FontEmbedMode); 
   Debug.WriteLine("    ImageOverText: " + pdfOptions.ImageOverText); 
 
   var htmlOptions = docWriter.GetOptions(DocumentFormat.Html) as HtmlDocumentOptions; 
   Debug.WriteLine("  HTML options: "); 
   Debug.WriteLine("    DocumentType:       " + htmlOptions.DocumentType); 
   Debug.WriteLine("    FontEmbedMode:      " + htmlOptions.FontEmbedMode); 
   Debug.WriteLine("    UseBackgroundColor: " + htmlOptions.UseBackgroundColor); 
   Debug.WriteLine("    BackgroundColor:    " + htmlOptions.BackgroundColor); 
   Debug.WriteLine("-------------------------"); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentOptionsDiskExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String xmlFileName = combine(LEAD_VARS_IMAGES_DIR, "DocumentWriterOptions.xml"); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   DocumentWriter docWriter1 = new DocumentWriter(); 
 
   // Show the default PDF and HTML options before 
   ShowOptions("Default options for docWriter1", docWriter1); 
 
   // Change the PDF options and HTML options 
   PdfDocumentOptions pdfOptions = (PdfDocumentOptions) docWriter1.getOptions(DocumentFormat.PDF); 
   pdfOptions.setDocumentType(PdfDocumentType.PDFA); 
   pdfOptions.setImageOverText(true); 
   docWriter1.setOptions(DocumentFormat.PDF, pdfOptions); 
 
   HtmlDocumentOptions htmlOptions = (HtmlDocumentOptions) docWriter1.getOptions(DocumentFormat.HTML); 
   htmlOptions.setUseBackgroundColor(true); 
   htmlOptions.setBackgroundColor(RasterColor.fromKnownColor(RasterKnownColor.LIGHT_BLUE)); 
   docWriter1.setOptions(DocumentFormat.HTML, htmlOptions); 
 
   // Show the options again 
   ShowOptions("New options for docWriter1", docWriter1); 
 
   // Save these options to disk 
   docWriter1.saveOptions(xmlFileName); 
 
   // Create a new DocumentWriter object 
   DocumentWriter docWriter2 = new DocumentWriter(); 
 
   // Show its options, should be the defaults 
   ShowOptions("Default options for docWriter2", docWriter2); 
 
   // Load the options from disk to this object 
   docWriter2.loadOptions(xmlFileName); 
 
   // Show the options now, should be the saved ones 
   ShowOptions("Options for docWriter2 after loading from the XML file", docWriter2); 
 
   assertTrue("Options saved incorrectly", xmlFileName.length() == 57); 
   System.out.println("Options saved correctly"); 
} 
 
private void ShowOptions(String message, DocumentWriter docWriter) { 
   System.out.println(message); 
 
   PdfDocumentOptions pdfOptions = (PdfDocumentOptions) docWriter.getOptions(DocumentFormat.PDF); 
   System.out.println("  PDF options: "); 
   System.out.println("    DocumentType:  " + pdfOptions.getDocumentType()); 
   System.out.println("    FontEmbedMode: " + pdfOptions.getFontEmbedMode()); 
   System.out.println("    ImageOverText: " + pdfOptions.getImageOverText()); 
 
   HtmlDocumentOptions htmlOptions = (HtmlDocumentOptions) docWriter.getOptions(DocumentFormat.HTML); 
   System.out.println("  HTML options: "); 
   System.out.println("    DocumentType:       " + htmlOptions.getFormat()); 
   assertTrue("is html document type", htmlOptions.getFormat() == DocumentFormat.HTML); 
   System.out.println("    FontEmbedMode:      " + htmlOptions.getFontEmbedMode()); 
   System.out.println("    UseBackgroundColor: " + htmlOptions.getUseBackgroundColor()); 
   System.out.println("    BackgroundColor:    " + htmlOptions.getBackgroundColor()); 
   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.Document.Writer Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.