LtdDocumentOptions Class
Summary
Provides extra options to use when saving a document using the LEADTOOLS Temporary Document (LTD) format.
Syntax
C#
VB
Java
Objective-C
WinRT C#
C++
@interface LTLtdDocumentOptions : LTDocumentOptions <NSCopying, NSCoding>
public class LtdDocumentOptions extends DocumentOptions
function Leadtools.Forms.DocumentWriters.LtdDocumentOptions()
Example
This example will create a new LEADTOOLS Temporary Document (LTD) over multiple sessions then convert the result to a PDF file.
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools
Imports Leadtools.Codecs
Public Sub LtdDocumentOptionsExample()
Dim inputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx")
Dim outputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf")
Dim ltdFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.ltd")
' Check if the LTD file exists, if so, delete it so we start a new session
If File.Exists(ltdFileName) Then File.Delete(ltdFileName)
' Get the number of pages
Dim pageCount As Integer
Using codecs As New RasterCodecs()
codecs.Options.RasterizeDocument.Load.Resolution = 300
pageCount = codecs.GetTotalPages(inputFileName)
End Using
' Loop through the pages and add them to the LTD
For pageNumber As Integer = 1 To pageCount
AppendToLtd(inputFileName, pageNumber, ltdFileName)
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, outputFileName, DocumentFormat.Pdf)
End Sub
Private Sub AppendToLtd(inputFileName As String, pageNumber As Integer, ltdFileName 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 docWriter As New DocumentWriter()
Using codecs As New RasterCodecs()
codecs.Options.RasterizeDocument.Load.Resolution = 300
' Create a new (or append if the file exists) LTD document
docWriter.BeginDocument(ltdFileName, DocumentFormat.Ltd)
' Load the page as SVG document and as Raster image
Console.WriteLine("Loading page {0} ...", pageNumber)
Using svgDocument As ISvgDocument = codecs.LoadSvg(inputFileName, pageNumber, Nothing)
Using image As RasterImage = codecs.Load(inputFileName, pageNumber)
' Add the page, notice we will be using image/text feature
Dim page As New DocumentSvgPage()
page.SvgDocument = svgDocument
page.Image = image
Console.WriteLine("Adding page {0} ...", pageNumber)
docWriter.AddPage(page)
End Using
End Using
End Using
' Finally finish writing the PDF file on disk
docWriter.EndDocument()
End Sub
using Leadtools.Forms.DocumentWriters;
using Leadtools;
using Leadtools.Codecs;
public void LtdDocumentOptionsExample()
{
var inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx");
var outputFileName = Path.Combine(LEAD_VARS.ImagesDir,"Example.pdf");
var ltdFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.ltd");
// Check if the LTD file exists, if so, delete it so we start a new session
if (File.Exists(ltdFileName))
File.Delete(ltdFileName);
// Get the number of pages
int pageCount;
using (var codecs = new RasterCodecs())
{
codecs.Options.RasterizeDocument.Load.Resolution = 300;
pageCount = codecs.GetTotalPages(inputFileName);
}
// Loop through the pages and add them to the LTD
for (var pageNumber = 1; pageNumber < pageCount; pageNumber++)
{
AppendToLtd(inputFileName, pageNumber, ltdFileName);
}
// Create a new instance of the LEADTOOLS Document Writer
var docWriter = new DocumentWriter();
// Set the PDF options to be PDF/A with Image/Text
var 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, outputFileName, DocumentFormat.Pdf);
}
private void AppendToLtd(string inputFileName, int pageNumber, string ltdFileName)
{
// 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
var docWriter = new DocumentWriter();
using (var codecs = new RasterCodecs())
{
codecs.Options.RasterizeDocument.Load.Resolution = 300;
// Create a new (or append if the file exists) LTD document
docWriter.BeginDocument(ltdFileName, DocumentFormat.Ltd);
// Load the page as SVG document and as Raster image
Console.WriteLine("Loading page {0} ...", pageNumber);
using (var svgDocument = codecs.LoadSvg(inputFileName, pageNumber, null))
using (var image = codecs.Load(inputFileName, pageNumber))
{
// Add the page, notice we will be using image/text feature
var page = new DocumentSvgPage();
page.SvgDocument = svgDocument;
page.Image = image;
Console.WriteLine("Adding page {0} ...", pageNumber);
docWriter.AddPage(page);
}
}
// Finally finish writing the PDF file on disk
docWriter.EndDocument();
}