PDF 암호화 및 복호화
from ironpdf import *

# Open an Encrypted File, alternatively create a new PDF from Html
pdf = PdfDocument.FromFile("encrypted.pdf", "password")
 
# Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = Now()
 
# Edit file security settings
# The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
 
# Change or set the document encryption password
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")
pip install ironpdf
PDF 암호화 및 복호화

PDF 암호화 및 복호화

IronPDF for Python은 암호로 보호된 PDF 파일을 열고, 그 메타데이터와 보안 설정을 수정하며, 새로운 비밀번호로 다시 저장할 수 있습니다 - 몇 줄의 코드로 전체 암호화 및 해독 작업 흐름을 가능하게 합니다.

시작하기

PdfDocument.FromFile에 파일 경로와 기존 비밀번호를 전달하여 암호화된 PDF를 엽니다. 필요에 따라 보안 설정과 메타데이터를 수정한 후 pdf.Password에 새 비밀번호를 할당하고 SaveAs로 저장합니다.

코드 이해하기

  • PdfDocument.FromFile(path, password): 제공된 비밀번호를 사용하여 암호화된 PDF 파일을 열어 해독합니다. 암호가 올바르지 않을 경우 예외를 발생시킵니다.
  • MetaData.Author / Keywords / ModifiedDate: 해독 후 읽거나 업데이트할 수 있는 메타데이터 필드입니다.
  • SecuritySettings.RemovePasswordsAndEncryption(): 메모리 내 문서에서 현재 암호화를 제거하여 보안 설정을 다시 구성할 수 있게 합니다.
  • SecuritySettings.MakePdfDocumentReadOnly(key): 새로운 내부 키로 읽기 전용 보호를 다시 적용합니다.
  • SecuritySettings.AllowUser*: 세밀한 사용자 권한 플래그 - 특정 작업을 제한하기 위해 False로 설정합니다.
  • pdf.Password = "my-password": 저장된 PDF를 열기 위해 필요한 새로운 비밀번호를 설정합니다.
  • SaveAs("secured.pdf"): 모든 새로운 설정이 적용된 재암호화된 문서를 저장합니다.

재암호화 없는 복호화

암호로 보호된 PDF의 암호 없는 사본을 생성하려면 RemovePasswordsAndEncryption()을 호출하고 새로운 Password를 설정하지 않고 저장합니다.

IronPDF for Python으로 PDF 문서를 안전하게 관리하는 방법을 알아보세요!

시작할 준비 되셨나요?

버전:2026.11방금 출시