Skip to content
How to open an encrypted locked PDF

How to open an encrypted locked PDF

Encrypted PDF documents can be easily decrypted by UniPDF by following this step below:

  • Check if the document is encrypted
pdfReader, _ := model.NewPdfReader(f)
isEncrypted, _ := pdfReader.IsEncrypted()
  • If the document is encrypted, call Decrypt to decrypt it using a password
if isEncrypted {
 documentPassword := "unlockthedoc"

 auth, err := pdfReader.Decrypt([]byte(documentPassword))

 if !auth {
 return errors.New("Decryption failed")
 }
}
  • If there’s no error, then the document is successfully decrypted and you can continue processing the document.

For a complete example on how to unlock an encrypted PDF document, see our user guide.