Document Library for WinForms
ドキュメントの保護
PdfDocumentSource for WinForms > ドキュメントの保護

PdfDocumentSource allows you to set password for protecting your PDF document. It allows you to create a password protected PDF using the PdfSecurityOptions class from C1.Win.Document.Export namespace. The PdfSecurityOptions class lets you set a password to open the PDF document using the UserPassword property.

Add password via code

Let's say the user wants to generate a password-protected PDF document at the click of a button. For this, you can follow the steps below:

  1. Load the PDF document using the LoadFromFile method of PdfDocumentSource component:

    C#
    コードのコピー
    private void Form1_Load(object sender, EventArgs e)
    {
        c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
    }
    
  2. Create an object of PDFFilter class to access the PDF document using the FileName property and set the password using the PdfSecurityOptions.UserPassword property. Then, export the PDF with password using the Export method.

    C#
    コードのコピー
    private void pwBtn_Click(object sender, EventArgs e)
    {
        //パスワード付きのPDFをエクスポートします。
        var filter = new PdfFilter();
        filter.FileName = @"..\..\Password.pdf";
        filter.PdfSecurityOptions.UserPassword = "pass1234";
        c1PdfDocumentSource1.Export(filter);
    }