//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Security; namespaceDsPdfWeb.Demos{// This sample shows how to set restrictions on a PDF,// e.g. restricting the ability to print or copy content// from the document. // See also the SecurityHandlers sample, which shows// how to examine restrictions in a loaded PDF.publicclassDocumentRestrictions {publicintCreatePDF(Stream stream) {// Create a new PDF document:var doc = newGcPdfDocument();var rc = Common.Util.AddNote("This document has the following restrictions:\n" +" - printing is not allowed;\n" +" - content copying is not allowed;\n" +" - document assembly is not allowed.", doc.NewPage()); // Create a Rev4 security handler and specify some restrictions:var ssh4 = newStandardSecurityHandlerRev4() {// EncryptionAlgorithm = EncryptionAlgorithm.AES,// EncryptStrings = true,PrintingPermissions = PrintingPermissions.Disabled,CopyContent = false,EditingPermissions = EditingPermissions.Disabled };// Assign the handler we created to the document so that it is used when saving the PDF: doc.Security.EncryptHandler = ssh4; // Add a text prompting the user to check out the source code:var pg = doc.Pages.Last;var g = pg.Graphics;var tl = g.CreateTextLayout(); tl.AppendLine("See the source code of this demo for details on how to use a security handler to set PDF document restrictions."); tl.MaxWidth = pg.Bounds.Width - rc.X * 2; tl.MarginLeft = rc.X; tl.MarginTop = rc.Bottom + 36; g.DrawTextLayout(tl, PointF.Empty); // Done: doc.Save(stream);return doc.Pages.Count; } }}