DocumentRestrictions.vb
- ''
- '' This code is part of Document Solutions for PDF demos.
- '' Copyright (c) MESCIUS inc. All rights reserved.
- ''
- Imports System.IO
- Imports System.Drawing
- Imports GrapeCity.Documents.Pdf
- Imports GrapeCity.Documents.Text
- Imports GrapeCity.Documents.Pdf.Security
-
- '' 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
- Function CreatePDF(ByVal stream As Stream) As Integer
- '' Create a New PDF document:
- Dim doc = New GcPdfDocument()
- Dim rc = Util.AddNote("This document has the following restrictions:" + vbLf +
- " - printing is not allowed;" + vbLf +
- " - content copying is not allowed;" + vbLf +
- " - document assembly is not allowed.", doc.NewPage())
-
- '' Create a Rev4 security handler And specify some restrictions:
- Dim ssh4 = New StandardSecurityHandlerRev4() With
- {
- .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
- Dim pg = doc.Pages.Last
- Dim g = pg.Graphics
- Dim 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
- End Function
- End Class
-