密碼、安全性與元資料
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()

# 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.SecuritySettings.OwnerPassword = "top-secret"  # password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable"  # password to open the pdf
pdf.SaveAs("secured.pdf")
pip install ironpdf
密碼、安全性與元資料

密碼、安全性與元資料

IronPDF for Python提供對PDF文件安全性和元資料的全面控制,包括作者資訊、關鍵字、密碼和使用者許可限制。

入門指南

載入一個SecuritySettings物件的屬性,然後保存。 元資料和安全性設置將在一次保存操作中一起應用。

元資料屬性

  • MetaData.Author:設置在PDF屬性中可見的文件作者名稱。
  • MetaData.Keywords:設置與文件相關聯的SEO友好的關鍵字。
  • MetaData.ModifiedDate:記錄文件上次修改的時間。 Now()插入當前的時間戳。

安全設定

  • SecuritySettings.RemovePasswordsAndEncryption():在應用新設置之前,清除文件中現有的密碼和加密。
  • SecuritySettings.MakePdfDocumentReadOnly(key):限制文件編輯。 key是一個內部簽名密鑰,而不是面向使用者的密碼。
  • False,使用者無法在PDF查看器中新增註釋。
  • False,防止從PDF中複製文字。
  • False,使用者無法填寫表單欄位。
  • SecuritySettings.AllowUserPrinting:控制列印許可。 PdfPrintSecurity.FullPrintRights允許列印; 使用其他值來限制它。
  • SecuritySettings.OwnerPassword:需要密碼以編輯或更改PDF查看器中的安全設置。
  • SecuritySettings.UserPassword:需要密碼以開啟和閱讀PDF。
學習如何使用IronPDF for Python來保護PDF文件!

準備開始了嗎?

版本:2026.11剛剛發布