public bool Protected { get; set; }
true to create a protected PDF document, otherwise; false. Default value is false.
This is used when creating encrypted PDF documents. PDF documents can be encrypted at two levels: low (40-bit RC4) and high (128-bit RC4). To change the encryption level, use the EncryptionMode property.
PDF documents can be protected (secured) in two different ways, as follows:
Protected against viewing. PDF viewer applications will request a password from the user when the document is opened for viewing. This password is called the user password. To protect a PDF document against viewing, set the Protected property to true and the UserPassword property to the password value.
Protected against editing. PDF editor applications will request a password from the user when the document is opened for editing. This password is called the owner password. To protect a PDF document against editing, set the Protected property to true and the 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:
Encryption | Owner 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. |
Note that Owner Access Rights (UserPassword and OwnerPassword) have effect only if you set the Protected property to true.
Note that Protected is not supported when the DocumentType is PdfDocumentType.PdfA.
using Leadtools.Document.Writer;
using Leadtools.Ocr;
using Leadtools;
using Leadtools.Codecs;
public void PdfDocumentOptionsExample()
{
var inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.docx");
var outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf");
// Setup a new RasterCodecs object
var codecs = new RasterCodecs();
codecs.Options.RasterizeDocument.Load.Resolution = 300;
// Get the number of pages in the input document
var pageCount = codecs.GetTotalPages(inputFileName);
// Create a new instance of the LEADTOOLS Document Writer
var docWriter = new DocumentWriter();
// Change the PDF options
var 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);
// Create a new PDF document
Debug.WriteLine("Creating new PDF document: {0}", outputFileName);
docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf);
// Loop through all the pages
for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++)
{
// Get the page as SVG
Debug.WriteLine("Loading page {0}", pageNumber);
var page = new DocumentWriterSvgPage();
page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, null);
// Add the page
Debug.WriteLine("Adding page {0}", pageNumber);
docWriter.AddPage(page);
page.SvgDocument.Dispose();
}
// Finally finish writing the PDF file on disk
docWriter.EndDocument();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}