在我的程序中,我用指定的密码写下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并要求输入密码。我也尝试加入:
PdfDocument document = PdfReader.Open(selectedOHRecord.Path, "ExamplePass");
这是从PDFsharp网站本身,但是当我打电话时什么都没有发生。有没有办法打开PDF并为用户输入密码,以便他们不必输入密码?
密码的用途是什么? –
@PDFsharpTeam我们希望防止PDF文件在打开的程序之外打开,即防止用户在Windows资源管理器中打开文件 – CBreeze
PDFsharp API完全独立于Adobe。无法将密码从PDFsharp传递到Adobe Reader。而且AFAIK无法使用命令行将密码传递给Adobe Reader。 –