
using System; using System.Collections.Generic; using System.Text; using Bytescout.PDF; namespace HelloWorldWithSecurity_HiPrintRemoved { class Program { static void Main(string[] args) { #region Create PDF with security // Create main PDF Doc Engine PDFDocEngine engine = new PDFDocEngine("", ""); // Add new document Document document = engine.AddDocument(); // Append new page to the document Page page = document.AddPage(PageSizeType.A3, PageOrientationType.LandScape); // Create new drawing Drawing drawing = page.AddDrawing(); // Add standard font uint font = document.AddFontStandard(StandardFontType.Courier, FontEncodingType.WinAnsi); // Set Active Font drawing.SetActiveFont(font, 50, false, false); // Draw Text drawing.PlaceText(100, 100, 0, "Hello World!"); // Closing drawing on the page drawing.Close(); document.AddProtection(DocumentPermissionType.AssembleDocument | DocumentPermissionType.CopyInformation | DocumentPermissionType.ExtractTextAndImages | DocumentPermissionType.FillAcroForm | DocumentPermissionType.ModifyAnnotation | DocumentPermissionType.ModifyContent | DocumentPermissionType.Print | DocumentPermissionType.PrintHiResolution, SecurityKeyLength._128Bit, "123", "123"); // Save document document.Save("HelloWorldWithSecurity.pdf"); #endregion // Add new document document = engine.AddDocument("HelloWorldWithSecurity.pdf"); // check if document is protected if (document.Protected) { // check password if (document.ValidatePassword("123") == PasswordValidationType.Invalid) { Console.WriteLine("Invalid password"); } else // removing protection document.RemoveProtection(); } // add new protection document.AddProtection(document.Permissions ^ DocumentPermissionType.PrintHiResolution, SecurityKeyLength._128Bit, "", ""); // Save document document.Save("HelloWorldWithSecurity_HiPrintRemoved.pdf"); } } }