2016-05-03 99 views
0

私のプログラムでは、私が指定したパスワードでPDFを書き留めます。これは重要なことですが、私が開こうとしているPDFのパスワードを知っている(ハッキングしていないなど)。私はそうパスワードのようにPDFを保護する。このためPDFsharpを使用してパスワードで保護されたPDFを開く

Application.Current.Dispatcher.InvokeAsync(new Action(() => 
{ 
    string sourcePath = sourceFilePath; 
    string targetPath = @"C:\ExamplePath"; 

    useReturnedOHPath = true; 

    string sourceFile = Path.Combine(sourcePath, fileName); 

    var document = PdfReader.Open(sourceFile); 
    var securitySettings = document.SecuritySettings; 
    securitySettings.UserPassword = "ExamplePass"; 

    securitySettings.PermitAccessibilityExtractContent = false; 
    securitySettings.PermitAnnotations = false; 
    securitySettings.PermitAssembleDocument = false; 
    securitySettings.PermitExtractContent = false; 
    securitySettings.PermitFormsFill = true; 
    securitySettings.PermitFullQualityPrint = false; 
    securitySettings.PermitModifyDocument = true; 
    securitySettings.PermitPrint = false; 

    document.Save(sourceFile); 
    MessageBox.Show(sourceFile); 

    string cleanPath = CleanFileName(selectedPerson.ID + " " + DateTime.Now.ToString("dd-MM-yyyy hh-mm-ss") + ".pdf"); 
    ohDestFile = Path.Combine(targetPath, cleanPath); 

    File.Copy(sourceFile, ohDestFile, true); 
}), DispatcherPriority.ContextIdle); 

私はPDFにパスワードがExamplePassであることを知っています。今私のプログラムの中からPDFを開くには、いくつかの方法を試しました。

if (selectedOHRecord.Path != string.Empty) 
{ 
    Process.Start(selectedOHRecord.Path); 
} 

これはAcrobatを開き、パスワードを尋ねるだけです。私はこの何が全く起こらない呼び出すときしかし、PDFsharpのウェブサイト自体から取られ

PdfDocument document = PdfReader.Open(selectedOHRecord.Path, "ExamplePass"); 

:私はまたに追加しようとしました。 PDFを開いてユーザーのパスワードを入力して入力する必要がない方法がありますか?

+0

パスワードの目的は何ですか? –

+0

@PDFsharpTeam PDFファイルが開かれているプログラムの外部で開かないようにしたい、つまりユーザーがWindowsエクスプローラでファイルを開くのを防ぐ。 – CBreeze

+0

PDFsharp APIはAdobeから完全に独立している。 PDFsharpからAdobe Readerにパスワードを渡す方法はありません。また、AFAIKでは、コマンドラインを使用してAdobe Readerにパスワードを渡す方法はありません。 –

答えて

0

PDFファイルにユーザーパスワードがある場合、Adobe Readerはパスワードの入力を求めます。

PdfReader.Openに電話をかけても、パスワードがAdobe Readerに渡されないため、もう一度メッセージが表示されます。

ユーザーパスワードの代わりに所有者パスワードを設定できます。 Adobe Readerでファイルを開くとプロンプトは表示されませんが、編集はできません。

サンプルの保護解除のようにパスワードを削除し、パスワードなしでPDFファイルを一時ファイルに保存し、Adobe Readerで開きます。ユーザーは、保護されていないコピーを保持するために、選択したフォルダにAdobe Readerからファイルを保存できます。
http://www.pdfsharp.net/wiki/UnprotectDocument-sample.ashx

関連する問題