Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) PDF Get Encryption and Permissions InformationSee more PDF Signatures ExamplesDetermine if a PDF is encrypted, and the associated user permissions. Note: Some PDFs are encrypted but not password-protected. In such cases, encryption is used primarily for preventing unauthorized modifications to the document, but it doesn't restrict access. Therefore, you can open and read the document without a password. Note: This example requires Chilkat v9.5.0.96 or later.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @pdf int -- Use "Chilkat_9_5_0.Pdf" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Pdf', @pdf OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Open a PDF. -- Starting in Chilkat v9.5.0.96, the LastJsonData will contain information about encryption and permissions. DECLARE @success int EXEC sp_OAMethod @pdf, 'LoadFile', @success OUT, 'c:/someDir/sample.pdf' IF @success = 0 BEGIN EXEC sp_OAGetProperty @pdf, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @pdf RETURN END -- Examine the LastJsonData DECLARE @ljd int EXEC sp_OAMethod @pdf, 'LastJsonData', @ljd OUT EXEC sp_OASetProperty @ljd, 'EmitCompact', 0 EXEC sp_OAMethod @ljd, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- Sample output: -- { -- "pdfVersion": "1.6", -- "encrypt": { -- "filter": "/Standard", -- "keyLength": 128, -- "V": 4, -- "R": 4, -- "P": -1340, -- "perm": { -- "printLowResolution": "allowed", -- "printHighResolution": "allowed", -- "modifyOther": "not allowed", -- "modifyAnnotations": "allowed", -- "modifyForms": "not allowed", -- "fillInForms": "allowed", -- "assembleDoc": "allowed", -- "extractAnyPurpose": "not allowed", -- "extractAccessibility": "not allowed" -- }, -- "method": "AESV2" -- } -- } -- Use this online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON DECLARE @pdfVersion nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @pdfVersion OUT, 'pdfVersion' DECLARE @Filter nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @Filter OUT, 'encrypt.filter' DECLARE @KeyLength int EXEC sp_OAMethod @ljd, 'IntOf', @KeyLength OUT, 'encrypt.keyLength' DECLARE @V int EXEC sp_OAMethod @ljd, 'IntOf', @V OUT, 'encrypt.V' DECLARE @R int EXEC sp_OAMethod @ljd, 'IntOf', @R OUT, 'encrypt.R' DECLARE @P int EXEC sp_OAMethod @ljd, 'IntOf', @P OUT, 'encrypt.P' DECLARE @PrintLowResolution nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @PrintLowResolution OUT, 'encrypt.perm.printLowResolution' DECLARE @PrintHighResolution nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @PrintHighResolution OUT, 'encrypt.perm.printHighResolution' DECLARE @ModifyOther nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @ModifyOther OUT, 'encrypt.perm.modifyOther' DECLARE @ModifyAnnotations nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @ModifyAnnotations OUT, 'encrypt.perm.modifyAnnotations' DECLARE @ModifyForms nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @ModifyForms OUT, 'encrypt.perm.modifyForms' DECLARE @FillInForms nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @FillInForms OUT, 'encrypt.perm.fillInForms' DECLARE @AssembleDoc nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @AssembleDoc OUT, 'encrypt.perm.assembleDoc' DECLARE @ExtractAnyPurpose nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @ExtractAnyPurpose OUT, 'encrypt.perm.extractAnyPurpose' DECLARE @ExtractAccessibility nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @ExtractAccessibility OUT, 'encrypt.perm.extractAccessibility' DECLARE @Method nvarchar(4000) EXEC sp_OAMethod @ljd, 'StringOf', @Method OUT, 'encrypt.method' EXEC @hr = sp_OADestroy @pdf END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.