PDF ファイルを復号化

所有者パスワードで PDF を復号化

.NET 経由の Aspose.PDF for Python を使用して、所有者パスワードを使用してパスワードで保護された PDF ドキュメントを復号化します。この操作により暗号化が解除され、ドキュメントへの無制限のアクセスが可能になります。

  1. 「PDFFileSecurity」オブジェクトを作成します。
  2. ‘bind_pdf () ‘メソッドを使用して暗号化された PDF をロードします。
  3. ドキュメントを復号化します。
  4. 復号化された PDF を保存します。
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


# Decrypt PDF with Owner Password
def decrypt_pdf_with_owner_password(infile, outfile):
    """Decrypt a PDF document using the owner password."""
    # Create PdfFileSecurity object
    file_security = pdf_facades.PdfFileSecurity()

    # Bind PDF document
    file_security.bind_pdf(infile)

    # Decrypt the PDF
    file_security.decrypt_file("owner_password")

    # Save decrypted PDF
    file_security.save(outfile)

例外なく PDF を復号化してみてください

PDF 文書は、アクセスや使用を制限するためにパスワードで保護されていることがよくあります。このような文書に完全にアクセスしたり変更したりするには、暗号化を解除する必要がある場合があります。.NET 経由の Aspose.PDF for Python を使用して、所有者パスワードを使用して保護された PDF ドキュメントを復号化し、暗号化とアクセス制限を解除します。

  1. 「PDFFileSecurity」オブジェクトを作成します。
  2. 入力 PDF をバインドします。
  3. PDF を復号化します。
  4. 出力 PDF を保存します。
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


# Try Decrypt PDF Without Exception
def try_decrypt_pdf_without_exception(infile, outfile):
    """Attempt to decrypt a PDF without throwing an exception on failure."""
    # Create PdfFileSecurity object
    file_security = pdf_facades.PdfFileSecurity()

    # Bind PDF document
    file_security.bind_pdf(infile)

    # Attempt to decrypt the PDF
    result = file_security.try_decrypt_file("owner_password")

    # Save only if decryption was successful
    if result:
        file_security.save(outfile)
    else:
        print("Decryption failed. Check password or document security.")