PDFにパスワードと権限を設定する方法
パスワード保護は、無許可のアクセスを制限するためにドキュメントを暗号化することを含みます。 それには通常、2種類のパスワードが含まれます: ユーザーパスワード(またはパスワードを開く)ドキュメントを開くために必要なユーザーパスワードおよびオーナーパスワード(または権限のパスワード)編集、印刷、およびその他のアクションの権限を制御します。
IronPDFは、既存および新規のPDFファイルに必要なパスワードと権限のすべてをサポートします。 詳細なメタデータとセキュリティ設定を適用することができ、これにはPDFドキュメントを印刷不可、読み取り専用、暗号化に制限する機能が含まれます; 128ビットの暗号化、復号化、パスワード保護はすべてサポートされています。
IronPDFを始めましょう
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
C#でパスワードおよび権限を使用してPDFを保護する方法

- パスワードでPDFを保護するためのC#ライブラリをダウンロード
- 設定 オーナーパスワード PDFファイルの編集を防止するプロパティ
- 設定 ユーザーパスワード PDFファイルが開かれるのを防ぐプロパティ
- PDFファイルを128ビット暗号化で暗号化
- パスワードを提供してください
ファイルから
PDFドキュメントを開くメソッド
PDFにパスワードを設定する
当社にはPDFファイルの例IronPDFを使用して保護したい内容。 以下のコードを実行して、PDFにパスワードを追加しましょう。 この例では、パスワード password123 を使用します。
:path=/static-assets/pdf/content-code-examples/how-to/pdf-permissions-passwords-add-password.cs
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World");
// Password to edit the pdf
pdf.SecuritySettings.OwnerPassword = "123password";
// Password to open the pdf
pdf.SecuritySettings.UserPassword = "password123";
pdf.SaveAs("protected.pdf");
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World")
' Password to edit the pdf
pdf.SecuritySettings.OwnerPassword = "123password"
' Password to open the pdf
pdf.SecuritySettings.UserPassword = "password123"
pdf.SaveAs("protected.pdf")
結果として得られるPDFは次の通りです。password123 というパスワードを入力して閲覧できます。
パスワードで保護されたPDFを開く
このセクションでは、パスワードが設定されているPDFを開く方法について説明します。 PdfDocument.FromFile
メソッドには、2つ目のオプション引数としてパスワードがあります。 このパラメータに正しいパスワードを入力してPDFを開いてください。
:path=/static-assets/pdf/content-code-examples/how-to/pdf-permissions-passwords-open-password.cs
using IronPdf;
var pdf = PdfDocument.FromFile("protected.pdf", "password123");
//... perform PDF-tasks
pdf.SaveAs("protected_2.pdf"); // Saved as another file
Imports IronPdf
Private pdf = PdfDocument.FromFile("protected.pdf", "password123")
'... perform PDF-tasks
pdf.SaveAs("protected_2.pdf") ' Saved as another file
高度なセキュリティと権限設定
PdfDocument オブジェクトには、Author や ModifiedDate など、設定可能な MetaData フィールドもあります。 以下のように、ユーザー注釈、ユーザー印刷、およびその他多くの機能を無効にすることもできます:
:path=/static-assets/pdf/content-code-examples/how-to/pdf-permissions-passwords-advanced.cs
using IronPdf;
// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("protected.pdf", "password123");
// 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 = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save the secure PDF
pdf.SaveAs("secured.pdf");
Imports IronPdf
' Open an Encrypted File, alternatively create a new PDF from HTML
Private pdf = PdfDocument.FromFile("protected.pdf", "password123")
' 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 = IronPdf.Security.PdfPrintSecurity.FullPrintRights
' Save the secure PDF
pdf.SaveAs("secured.pdf")
権限設定はドキュメントパスワードに関連しており、以下のように動作します。 例えば、AllowUserCopyPasteContent プロパティを false に設定することは、コンテンツのコピー/貼り付けを防ぐことを意図しています:
- パスワードが設定されていません: パスワードがない場合、コンテンツのコピー/ペーストは引き続きブロックされます。
- ユーザーのパスワード設定: ユーザーのパスワードが設定されている場合、正しいパスワードを入力することでコンテンツのコピー/ペーストが可能になります。
- オーナーパスワードの設定: オーナーパスワードが設定されている場合、ユーザーパスワードを入力するだけではコピー/ペースト機能を解除できません。 ただし、所有者パスワードを正しく入力すると、コンテンツのコピー/貼り付けが可能になります。
関連する記事では、事前定義されたメタデータとカスタムメタデータについて詳しく議論しています。 このリンクをフォローして詳細をご覧ください:PDFメタデータを設定および編集する方法."