DocumentRestrictions.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GrapeCity.Documents.Pdf.Security
  10.  
  11. '' This sample shows how to set restrictions on a PDF,
  12. '' e.g. restricting the ability to print Or copy content
  13. '' from the document.
  14. '' See also the DocumentPermissions sample, which shows
  15. '' how to examine restrictions in a loaded PDF.
  16. Public Class DocumentRestrictions
  17. Function CreatePDF(ByVal stream As Stream) As Integer
  18. '' Create a New PDF document:
  19. Dim doc = New GcPdfDocument()
  20. Dim rc = Util.AddNote("This document has the following restrictions:" + vbLf +
  21. " - printing is not allowed;" + vbLf +
  22. " - content copying is not allowed;" + vbLf +
  23. " - document assembly is not allowed.", doc.NewPage())
  24.  
  25. '' Create a Rev4 security handler And specify some restrictions:
  26. Dim ssh4 = New StandardSecurityHandlerRev4() With
  27. {
  28. .PrintingPermissions = PrintingPermissions.Disabled,
  29. .CopyContent = False,
  30. .EditingPermissions = EditingPermissions.Disabled
  31. }
  32. '' Assign the handler we created to the document so that it Is used when saving the PDF
  33. doc.Security.EncryptHandler = ssh4
  34.  
  35. '' Add a text prompting the user to check out the source code
  36. Dim pg = doc.Pages.Last
  37. Dim g = pg.Graphics
  38. Dim tl = g.CreateTextLayout()
  39. tl.AppendLine("See the source code of this demo for details on how to use a security handler to set PDF document restrictions.")
  40. tl.MaxWidth = pg.Bounds.Width - rc.X * 2
  41. tl.MarginLeft = rc.X
  42. tl.MarginTop = rc.Bottom + 36
  43. g.DrawTextLayout(tl, PointF.Empty)
  44.  
  45. '' Done
  46. doc.Save(stream)
  47. Return doc.Pages.Count
  48. End Function
  49. End Class
  50.