8.3 Handling password protected documents

Some document types (such as PDF) can require passwords to allow the file to be opened. After you have obtained a fz_document, you should therefore check whether it needs a password using fz_needs_password:

/* 
   fz_needs_password: Check if a document is encrypted with a 
   non-blank password. 
 
   Does not throw exceptions. 
*/ 
int fz_needs_password(fz_context *ctx, fz_document *doc);

If a password is required, you can supply one using fz_authenticate_password:

/* 
   fz_authenticate_password: Test if the given password can 
   decrypt the document. 
 
   password: The password string to be checked. Some document 
   specifications do not specify any particular text encoding, so 
   neither do we. 
 
   Returns 0 for failure to authenticate, non-zero for success. 
 
   For PDF documents, further information can be given by examining 
   the bits in the return code. 
 
      Bit 0 => No password required 
      Bit 1 => User password authenticated 
      Bit 2 => Owner password authenticated 
 
   Does not throw exceptions. 
*/ 
int fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password);