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);
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.
| Parameter | Description |
|---|---|
IPDF | Document handle (whose *import file* is decrypted/re-encrypted). |
FileName | Output file path for the decrypted/re-encrypted copy. |
PwdType | Accepted; not confirmed to affect password matching. |
Password / InPwd | The 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)
public static extern int pdfReEncryptPDFA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string InPwd, [MarshalAs(UnmanagedType.LPStr)] string NewOpenPwd, [MarshalAs(UnmanagedType.LPStr)] string NewOwnerPwd, TKeyLen NewKeyLen, int Restrict);
public static extern int pdfReEncryptPDFW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string InPwd, [MarshalAs(UnmanagedType.LPStr)] string NewOpenPwd, [MarshalAs(UnmanagedType.LPStr)] string NewOwnerPwd, TKeyLen NewKeyLen, int Restrict);
Core
pdfReEncryptPDFA
pdfReEncryptPDFW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.