LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly)
LEAD Technologies, Inc

LtdDocumentOptions Class

Example 





Members 
Provides extra options to use when saving a document using the LEADTOOLS Temporary Document (LTD) format. .NET support
Object Model
LtdDocumentOptions Class
Syntax
public class LtdDocumentOptions : DocumentOptions 
'Declaration
 
Public Class LtdDocumentOptions 
   Inherits DocumentOptions
'Usage
 
Dim instance As LtdDocumentOptions
public sealed class LtdDocumentOptions : DocumentOptions 
function Leadtools.Forms.DocumentWriters.LtdDocumentOptions()
public ref class LtdDocumentOptions : public DocumentOptions 
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.

Example
 
' 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()
      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
// 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()
   {
      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";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

LtdDocumentOptions Members
Leadtools.Forms.DocumentWriters Namespace
DocumentWriter Class
Programming with LEADTOOLS Document Writers
Files to be Included with Your Application
Unlocking Special LEAD Features

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

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