LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
DocxDocumentOptions Class
See Also  Members  
Leadtools.Forms.DocumentWriters Namespace : DocxDocumentOptions Class



The DocxDocumentOptions Class is available as an add-on to the LEADTOOLS Document and Medical Imaging toolkits.

Provides extra options to use when saving a document using the Microsoft Word 2007 format (DOCX).

Object Model

DocxDocumentOptions Class

Syntax

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

Example

This example will create a new Microsoft Word 2007 document (DOCX) 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 DocxDocumentOptionsExample()
      ' 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.docx")
      Dim emfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf")

      ' Change the DOCX options to add frames to the file
      Dim docxOptions As DocxDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Docx), DocxDocumentOptions)
      docxOptions.Framed = True

      docWriter.SetOptions(DocumentFormat.Docx, docxOptions)

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

      ' 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 DOCX file on disk
      docWriter.EndDocument()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
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 DocxDocumentOptionsExample()
   {
      // 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 = Path.Combine(LEAD_VARS.ImagesDir, "Test.docx");
      string emfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf");

      // Change the DOCX options to add frames to the file
      DocxDocumentOptions docxOptions = docWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;
      docxOptions.Framed = true;

      docWriter.SetOptions(DocumentFormat.Docx, docxOptions);

      // Create a new DOCX document
      Console.WriteLine("Creating new DOCX document: {0}", outputFileName);
      docWriter.BeginDocument(outputFileName, DocumentFormat.Docx);

      // 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 DOCX file on disk
      docWriter.EndDocument();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}

Remarks

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

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

  1. Use the DocumentWriter.GetOptions method of the DocumentWriter object being used passing DocumentFormat.Docx to the format parameter. Note that the resulting object from the base DocumentOptions class needs to be cast to DocxDocumentOptions.
  2. Use the various DocxDocumentOptions 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.Docx for the format parameter) to create a new document and add the pages.

The DocxDocumentOptions class contains the following properties:

Property Description
DocxDocumentOptions.Framed Turn off or on the option to put the text blocks inside a frame (text box object) in the resulting DOCX file.

This format requires .NET framework 3.0 and Microsoft Open XML Format SDK 1.0. The Microsoft Open XML Format SDK requires Windows Server 2003 family or later, Windows Vista or later, or Windows XP Service Pack 2. For more information, refer to Files to be Included with Your Application.

Inheritance Hierarchy

System.Object
   Leadtools.Forms.DocumentWriters.DocumentOptions
      Leadtools.Forms.DocumentWriters.DocxDocumentOptions

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

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