Decrypt PDF using Go
Contents
[
Hide
]
Decrypt PDF File using Owner Password
You can open, decrypt, and save a password-protected PDF document using the Aspose.PDF for Go via C++. The PDF file is opened with the owner password, decrypted to remove all security restrictions, and then saved as a new, unprotected document.
- Call OpenWithPassword and provide the file name along with the owner password to access the encrypted PDF.
- Call the Decrypt method to remove password protection and all associated security restrictions from the document.
- Save the decrypted PDF using SaveAs.
package main
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
import "log"
func main() {
// OpenWithPassword(filename string, password string) opens a password-protected PDF-document
pdf, err := asposepdf.OpenWithPassword("sample_with_password.pdf", "ownerpass")
if err != nil {
log.Fatal(err)
}
// Close() releases allocated resources for PDF-document
defer pdf.Close()
// Decrypt() decrypts PDF-document
err = pdf.Decrypt()
if err != nil {
log.Fatal(err)
}
// SaveAs(filename string) saves previously opened PDF-document with new filename
err = pdf.SaveAs("sample_without_password.pdf")
if err != nil {
log.Fatal(err)
}
}