Leadtools.Forms.DocumentWriters Namespace : PdfDocumentOptions Class |
public class PdfDocumentOptions : DocumentOptions
'Declaration Public Class PdfDocumentOptions Inherits DocumentOptions
'Usage Dim instance As PdfDocumentOptions
public sealed class PdfDocumentOptions : DocumentOptions
function Leadtools.Forms.DocumentWriters.PdfDocumentOptions()
public ref class PdfDocumentOptions : public DocumentOptions
The options set in the PdfDocumentOptions class will be used when the user saves a document using the DocumentFormat.Pdf format.
Before using the LEADTOOLS Document Writer to create PDF documents, you must unlock the RasterSupportType.DocumentWritersPdf key unless the document writers are being used from the LEADTOOLS OCR engine. For more information, refer to Unlocking Special LEAD Features.
To change the options used with the PDF format, perform the following steps:
The PdfDocumentOptions class contains the following features:
Feature | Description | ||||||
---|---|---|---|---|---|---|---|
Set the PDF document type to PDF or PDF/A. | Use the PdfDocumentOptions.DocumentType property to set the document type to either PDF or PDF/A. | ||||||
Control the font embedding mode | Use the PdfDocumentOptions.FontEmbedMode property to control how the fonts are embedded in the resulting PDF document. Note that PdfDocumentOptions.FontEmbedMode is not used when saving PDF/A files; all fonts are always embedded in the file. | ||||||
Add an image as an overlay on top of the PDF content. | Use the PdfDocumentOptions.ImageOverText property to add the original raster image as an overlay on top of the PDF content. The resulting document will look exactly like the original document. If this option is used, the overlay image must be set in the Image property of the DocumentPage object passed to the DocumentWriter.AddPage method. | ||||||
Create linearized PDF documents optimized for fast web viewing. | A linearized PDF file is a file that has been organized in a special way to enable efficient incremental access in a network environment. This allows the first page of the PDF file to be displayed in a user Web browser before the entire file is downloaded from the Web server. To enable the creation of linearized PDF documents, use the PdfDocumentOptions.Linearized property. PDF linearization is supported in both PDF and PDF/A formats. | ||||||
Set the PDF document metadata | The resulting PDF can contain optional metadata associated with the document. This metadata can be used by external search and indexing engines to search and classify PDF documents. Use the PdfDocumentOptions.Title, PdfDocumentOptions.Subject, PdfDocumentOptions.Author and PdfDocumentOptions.Keywords to set the document metadata. | ||||||
Security, access rights and Encryption |
PDF documents can be protected (secured) using two methods:
When a PDF document is protected against editing (through the use of an owner password), an encryption level and owner access rights can be granted or denied in the resulting document. The following table lists the PDF access rights supported by the LEADTOOLS Document Writers:
|
||||||
Add bookmarks in the final PDF document. | Use PdfAutoBookmark or PdfCustomBookmark to create either auto or custom (user) bookmarks in the final PDF documents. | ||||||
Create an annotated PDF document by adding an annotation objects. | Annotated PDF can be created by passing valid LEADTOOLS annotation container for each page that needs to be annotated inside the PDF document. Set the AnnotationContainer property to a valid LEADTOOLS annotation container before calling the DocumentWriter.AddPage method. |
' 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 PdfDocumentOptionsExample() ' 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") ' We are going to use RasterCodecs to load a TIF file Dim codecs As New RasterCodecs() ' Create a new instance of the LEADTOOLS Document Writer Dim docWriter As New DocumentWriter() Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Test1.pdf") Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Test2.pdf") Dim emfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf") Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") ' Create a new PDF document with: PDF and no image/text Dim pdfOptions As PdfDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions) pdfOptions.DocumentType = PdfDocumentType.Pdf pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None pdfOptions.ImageOverText = False docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions) Console.WriteLine("Creating new PDF document: {0}", pdfFileName1) docWriter.BeginDocument(pdfFileName1, DocumentFormat.Pdf) ' 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) ' Finally finish writing the PDF file on disk docWriter.EndDocument() ' Now create a new PDF document with: PDF/A and image/text pdfOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions) pdfOptions.DocumentType = PdfDocumentType.PdfA pdfOptions.FontEmbedMode = DocumentFontEmbedMode.All pdfOptions.ImageOverText = True pdfOptions.Linearized = False pdfOptions.Title = "Add your title here" pdfOptions.Subject = "Add your subject here" pdfOptions.Keywords = "Add your keywords here" pdfOptions.Author = "Add author name here" pdfOptions.Protected = True pdfOptions.UserPassword = "User password" pdfOptions.OwnerPassword = "Owner password" pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit pdfOptions.PrintEnabled = False pdfOptions.HighQualityPrintEnabled = True pdfOptions.CopyEnabled = False pdfOptions.EditEnabled = True pdfOptions.AnnotationsEnabled = True pdfOptions.AssemblyEnabled = False pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg pdfOptions.QualityFactor = 2 ' Use default resolution pdfOptions.DocumentResolution = 0 pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed ' Setup empty page size (Letter size) pdfOptions.EmptyPageWidth = 8.5 pdfOptions.EmptyPageHeight = 11 pdfOptions.EmptyPageResolution = 300 docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions) Console.WriteLine("Creating new PDF document: {0}", pdfFileName2) docWriter.BeginDocument(pdfFileName2, DocumentFormat.Pdf) ' Use the Windows API to load the EMF emfHandle = 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 page = DocumentPage.Empty page.EmfHandle = emfHandle page.Image = image Console.WriteLine("Adding EMF page from: {0}", emfFileName) 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 PdfDocumentOptionsExample() { // We are going to use RasterCodecs to load a TIF file RasterCodecs codecs = new RasterCodecs(); // Create a new instance of the LEADTOOLS Document Writer DocumentWriter docWriter = new DocumentWriter(); string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Test1.pdf"); string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Test2.pdf"); string emfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf"); string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); // Create a new PDF document with: PDF and no image/text PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; pdfOptions.DocumentType = PdfDocumentType.Pdf; pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None; pdfOptions.ImageOverText = false; pdfOptions.Linearized = false; pdfOptions.Title = "Add your title here"; pdfOptions.Subject = "Add your subject here"; pdfOptions.Keywords = "Add your keywords here"; pdfOptions.Author = "Add author name here"; pdfOptions.Protected = true; pdfOptions.UserPassword = "User password"; pdfOptions.OwnerPassword = "Owner password"; pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit; pdfOptions.PrintEnabled = false; pdfOptions.HighQualityPrintEnabled = true; pdfOptions.CopyEnabled = false; pdfOptions.EditEnabled = true; pdfOptions.AnnotationsEnabled = true; pdfOptions.AssemblyEnabled = false; pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate; pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg; pdfOptions.QualityFactor = 2; // Use default resolution pdfOptions.DocumentResolution = 0; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; // Setup empty page size (Letter size) pdfOptions.EmptyPageWidth = 8.5; pdfOptions.EmptyPageHeight = 11; pdfOptions.EmptyPageResolution = 300; docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); Console.WriteLine("Creating new PDF document: {0}", pdfFileName1); docWriter.BeginDocument(pdfFileName1, DocumentFormat.Pdf); // 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(); // Now create a new PDF document with: PDF/A and image/text pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; pdfOptions.DocumentType = PdfDocumentType.PdfA; pdfOptions.FontEmbedMode = DocumentFontEmbedMode.All; pdfOptions.ImageOverText = true; docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); Console.WriteLine("Creating new PDF document: {0}", pdfFileName2); docWriter.BeginDocument(pdfFileName2, DocumentFormat.Pdf); // Use the Windows API to load the EMF emfHandle = GetEnhMetaFile(emfFileName); RasterImage image = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); // Add the page, notice we will be using image/text feature page = DocumentPage.Empty; page.EmfHandle = emfHandle; page.Image = image; Console.WriteLine("Adding EMF page from: {0}", emfFileName); 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"; }
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