SetEncryptEmbeddedFilesOnly
Security, Attachments
Description
Restricts encryption to embedded files, so the document itself opens and renders without a password while its attachments stay protected.
Syntax
Delphi
Function TPDFlib.SetEncryptEmbeddedFilesOnly(Enable: Integer): Integer;Parameters
| Enable | Pass 1 before Encrypt to protect embedded files only, or 0 to restore whole-document encryption (the default). |
|---|
Return values
| 0 | Invalid value, or no document is selected. |
|---|---|
| 1 | Setting applied. |
Remarks
The encryption dictionary is written with /StmF and /StrF set to Identity and /EFF pointing at the standard crypt filter, the layout ISO 32000-2 7.6.6 defines for this case. Page content, strings and metadata stay in the clear, so any reader displays the document with no password prompt, while embedded file streams are encrypted and need the password to extract.
This is the usual shape for invoices, medical records and case files whose cover pages are meant to be public but whose payload is not. Requires AES-128 or AES-256; the older RC4 handlers have no crypt filter layer and ignore the setting.
Example
PDF.SetEncryptEmbeddedFilesOnly(1);
PDF.DrawText(50, 50, 'Public cover page');
PDF.AddEmbeddedFile('case-file.zip', 'application/zip');
PDF.Encrypt('owner-pw', '', 4, Perms); // AES-256
PDF.SaveToFile('dossier.pdf');See also
GetEncryptEmbeddedFilesOnly, Encrypt, AddEmbeddedFile, SetEncryptMetadata