Leadtools.Forms.DocumentWriters Namespace : DocumentWriter Class |
public class DocumentWriter
'Declaration Public Class DocumentWriter
'Usage Dim instance As DocumentWriter
public sealed class DocumentWriter
function Leadtools.Forms.DocumentWriters.DocumentWriter()
public ref class DocumentWriter
The DocumentWriter and the LEADTOOLS Document Writers toolkit is used to create multi-page and searchable documents from one or more Windows Enhanced Meta File (EMF) objects.
Support for various popular formats is included, such as PDF, XPS, DOC, HTML, RTF or Text. For a list of all the document formats supported, refer to the DocumentFormat enumeration.
To create a document from EMF, perform the following steps
The Windows Enhanced Meta File (EMF) objects can be obtained from various sources as shown in the following list:
Many of the document formats supported by DocumentWriter contain extra options and functionality that can be controlled through the use of the DocumentWriter.GetOptions and DocumentWriter.GetOptions methods. These options can be set and then saved to an external XML file using the DocumentWriter.SaveOptions method. Later, you can re-load these options using the DocumentWriter.LoadOptions method.
Support is provided to monitor the document creation operation through the DocumentWriter.Progress event. Your application can provide a visual feedback using a progress bar and a cancel button to the user to allow both monitoring and abortion of the current operation.
The LEADTOOLS Temporary Document format (DocumentFormat.Ltd) allows you to create a temporary document on disk that you can add pages to in between sessions. This can be helpful when you have large amount of pages to add to a PDF document for example or when not all the pages can be obtained at the same time (for example, in a server scenario when the client sends one page to the server at a time). After all pages are added to the temporary file on disk, you can use the DocumentWriter.Convert method to convert this file to the final document (for example PDF or DOC).
The Dots/Inch (DPI) of the page is the same as the DPI stored in the DocumentPage.EmfHandle property. Therefore, to create a page with 300 DPI, you must add a document page with an EMF that has a DPI of 300 (both horizontally or vertically although the LEADTOOLS Document Writer supports different values for the DPI). When using the PDF with image/text feature, set the DPI of the Leadtools.RasterImage object to the same DPI as the EMF handle using the RasterImage.XResolution and RasterImage.YResolution properties.
You can also use the DocumentWriter.AppendLtd method to append pages from one LTD file to another.
' 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 DocumentWriterExample() ' Create a new instance of the LEADTOOLS Document Writer Dim docWriter As New DocumentWriter() ' Create a new PDF document on disk Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "DocumentWriter.pdf") Console.WriteLine("Creating new PDF document: {0}", pdfFileName) docWriter.BeginDocument(pdfFileName, DocumentFormat.Pdf) ' Add the EMF files shipped with LEADTOOLS as pages to this document For i As Integer = 0 To 3 Dim emfFileName As String = String.Format("{0}Ocr{1}.emf", LEAD_VARS.ImagesDir, i + 1) ' Use the Windows API to load the EMF Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName) ' Add the page, notice we will not be using image/text feature (the default) 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) Next ' Finally finish writing the PDF 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
// 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 DocumentWriterExample() { // Create a new instance of the LEADTOOLS Document Writer DocumentWriter docWriter = new DocumentWriter(); // Create a new PDF document on disk string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "DocumentWriter.pdf"); Console.WriteLine("Creating new PDF document: {0}", pdfFileName); docWriter.BeginDocument(pdfFileName, DocumentFormat.Pdf); // Add the EMF files shipped with LEADTOOLS as pages to this document for(int i = 0; i < 4; i++) { string emfFileName = string.Format("{0}Ocr{1}.emf", LEAD_VARS.ImagesDir, i + 1); // Use the Windows API to load the EMF IntPtr emfHandle = GetEnhMetaFile(emfFileName); // Add the page, notice we will not be using image/text feature (the default) 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 PDF file on disk docWriter.EndDocument(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
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