Provides extra options to use when saving a document using the LEADTOOLS Temporary Document (LTD) format.
Syntax
Visual Basic (Declaration) | |
---|
Public Class LtdDocumentOptions
Inherits DocumentOptions |
Example
This example will create a new LEADTOOLS Temporary Document (LTD) over multiple sessions then convert the result to a PDF file.
Visual Basic | Copy Code |
---|
<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()
RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here")
Dim pdfFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Test.pdf"
Dim ltdFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Test.ltd"
Dim tifFileNames() As String = _
{ _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr2.tif", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr3.tif", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr4.tif" _
}
Dim emfFileNames() As String = _
{ _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr2.emf", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr3.emf", _
LeadtoolsExamples.Common.ImagesPath.Path + "Ocr4.emf" _
}
If (File.Exists(ltdFileName)) Then
File.Delete(ltdFileName)
End If
For i As Integer = 0 To tifFileNames.Length - 1
AppendToLtd(ltdFileName, tifFileNames(i), emfFileNames(i))
Next
Dim docWriter As New DocumentWriter()
dim pdfOptions as PdfDocumentOptions = directcast(docWriter.GetOptions(DocumentFormat.Pdf) , PdfDocumentOptions)
pdfOptions.DocumentType = PdfDocumentType.PdfA
pdfOptions.ImageOverText = True
docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions)
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)
RasterCodecs.Startup()
Dim codecs As New RasterCodecs()
Dim docWriter As New DocumentWriter()
docWriter.BeginDocument(ltdFileName, DocumentFormat.Ltd)
Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName)
Dim image As RasterImage = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
Dim page As DocumentPage = DocumentPage.Empty
page.EmfHandle = emfHandle
page.Image = image
Console.WriteLine("Adding page...")
docWriter.AddPage(page)
DeleteEnhMetaFile(emfHandle)
image.Dispose()
docWriter.EndDocument()
codecs.Dispose()
RasterCodecs.Shutdown()
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 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 = LeadtoolsExamples.Common.ImagesPath.Path + "Test.pdf"; string ltdFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Test.ltd"; string[] tifFileNames = { LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif", LeadtoolsExamples.Common.ImagesPath.Path + "Ocr2.tif", LeadtoolsExamples.Common.ImagesPath.Path + "Ocr3.tif", LeadtoolsExamples.Common.ImagesPath.Path + "Ocr4.tif" }; string[] emfFileNames = { LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf", LeadtoolsExamples.Common.ImagesPath.Path + "Ocr2.emf", LeadtoolsExamples.Common.ImagesPath.Path + "Ocr3.emf", LeadtoolsExamples.Common.ImagesPath.Path + "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.Startup(); 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(); RasterCodecs.Shutdown(); } |
Remarks
Inheritance Hierarchy
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also