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



The LtdDocumentOptions 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 LEADTOOLS Temporary Document (LTD) format.

Object Model

LtdDocumentOptions Class

Syntax

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

Example

This example will create a new LEADTOOLS Temporary Document (LTD) over multiple sessions then convert the result to a PDF file.

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 LtdDocumentOptionsExample()
      ' Unlock the support needed for LEADTOOLS Document Writers (with PDF output)
      RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here")
      RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here")

      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Test.pdf")
      Dim ltdFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Test.ltd")

      Dim tifFileNames() As String = _
      { _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.tif"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.tif"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.tif") _
      }

      Dim emfFileNames() As String = _
      { _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.emf"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.emf"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.emf") _
      }

      ' Check if the LTD file exists, if so, delete it so we start a new session
      If (File.Exists(ltdFileName)) Then
         File.Delete(ltdFileName)
      End If

      ' Loop through the TIF/EMF pairs and add them to the LTD
      For i As Integer = 0 To tifFileNames.Length - 1
         AppendToLtd(ltdFileName, tifFileNames(i), emfFileNames(i))
      Next

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

      ' Set the PDF options to be PDF/A with Image/Text
      dim pdfOptions as PdfDocumentOptions = directcast(docWriter.GetOptions(DocumentFormat.Pdf) , PdfDocumentOptions)
      pdfOptions.DocumentType = PdfDocumentType.PdfA
      pdfOptions.ImageOverText = True
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions)

      ' Now convert the LTD file we generated to PDF
      Console.WriteLine("Converting LTD to PDF")
      docWriter.Convert(ltdFileName, pdfFileName, DocumentFormat.Pdf)
   End Sub

   Private Sub AppendToLtd(ByVal ltdFileName As String, ByVal tifFileName As String, ByVal emfFileName As String)
      ' This assumes we are in a separate session than the main program, so create
      ' a new instance of the RasterCodecs and DocumentWriter objects we need
      Dim codecs As New RasterCodecs()

      Dim docWriter As New DocumentWriter()

      ' Create a new (or append if the file exists) LTD document
      docWriter.BeginDocument(ltdFileName, DocumentFormat.Ltd)

      ' Add the page

      ' Use the Windows API to load the EMF
      Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName)
      Dim image As RasterImage = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)

      ' Add the page, notice we will be using image/text feature
      Dim page As DocumentPage = DocumentPage.Empty
      page.EmfHandle = emfHandle
      page.Image = image

      Console.WriteLine("Adding page...")
      docWriter.AddPage(page)

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

      ' We don't need the image anymore
      image.Dispose()

      ' Finally finish writing the PDF file on disk
      docWriter.EndDocument()

      codecs.Dispose()
   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 LtdDocumentOptionsExample()
   {
      // Unlock the support needed for LEADTOOLS Document Writers (with PDF output)
      RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here");
      RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here");

      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir,"Test.pdf");
      string ltdFileName = Path.Combine(LEAD_VARS.ImagesDir, "Test.ltd");

      string[] tifFileNames =
      {
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.tif"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.tif"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.tif")
      };

      string[] emfFileNames =
      {
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.emf"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.emf"),
         Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.emf")
      };

      // Check if the LTD file exists, if so, delete it so we start a new session
      if(File.Exists(ltdFileName))
         File.Delete(ltdFileName);

      // Loop through the TIF/EMF pairs and add them to the LTD
      for(int i = 0; i < tifFileNames.Length; i++)
      {
         AppendToLtd(ltdFileName, tifFileNames[i], emfFileNames[i]);
      }

      // Create a new instance of the LEADTOOLS Document Writer
      DocumentWriter docWriter = new DocumentWriter();

      // Set the PDF options to be PDF/A with Image/Text
      PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
      pdfOptions.DocumentType = PdfDocumentType.PdfA;
      pdfOptions.ImageOverText = true;
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);

      // Now convert the LTD file we generated to PDF
      Console.WriteLine("Converting LTD to PDF");
      docWriter.Convert(ltdFileName, pdfFileName, DocumentFormat.Pdf);
   }

   private void AppendToLtd(string ltdFileName, string tifFileName, string emfFileName)
   {
      // This assumes we are in a separate session than the main program, so create
      // a new instance of the RasterCodecs and DocumentWriter objects we need
      RasterCodecs codecs = new RasterCodecs();

      DocumentWriter docWriter = new DocumentWriter();

      // Create a new (or append if the file exists) LTD document
      docWriter.BeginDocument(ltdFileName, DocumentFormat.Ltd);

      // Add the page

      // Use the Windows API to load the EMF
      IntPtr emfHandle = GetEnhMetaFile(emfFileName);
      RasterImage image = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

      // Add the page, notice we will be using image/text feature
      DocumentPage page = DocumentPage.Empty;
      page.EmfHandle = emfHandle;
      page.Image = image;

      Console.WriteLine("Adding page...");
      docWriter.AddPage(page);

      // Use the Windows API to delete the EMF
      DeleteEnhMetaFile(emfHandle);

      // We don't need the image anymore
      image.Dispose();

      // Finally finish writing the PDF file on disk
      docWriter.EndDocument();

      codecs.Dispose();
   }

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

Remarks

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

The LEADTOOLS Temporary Document (LTD) format is a proprietary that support appending pages to an existing file, therefore, you can use the LTD format if you have large amount of pages to convert over multiple sessions. When calling the DocumentWriter.BeginDocument method with the DocumentFormat.Ltd format, the toolkit will check if the output file specified exists on disk. If it does, the new pages will be appended to the end of the file. When you are finished adding all the pages, you can use the DocumentWriter.Convert method to convert this temporary file to the desired output format such as PDF, HTML or DOC.

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

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

Currently, the LtdDocumentOptions class contains no extra options.

Inheritance Hierarchy

System.Object
   Leadtools.Forms.DocumentWriters.DocumentOptions
      Leadtools.Forms.DocumentWriters.LtdDocumentOptions

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