私のプログラムでは、私が指定したパスワードで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を開いてユーザーのパスワードを入力して入力する必要がない方法がありますか?
パスワードの目的は何ですか? –
@PDFsharpTeam PDFファイルが開かれているプログラムの外部で開かないようにしたい、つまりユーザーがWindowsエクスプローラでファイルを開くのを防ぐ。 – CBreeze
PDFsharp APIはAdobeから完全に独立している。 PDFsharpからAdobe Readerにパスワードを渡す方法はありません。また、AFAIKでは、コマンドラインを使用してAdobe Readerにパスワードを渡す方法はありません。 –