Password protect the exported PDF (the password is "password")

DOCX PDF TIFF SVG JPG PNG C# VB
PasswordProtectPdf.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System.IO;
  6. using GrapeCity.Documents.Word;
  7. using GrapeCity.Documents.Word.Layout;
  8.  
  9. namespace DsWordWeb.Demos
  10. {
  11. // This example shows how to password protect the PDF document
  12. // when using GrapeCity.Documents.Word.Layout (GcWordLayout) to
  13. // save a DOCX as PDF.
  14. public class PasswordProtectPdf
  15. {
  16. public GcWordDocument CreateDocx()
  17. {
  18. GcWordDocument doc = new GcWordDocument();
  19. doc.Load(Path.Combine("Resources", "WordDocs", "ProcurementLetter.docx"));
  20. return doc;
  21. }
  22.  
  23. // Optional static method. If it is defined on a sample class,
  24. // these options are used when saving the document to PDF.
  25. public static PdfOutputSettings GetPdfOutputSettings()
  26. {
  27. var settings = new PdfOutputSettings();
  28. // This creates a security handler with both owner and user passwords
  29. // set to the passed string ("password" in this example):
  30. var sh = settings.CreateSecurityHandler("password");
  31. // Other SecurityHandler properties can be used to customize PDF protection,
  32. // e.g. here we protect the PDF content from copying, printing and editing:
  33. sh.CopyContent = false;
  34. sh.PrintingPermissions = GrapeCity.Documents.Pdf.Security.PrintingPermissions.Disabled;
  35. sh.EditingPermissions = GrapeCity.Documents.Pdf.Security.EditingPermissions.Disabled;
  36. return settings;
  37. }
  38. }
  39. }
  40.