Leadtools.Forms.DocumentWriters Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
TextDocumentOptions Class
See Also  Members   Example 
Leadtools.Forms.DocumentWriters Namespace : TextDocumentOptions Class



Provides extra options to use when saving a document to a text file using the LEADTOOLS DocumentWriter.

Syntax

Visual Basic (Declaration) 
Public Class TextDocumentOptions 
   Inherits DocumentOptions
Visual Basic (Usage)Copy Code
Dim instance As TextDocumentOptions
C# 
public class TextDocumentOptions : DocumentOptions 
C++/CLI 
public ref class TextDocumentOptions : public DocumentOptions 

Example

This example will create a new text file using the various supported options.

Visual BasicCopy Code
' Windows API functions needed to load/delete an EMF
<DllImport("gdi32.dll")> _
Private Shared Function GetEnhMetaFile(ByVal lpszMetaFile As String) As IntPtr
End Function
<DllImport("gdi32.dll")> _
Private Shared Function DeleteEnhMetaFile(ByVal hemf As IntPtr) As Boolean
End Function

Private Sub TextDocumentOptionsExample()
   ' Unlock the support needed for LEADTOOLS Document Writers (with PDF output)
   RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here")

   ' Create a new instance of the LEADTOOLS Document Writer
   Dim docWriter As New DocumentWriter()

   Dim outputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Test.txt"
   Dim emfFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf"

   ' Change the TEXT options to add page breaks and numbers
   Dim textOptions As TextDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Text), TextDocumentOptions)
   textOptions.DocumentType = TextDocumentType.Ansi
   textOptions.AddPageNumber = True
   textOptions.AddPageBreak = True
   textOptions.Formatted = True

   docWriter.SetOptions(DocumentFormat.Text, textOptions)

   ' Create a new text document
   Console.WriteLine("Creating new TEXT document: {0}", outputFileName)
   docWriter.BeginDocument(outputFileName, DocumentFormat.Text)

   ' Use the Windows API to load the EMF
   Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName)

   ' Add the page
   Dim page As DocumentPage = DocumentPage.Empty
   page.EmfHandle = emfHandle
   page.Image = Nothing

   Console.WriteLine("Adding EMF page from: {0}", emfFileName)
   docWriter.AddPage(page)

   ' Use the Windows API to delete the EMF
   DeleteEnhMetaFile(emfHandle)

   ' Finally finish writing the TEXT file on disk
   docWriter.EndDocument()
End Sub
C#Copy Code
// Windows API functions needed to load/delete an EMF 
[DllImport("gdi32.dll")] 
private static extern IntPtr GetEnhMetaFile(string lpszMetaFile); 
[DllImport("gdi32.dll")] 
private static extern bool DeleteEnhMetaFile(IntPtr hemf); 
private void TextDocumentOptionsExample() 

   // Unlock the support needed for LEADTOOLS Document Writers (with PDF output) 
   RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here"); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   DocumentWriter docWriter = new DocumentWriter(); 
 
   string outputFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Test.txt"; 
   string emfFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf"; 
 
   // Change the TEXT options to add page breaks and numbers 
   TextDocumentOptions textOptions = docWriter.GetOptions(DocumentFormat.Text) as TextDocumentOptions; 
   textOptions.DocumentType = TextDocumentType.Ansi; 
   textOptions.AddPageNumber = true; 
   textOptions.AddPageBreak = true; 
   textOptions.Formatted = true; 
 
   docWriter.SetOptions(DocumentFormat.Text, textOptions); 
 
   // Create a new text document 
   Console.WriteLine("Creating new TEXT document: {0}", outputFileName); 
   docWriter.BeginDocument(outputFileName, DocumentFormat.Text); 
 
   // Use the Windows API to load the EMF 
   IntPtr emfHandle = GetEnhMetaFile(emfFileName); 
 
   // Add the page 
   DocumentPage page = DocumentPage.Empty; 
   page.EmfHandle = emfHandle; 
   page.Image = null; 
 
   Console.WriteLine("Adding EMF page from: {0}", emfFileName); 
   docWriter.AddPage(page); 
 
   // Use the Windows API to delete the EMF 
   DeleteEnhMetaFile(emfHandle); 
 
   // Finally finish writing the TEXT file on disk 
   docWriter.EndDocument(); 
}

Remarks

The options set in the TextDocumentOptions class will be used when the user saves a document using the DocumentFormat.Text format.

To change the options used with the Text format, perform the following steps:

  1. Use the DocumentWriter.GetOptions method of the DocumentWriter object being used. Passing DocumentFormat.Text to the Format parameter. Note that the resulting object from the base DocumentOptions class needs to be cast to TextDocumentOptions.
  2. Use the various TextDocumentOptions properties to change the options.
  3. Use DocumentWriter.SetOptions to set the new options in the engine.
  4. Now you can call the DocumentWriter.BeginDocument method (with DocumentFormat.Text for the format parameter) to create a new document and add the pages.

The TextDocumentOptions class contains the following properties:
PropertyDescription
TextDocumentOptions.DocumentTypeThe type of the Text document (ANSI or UNICODE).
TextDocumentOptions.FormattedTo control whether the output file will be just a flow of text or try to maintain almost the same shape of original page (i.e. margins and lines between paragraphs using spaces).
TextDocumentOptions.AddPageBreakAdd an optional marker between pages in the resulting text file.
TextDocumentOptions.AddPageNumberPrint the page numbers in the resulting text file.

Inheritance Hierarchy

System.Object
   Leadtools.Forms.DocumentWriters.DocumentOptions
      Leadtools.Forms.DocumentWriters.TextDocumentOptions

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Leadtools.Forms.DocumentWriters requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features