'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.Security PublicClassSecurityHandlerRev6PublicFunctionCreatePDF(ByVal stream AsStream) AsInteger' Sample passwords:ConstownerPasswordAsString = "I'm the owner"ConstuserPasswordAsString = "I'm a user" ' Step 1: Generate a document with some security attributes:Dim doc0 = NewGcPdfDocument()Dim rc0 = Util.AddNote("Demonstrating the use of the Standard Security Handler Revision 6.", doc0.NewPage()) ' Create a Rev6 security handler and set security properties:Dim ssh6 = NewStandardSecurityHandlerRev6() With { .OwnerPassword = ownerPassword, .UserPassword = userPassword, .CopyContent = False, .PrintingPermissions = PrintingPermissions.Disabled, .EncryptStrings = True } ' Assign the handler we created to the document so that it is used when saving the PDF: doc0.Security.EncryptHandler = ssh6 ' Save the PDF in a temp file. It will be loaded and examined in the next step:Dim fn = Path.GetTempFileName() doc0.Save(fn) ' Step 2: Load the generated PDF and examine its security attributes:Dim doc = NewGcPdfDocument()Using fs = File.OpenRead(fn)' User password is needed to load the document: doc.Load(fs, userPassword) ' At this point we can examine doc.Security.DecryptHandler if it exists,' but there is NO Security.EncryptHandler:If doc.Security.EncryptHandlerIsNotNothingThenThrowNew Exception("This should not happen.")EndIf Dim dh = doc.Security.DecryptHandlerIfTypeOf dh IsStandardSecurityHandlerRev6ThenDim dh_ssh6 = DirectCast(dh, StandardSecurityHandlerRev6)' Print out some of the permissions in the loaded PDF that was generated in Step 1:Dim txt = $"Some of the security attributes found in the PDF " &$"that was generated using StandardSecurityHandlerRev6:{vbLf}" &$"- EncryptionAlgorithm: {dh_ssh6.EncryptionAlgorithm}{vbLf}" &$"- EncryptionKeyLength: {dh_ssh6.EncryptionKeyLength}{vbLf}" &$"- CopyContent: {dh_ssh6.CopyContent}{vbLf}" &$"- PrintingPermissions: {dh_ssh6.PrintingPermissions}{vbLf}" &$"- EncryptStrings: {dh_ssh6.EncryptStrings}{vbLf}" Util.AddNote( txt, doc.Pages(0),NewRectangleF(72, rc0.Bottom + 36, 72 * 6, 72 * 2)) ' This won't work, sorry:Dim noway = dh_ssh6.OwnerPasswordIf noway IsNotNothingThenThrowNew Exception("This should not happen.")EndIfEndIf ' Save the new PDF. Please note that because we did not set the Security.EncryptHandler' on this PDF, this document (unlike the one that was generated in Step 1) has no security: doc.Save(stream)EndUsing' Clean up the temp file:File.Delete(fn)'' Done:Return doc.Pages.CountEndFunctionEndClass