DocumentRestrictions.cs
- //
- // This code is part of Document Solutions for PDF demos.
- // Copyright (c) MESCIUS inc. All rights reserved.
- //
- using System;
- using System.IO;
- using System.Drawing;
- using GrapeCity.Documents.Pdf;
- using GrapeCity.Documents.Text;
- using GrapeCity.Documents.Pdf.Security;
-
- namespace DsPdfWeb.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 DocumentPermissions sample, which shows
- // how to examine restrictions in a loaded PDF.
- public class DocumentRestrictions
- {
- public int CreatePDF(Stream stream)
- {
- // Create a new PDF document:
- var doc = new GcPdfDocument();
- 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 = new StandardSecurityHandlerRev4()
- {
- // 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;
-
- // Done:
- doc.Save(stream);
- return doc.Pages.Count;
- }
- }
- }
-