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 |
Example
This example will create a new Adobe Portable Document Format document (PDF) file using the various supported options.
Visual Basic | Copy Code |
---|
<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()
RasterSupport.Unlock(RasterSupportType.DocumentWriters, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "Replace with your own key here")
RasterCodecs.Startup()
Dim codecs As New RasterCodecs()
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"
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)
Dim emfHandle As IntPtr = GetEnhMetaFile(emfFileName)
Dim page As DocumentPage = DocumentPage.Empty
page.EmfHandle = emfHandle
page.Image = Nothing
Console.WriteLine("Adding EMF page from: {0}", emfFileName)
docWriter.AddPage(page)
DeleteEnhMetaFile(emfHandle)
docWriter.EndDocument()
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.DocumentResolution = 0
pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed
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)
emfHandle = GetEnhMetaFile(emfFileName)
Dim image As RasterImage = codecs.Load(tifFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
page = DocumentPage.Empty
page.EmfHandle = emfHandle
page.Image = image
Console.WriteLine("Adding EMF page from: {0}", emfFileName)
docWriter.AddPage(page)
DeleteEnhMetaFile(emfHandle)
image.Dispose()
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
Inheritance Hierarchy
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also