14

私は次のものを持っています:

  • 毎日 PDF ファイルを作成するルーチン X。
  • このファイルを Outlook 電子メールに添付して受信者に送信するルーチン Y。

上記は両方ともVBAです。これらは、C# コンソール アプリケーションから呼び出されます。

PDF が作成されたら、パスワードで保護する必要があります。サード パーティのソフトウェアを購入せずに VBA を介してこれを行うには、かなり複雑です。

C# を使用した最も簡単なソリューションは何ですか?

(支出額と回答の複雑さの間には反比例の関係があると思います!)

4

1 に答える 1

26

PDFSharpは、PDF ファイルをパスワードで保護できる必要があります。

// Open an existing document. Providing an unrequired password is ignored.
PdfDocument document = PdfReader.Open(filename, "some text");

PdfSecuritySettings securitySettings = document.SecuritySettings;

// Setting one of the passwords automatically sets the security level to 
// PdfDocumentSecurityLevel.Encrypted128Bit.
securitySettings.UserPassword  = "user";
securitySettings.OwnerPassword = "owner";

// Don't use 40 bit encryption unless needed for compatibility reasons
//securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted40Bit;

// Restrict some rights.
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotations = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = false;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = false;

// Save the document...
document.Save(filename);

参考:
http ://www.pdfsharp.net/wiki/ProtectDocument-sample.ashx

于 2012-09-12T07:57:46.620 に答える