←Select platform

SaveOptions(Stream) Method

Summary
Saves the document options to an XML stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SaveOptions( 
   Stream stream 
) 
macOS Only: 
- (void)saveOptionsToData:(NSMutableData *)data 
public void saveOptions(OutputStream stream) 
public: 
void SaveOptions(  
   Stream^ stream 
)  
def SaveOptions(self,stream): 

Parameters

stream
A standard .NET Stream to save the options to.

Remarks

To load the options saved into a .NET stream the SaveOptions(Stream) method, use LoadOptions(Stream).

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

Saving the options to an XML file allows the options to be the required way once and then re-used 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:

The following options are saved to the XML:

Example

This example will change some of the options in a DocumentWriter object, saves them to a memory stream and then re-load them in a new instance.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Ocr; 
 
 
public void DocumentOptionsStreamExample() 
{ 
   // Use a memory stream to save the options to 
   using (var stream = new MemoryStream()) 
   { 
      // Create a new instance of the LEADTOOLS Document Writer 
      var docWriter1 = new DocumentWriter(); 
 
      // Show the default PDF and HTML options before 
      ShowMyOptions("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 
      ShowMyOptions("New options for docWriter1", docWriter1); 
 
      // Save these options to the stream 
      docWriter1.SaveOptions(stream); 
      // Reset the stream back to its original position 
      stream.Position = 0; 
 
      // Create a new DocumentWriter object 
      var docWriter2 = new DocumentWriter(); 
 
      // Show its options, should be the defaults 
      ShowMyOptions("Default options for docWriter2", docWriter2); 
 
      // Load the options from the memory to this object 
      docWriter2.LoadOptions(stream); 
 
      // Show the options now, should be the saved ones 
      ShowMyOptions("Options for docWriter2 after loading from the XML file", docWriter2); 
   } 
} 
 
private void ShowMyOptions(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("-------------------------"); 
} 
Requirements

Target Platforms

Help Version 22.0.2023.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 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.