In my program I write away PDFs with a password I specify. This is important as I know the password to the PDFs I'm trying to open (not hacking it or anything). I password protect the PDF like so;
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);
Because of this I know that the password to the PDF is ExamplePass
. Now when I come to open the PDF from within my program I have tried a few methods, simply;
if (selectedOHRecord.Path != string.Empty)
{
Process.Start(selectedOHRecord.Path);
}
However understandably this just opens Acrobat and asks for a password. I've also tried adding in:
PdfDocument document = PdfReader.Open(selectedOHRecord.Path, "ExamplePass");
Which is taken from the PDFsharp website itself, however when I call this nothing happens at all. Is there a way I can open a PDF and input the password for the user so they don't have to type it?