Leadtools.Forms.DocumentWriters Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
PdfDocumentOptions Class
See Also  Members   Example 
Leadtools.Forms.DocumentWriters Namespace : PdfDocumentOptions Class



Provides extra options to use when saving a document using the Adobe Portable Document Format (PDF).

Syntax

Visual Basic (Declaration) 
Public Class PdfDocumentOptions 
   Inherits DocumentOptions
Visual Basic (Usage)Copy Code
Dim instance As PdfDocumentOptions
C# 
public class PdfDocumentOptions : DocumentOptions 
C++/CLI 
public ref class PdfDocumentOptions : public DocumentOptions 

Example

This example will create a new Adobe Portable Document Format document (PDF) file using the various supported options.

Visual BasicCopy Code
' 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
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()

   ' Create a new instance of the LEADTOOLS Document Writer
   Dim docWriter As New DocumentWriter()

   Dim pdfFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Test1.pdf"
   Dim pdfFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Test2.pdf"

   Dim emfFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf"
   Dim tifFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "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

   ' 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()
   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 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 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   DocumentWriter docWriter = new DocumentWriter(); 
 
   string pdfFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "Test1.pdf"; 
   string pdfFileName2 = LeadtoolsExamples.Common.ImagesPath.Path + "Test2.pdf"; 
 
   string emfFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.emf"; 
   string tifFileName = LeadtoolsExamples.Common.ImagesPath.Path + "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; 
 
   // 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(); 
   RasterCodecs.Shutdown(); 
}

Remarks

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 DOC format, perform the following steps:

  1. Use the DocumentWriter.GetOptions method of the DocumentWriter object being used. Passing DocumentFormat.Pdf to the Format parameter. Note that the resulting object from the base DocumentOptions class needs to be cast to PdfDocumentOptions.
  2. Use the various PdfDocumentOptions properties to change the options.
  3. Use DocumentWriter.SetOptions to set the new options in the engine.
  4. Now you can call the DocumentWriter.BeginDocument method (again, with DocumentFormat.Pdf for the Format parameter) to create a new document and add the pages.

The PdfDocumentOptions class contains the following features:
FeatureDescription
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 modeUse 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.
Set the PDF document metadataThe 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:

  • Protected against viewing. PDF viewers will request a password from the user when the document is opened for viewing. This password is called the user password. The created PDF document can be protected by setting the PdfDocumentOptions.Protected property to true and the PdfDocumentOptions.UserPassword property to the password value.

  • Protected against editing. PDF editor will request a password from the user when the document is opened for editing. This password is called the owner password. The created PDF document can be protected by setting the PdfDocumentOptions.Protected property to true and the PdfDocumentOptions.OwnerPassword property to the password value.

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:

EncryptionOwner Access Right
Low (PdfDocumentOptions.EncryptionMode set to PdfDocumentEncryptionMode.RC40Bit)Printing (PdfDocumentOptions.PrintEnabled), Copying text (PdfDocumentOptions.CopyEnabled), Editing (PdfDocumentOptions.EditEnabled) and Annotations and comments (PdfDocumentOptions.AnnotationsEnabled).
High (PdfDocumentOptions.EncryptionMode set to PdfDocumentEncryptionMode.RC128Bit)Adds the following to owner access rights supported by low level encryption: High quality printing (PdfDocumentOptions.HighQualityPrintEnabled) and adding/removing pages PdfDocumentOptions.AssemblyEnabled.

Inheritance Hierarchy

System.Object
   Leadtools.Forms.DocumentWriters.DocumentOptions
      Leadtools.Forms.DocumentWriters.PdfDocumentOptions

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Leadtools.Forms.DocumentWriters requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features