DocumentRestrictions.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using GrapeCity.Documents.Pdf;
  9. using GrapeCity.Documents.Text;
  10. using GrapeCity.Documents.Pdf.Security;
  11.  
  12. namespace DsPdfWeb.Demos
  13. {
  14. // This sample shows how to set restrictions on a PDF,
  15. // e.g. restricting the ability to print or copy content
  16. // from the document.
  17. // See also the DocumentPermissions sample, which shows
  18. // how to examine restrictions in a loaded PDF.
  19. public class DocumentRestrictions
  20. {
  21. public int CreatePDF(Stream stream)
  22. {
  23. // Create a new PDF document:
  24. var doc = new GcPdfDocument();
  25. Common.Util.AddNote("This document has the following restrictions:\n" +
  26. " - printing is not allowed;\n" +
  27. " - content copying is not allowed;\n" +
  28. " - document assembly is not allowed.", doc.NewPage());
  29.  
  30. // Create a Rev4 security handler and specify some restrictions:
  31. var ssh4 = new StandardSecurityHandlerRev4()
  32. {
  33. // EncryptionAlgorithm = EncryptionAlgorithm.AES,
  34. // EncryptStrings = true,
  35. PrintingPermissions = PrintingPermissions.Disabled,
  36. CopyContent = false,
  37. EditingPermissions = EditingPermissions.Disabled
  38. };
  39.  
  40. // Assign the handler we created to the document so that it is used when saving the PDF:
  41. doc.Security.EncryptHandler = ssh4;
  42.  
  43. // Done:
  44. doc.Save(stream);
  45. return doc.Pages.Count;
  46. }
  47. }
  48. }
  49.