Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
次のコードスニペットは、Aspose.PDF.Drawingライブラリでも機能します。
PDFファイルに権限を設定するには、DocumentPrivilegeクラスのオブジェクトを作成し、文書に適用したい権利を指定します。権限が定義されたら、このオブジェクトをDocumentオブジェクトのEncryptメソッドに引数として渡します。次のコードスニペットは、PDFファイルの権限を設定する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetPrivilegesOnExistingPdfFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate Document Privileges object
// Apply restrictions on all privileges
var documentPrivilege = Aspose.Pdf.Facades.DocumentPrivilege.ForbidAll;
// Only allow screen reading
documentPrivilege.AllowScreenReaders = true;
// Encrypt the file with User and Owner password
// Need to set the password, so that once the user views the file with user password
// Only screen reading option is enabled
document.Encrypt("user", "owner", documentPrivilege, Aspose.Pdf.CryptoAlgorithm.AESx128, false);
// Save PDF document
document.Save(dataDir + "SetPrivileges_out.pdf");
}
}
DocumentオブジェクトのEncryptメソッドを使用してPDFファイルを暗号化できます。ユーザーパスワード、オーナーパスワード、および権限をEncryptメソッドに渡すことができます。さらに、CryptoAlgorithm列挙体の任意の値を渡すことができます。この列挙体は、暗号化アルゴリズムとキーサイズのさまざまな組み合わせを提供します。選択した値を渡すことができます。最後に、DocumentオブジェクトのSaveメソッドを使用して暗号化されたPDFファイルを保存します。
PDFファイルを暗号化する際には、異なるユーザーおよびオーナーパスワードを指定してください。
次のコードスニペットは、PDFファイルを暗号化する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void EncryptPdfFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "Encrypt.pdf"))
{
// Encrypt PDF
document.Encrypt("user", "owner", 0, Aspose.Pdf.CryptoAlgorithm.RC4x128);
// Save PDF document
document.Save(dataDir + "Encrypt_out.pdf");
}
}
ユーザーは、文書への不正アクセスを防ぐために暗号化されたPDFファイルを交換することが増えています。たとえば、印刷、コピー、共有、PDFファイルの内容に関する情報の抽出などです。今日、PDFファイルを暗号化する最良の選択肢は、コンテンツの機密性と整合性を維持することです。この点において、暗号化されたPDFファイルにアクセスする必要があります。このアクセスは、認可されたユーザーのみが取得できます。また、人々はインターネット上でPDFファイルを復号化するさまざまなソリューションを探しています。
この問題は、Aspose.PDFライブラリを使用して一度で解決するのが最善です。
PDFファイルを復号化するには、まずDocumentオブジェクトを作成し、オーナーパスワードを使用してPDFを開く必要があります。その後、DocumentオブジェクトのDecryptメソッドを呼び出す必要があります。最後に、DocumentオブジェクトのSaveメソッドを使用して更新されたPDFファイルを保存します。次のコードスニペットは、PDFファイルを復号化する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DecryptPdfFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open PDF document with password
using (var document = new Aspose.Pdf.Document(dataDir + "Decrypt.pdf", "password"))
{
// Decrypt PDF
document.Decrypt();
// Save PDF document
document.Save(dataDir + "Decrypt_out.pdf");
}
}
PDFファイルのパスワードを変更するには、まずDocumentオブジェクトを使用してオーナーパスワードでPDFファイルを開く必要があります。その後、DocumentオブジェクトのChangePasswordsメソッドを呼び出す必要があります。このメソッドには、現在のオーナーパスワードと新しいユーザーパスワード、新しいオーナーパスワードを渡す必要があります。最後に、DocumentオブジェクトのSaveメソッドを使用して更新されたPDFファイルを保存します。
- ユーザーパスワードが設定されている場合、PDFを開くために必要です。Acrobat/Readerはユーザーにユーザーパスワードの入力を促します。正しくない場合、文書は開きません。
- オーナーパスワードが設定されている場合、印刷、編集、抽出、コメントなどの権限を制御します。Acrobat/Readerは、権限設定に基づいてこれらの操作を禁止します。権限を設定/変更する場合、このパスワードが必要です。
次のコードスニペットは、PDFファイルのパスワードを変更する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ChangePassword()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open PDF document with password
using (var document = new Aspose.Pdf.Document(dataDir + "ChangePassword.pdf", "owner"))
{
// Change password
document.ChangePasswords("owner", "newuser", "newowner");
// Save PDF document
document.Save(dataDir + "ChangePassword_out.pdf");
}
}
Aspose.PDF for .NETは、PDF文書を扱うための優れた機能を提供します。Aspose.PDF名前空間のDocumentクラスを使用してパスワード保護されたPDF文書を開く場合、パスワード情報をDocumentコンストラクタに引数として提供する必要があります。この情報が提供されない場合、エラーメッセージが生成されます。実際、DocumentオブジェクトでPDFファイルを開こうとすると、コンストラクタはPDFファイルの内容を読み取ろうとし、正しいパスワードが提供されない場合、エラーメッセージが生成されます(これは文書への不正アクセスを防ぐために行われます)。
暗号化されたPDFファイルを扱う際には、PDFにオープンパスワードおよび/または編集パスワードがあるかどうかを検出したいシナリオに遭遇することがあります。時には、開く際にパスワード情報を必要としない文書もありますが、ファイルの内容を編集するためには情報が必要です。したがって、上記の要件を満たすために、Aspose.PDF.FacadesのPdfFileInfoクラスは、必要な情報を判断するのに役立つプロパティを提供します。
PdfFileInfoには、PDF文書のセキュリティに関する情報を取得するための3つのプロパティがあります。
時には、パスワードの配列から正しいパスワードを判断し、正しいパスワードで文書を開く必要があります。次のコードスニペットは、パスワードの配列を反復処理し、正しいパスワードで文書を開く手順を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DetermineCorrectPasswordFromArray()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var info = new Aspose.Pdf.Facades.PdfFileInfo())
{
// Bind PDF document
info.BindPdf(dataDir + "IsPasswordProtected.pdf");
// Determine if the source PDF is encrypted
Console.WriteLine("File is password protected " + info.IsEncrypted);
String[] passwords = new String[5] { "test", "test1", "test2", "test3", "sample" };
for (int passwordcount = 0; passwordcount < passwords.Length; passwordcount++)
{
try
{
using (var document = new Aspose.Pdf.Document(dataDir + "IsPasswordProtected.pdf", passwords[passwordcount]))
{
if (document.Pages.Count > 0)
{
Console.WriteLine("Number of Page in document are = " + document.Pages.Count);
}
}
}
catch (Aspose.Pdf.InvalidPasswordException)
{
Console.WriteLine("Password = " + passwords[passwordcount] + " is not correct");
}
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.