API referenceEncryption

pdfDecryptPDF

Decrypt the currently-open import file to a new,

C
int32_t __stdcall pdfDecryptPDFA(PPDF IPDF, const char* FileName, int32_t PwdType, const char* Password);
int32_t __stdcall pdfReEncryptPDFA(PPDF IPDF, const char* FileName, int32_t PwdType, const char* InPwd, const char* NewOpenPwd, const char* NewOwnerPwd, TKeyLen NewKeyLen, TRestrictions Restrict);
Delphi
function pdfDecryptPDFA(const IPDF: PPDF; const FileName: PAnsiChar; PwdType: Integer; const Password: PAnsiChar): Integer; stdcall;
function pdfReEncryptPDFA(const IPDF: PPDF; const FileName: PAnsiChar; PwdType: Integer; const InPwd, NewOpenPwd, NewOwnerPwd: PAnsiChar; NewKeyLen: TKeyLen; Restrict: TRestrictions): Integer; stdcall;

Purpose. Decrypt the currently-open import file to a new, unencrypted output file, or re-encrypt it with entirely new key material — both real, working operations over the *import* source (pdfOpenImportFile*), not the live document being edited.

Description. Both are literally the same underlying engine (ImportDecryptToFile), differing only in a ReEncrypt boolean. ImportDecryptToFile re-opens the import source path with the supplied password (OpenImportFileWithPwd, decrypting it), optionally re-arms SetEncryption with new key material if ReEncrypt = True, then imports the whole decrypted-or-reencrypted PDF (ImportWholePDF) into a fresh output document and closes it — a genuine full decrypt/re-encrypt round trip through the real import/object-copy pipeline, not merely stripping/rewriting the /Encrypt dictionary in place. PwdType is accepted by both wrappers' ABI but this chapter did not find it actually distinguishing user-vs-owner password in ImportDecryptToFile/OpenImportFileWithPwd — a single Pwd value is tried regardless.

Parameters.

ParameterDescription
IPDFDocument handle (whose *import file* is decrypted/re-encrypted).
FileNameOutput file path for the decrypted/re-encrypted copy.
PwdTypeAccepted; not confirmed to affect password matching.
Password / InPwdThe password to open the encrypted import source.
NewOpenPwd, NewOwnerPwd, NewKeyLen, Restrict*(ReEncrypt only)* New encryption parameters applied before the re-import.

Return value. The number of pages imported into the output (ImportWholePDF's result) on success; 0 if FileName is nil, no import file is open, the password fails to open it, or the final close fails.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfDecryptPDFA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string Password);
public static extern int pdfDecryptPDFW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string Password);
Area
Encryption
Category

Encryption

Exported names

pdfDecryptPDFA pdfDecryptPDFW

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.