How do I open an encrypted locked PDF document

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

  1. Check if the document is encrypted
    pdfReader, _ := model.NewPdfReader(f)
    isEncrypted, _ := pdfReader.IsEncrypted()
    	
  2. 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")
      }
    }
    	
  3. 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 this following code example

https://github.com/unidoc/unipdf-examples/blob/master/security/pdf_unlock.go