Use the LEADTOOLS DocumentWriters to create popular multi-page and searchable document formats from SVG, EMF, and RasterImage objects.
The LEADTOOLS DocumentWriters support the creation of the following document formats:
Adobe Portable Document Format (PDF), including support for PDF/A and optional image over text overlays
Microsoft Word Document (DOCX and DOC)
Microsoft Excel Spreadsheet (XLS)
Microsoft Open XML Paper Specification (XPS)
Rich Text Format (RTF)
ePUB open e-book standard
ALTO XML (Library of Congress OCR text and layout information). Part of the METS standard
Scalable Vector Graphics (SVG)
Text (ANSI, UTF8, and UTF16)
Windows Enhanced Metafile Format (EMF)
A document is created by adding one or more Leadtools.Forms.DocumentWriters.DocumentPage derived pages. Input data can include SVG, EMF, RasterImage, or an empty page.
The DocumentWriters support adding pages from standard SVG objects using the Leadtools.Forms.DocumentWriters.DocumentSvgPage class. You can use one of the following methods to obtain an SVG document:
Use the Leadtools.Codecs.RasterCodecs.LoadSvg method. Besides SVG, this method can convert a variety of documents (such as PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX, Text, RTF, and many more) and vector (such as DXF and DWG)
Recognize the text and layout data of any RasterImage using the LEADTOOLS OCR engine and save the result as SVG by calling the IOcrDocument.Save method, specifying DocumentFormat.Svg as the output format
Load a document page as SVG using the LEADTOOLS Documents Framework
All of these methods return an ISvgDocument object that can be used to create documents as described later in this document.
The storage of size information in SVG documents is optional. If a document has a size, it is stored in the width and height attributes of the root
svg element and can be in any coordinate system. An SVG renderer will typically use this value to determine the final bounding rectangle of the document. SVG documents contain a hierarchy of elements. The final transformation (such as position and size) and style (such as color and fill) may depend on the transformation and style of the parent(s) inside the hierarchy. Calculations have to be done to keep track of this information when converting the SVG file. This procedure is defined by LEADTOOLS as flattening the document. For more information, refer to SVG Size, Bounds, and Flat.
An EMF is a collection of structures that stores a picture in a device-independent format. Device independence is the one feature that sets metafiles apart from raster images. Unlike a raster image, a metafile guarantees device independence. EMF files can contain various objects such as Text, Lines, and raster images. EMF also contains Dots/Inch (DPI) information that is used to calculate the real size of the picture stored inside.
The DocumentWriters support adding pages from Windows Enhanced Metafile (EMF) objects by using the Leadtools.Forms.DocumentWriters.DocumentEmfPage class. These can be obtained from various sources, for example:
Creating an EMF object directly using Windows GDI or GDI+ functionality. The Leadtools.Forms.DocumentWriters.DocumentEmfPage class documentation has an example that shows how to do this
Annotating an image. The LEADTOOLS Annotations toolkit can export an EMF file representation of the annotation objects in a container. Therefore, the Annotations toolkit can be used to create a document, populate it with various annotations objects, and then save the result as a PDF file by using the DocumentWriter class. The Document Writer demo included with the LEADTOOLS Toolkit shows an implementation of this scenario. For more information, refer to Programming With LEADTOOLS Annotations
The Dots/Inch (DPI) of the page is the same as the DPI stored in the DocumentEmfPage.EmfHandle property. For example, to create a page with 300 DPI, add a document page with an EMF having a DPI of 300 (both horizontally and vertically). This is just an example: the LEADTOOLS Document Writer supports different values for DPI. If you are 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.
The DocumentWriters support adding pages from LEADTOOLS RasterImage objects using the Leadtools.Forms.DocumentWriters.DocumentRasterPage class. These can be obtained from various sources, for example:
Loading a RasterImage from a file on disk or stream using the RasterCodecs class
Obtaining a RasterImage from a TWAIN, SANE, or WIA device
Converting a RasterImage from a platform image
The DocumentWriters also support adding empty pages using the Leadtools.Forms.DocumentWriters.DocumentEmptyPage class.
Perform the following steps to create a new document using the Leadtools.Forms.DocumentWriters.DocumentWriter class:
Create an instance of the Leadtools.Forms.DocumentWriters.DocumentWriter class.
Optional: Set the document options. For example, if you are planning to save the final document as PDF/A instead of the default PDF, call the DocumentWriter.GetOptions method to get an instance of the current PDF options stored in a Leadtools.Forms.DocumentWriters.PdfDocumentOptions object. Change the PdfDocumentOptions.DocumentType property to PdfDocumentType.PdfA, and set the options by calling the DocumentWriter.SetOptions method.
Optional: Subscribe to the DocumentWriter.Progress event if the ability to abort or monitor the progress of the operation is required, .
Call the DocumentWriter.BeginDocument method with the requested output file name and format to create a new document.
Add Leadtools.Forms.DocumentWriters.DocumentPage derived objects as pages to the document. Create an instance of Leadtools.Forms.DocumentWriters.DocumentRasterPage, Leadtools.Forms.DocumentWriters.DocumentSvgPage, Leadtools.Forms.DocumentWriters.DocumentEmfPage, or [Leadtools.Forms.DocumentWriters.DocumentEmptyPage]. Set the page to contain the data. For example, in a Leadtools.Forms.DocumentWriters.DocumentSvgPage, set the SvgDocument property to an SVG object. In a Leadtools.Forms.DocumentWriters.DocumentEmfPage, set the EmfHandle property to an EMF handle. If you are creating a PDF file with the "image over text" overlay option, then set the DocumentSvgPage.Image or DocumentEmfPage.Image property to the overlay image for the page.
Note that you can add different type of pages to create a document. For example, use an SVG for page 1, an EMF file for page 2, an empty page for page 3, and so forth.
Repeat the step above for each page in your source document(s)
Finally, call the DocumentWriter.EndDocument method to finalize the document and create it on disk
Note: You can use a Leadtools.Forms.DocumentWriters.DocumentWriter object to save one document at a time. After you call the DocumentWriter.BeginDocument method, end the document by adding the pages and then calling DocumentWriter.EndDocument before calling the DocumentWriter.BeginDocument method again to create a new document. DocumentWriter.BeginDocument will throw an exception if it is called while a document is already being created. You can create more than one instance of theLeadtools.Forms.DocumentWriters.DocumentWriter class, each with it own options, if multiple documents need to be created at the same time. The object and all its operations are safe for multi-threading.
Many of the document formats supported by the Leadtools.Forms.DocumentWriters.DocumentWriter class contain extra options that are controlled through the use of the DocumentWriter.GetOptions and DocumentWriter.SetOptions methods. These options can be saved to an external XML file using the DocumentWriter.SaveOptions method. Then the options can be reloaded using the DocumentWriter.LoadOptions method.
The progress of the document creation operation can be monitored through the DocumentWriter.Progress event. For example, it can be to used provide visual feedback using a progress bar or to provide a means for the user to abort the operation using a cancel button.
A LEADTOOLS Temporary Document (DocumentFormat.Ltd) can be used to create a persistent, temporary document file on disk to maintain pages between sessions. This can be helpful when you have large number of pages to add to a PDF document or when all of the pages cannot be obtained at the same time. (For example, in a server scenario a client may send one page at a time to the server.) After all of the pages are added to the temporary file on disk, you can call the DocumentWriter.Convert method to convert this file to the final document. You can also use the DocumentWriter.AppendLtd method to append pages from one LTD file to another.