Leadtools.Forms.DocumentWriters Namespace : TextDocumentOptions Class |
public class TextDocumentOptions : DocumentOptions
'Declaration Public Class TextDocumentOptions Inherits DocumentOptions
'Usage Dim instance As TextDocumentOptions
public sealed class TextDocumentOptions : DocumentOptions
function Leadtools.Forms.DocumentWriters.TextDocumentOptions()
public ref class TextDocumentOptions : public DocumentOptions
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:
The TextDocumentOptions class contains the following properties:
Property | Description |
---|---|
TextDocumentOptions.DocumentType | The type of the Text document (ANSI or UNICODE). |
TextDocumentOptions.Formatted | To 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.AddPageBreak | Add an optional marker between pages in the resulting text file. |
TextDocumentOptions.AddPageNumber | Print the page numbers in the resulting text file. |
Imports Leadtools.Forms.DocumentWriters Imports Leadtools Imports Leadtools.Codecs ' 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 = Path.Combine(LEAD_VARS.ImagesDir, "Test.txt") Dim emfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "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
using Leadtools.Forms.DocumentWriters; using Leadtools; // 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() { // Create a new instance of the LEADTOOLS Document Writer DocumentWriter docWriter = new DocumentWriter(); string outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Test.txt"); string emfFileName = Path.Combine(LEAD_VARS.ImagesDir, "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(); }