Page 1 of 1
Password dialog/prompt
Posted: Tue Sep 12, 2017 2:07 pm
by pHol
Hi!
I have looked in to previous posts about how to check if a document has a password (with authcallback) and I have followed that to be able to have my own password dialog shown. But I am having issues if I input the wrong password. Then I still get the built in version of the password dialog. I cannot see any event being fired before this is shown, not even the e.operBeforeExecute event is triggered before this dialog is shown. How do I catch the input password dialog/prompt or is this not possible?
Cheers,
Philip
Re: Password dialog/prompt
Posted: Tue Sep 12, 2017 2:52 pm
by Sasha - Tracker Dev Team
Hello Philip,
Please specify a code sample on a method that you are using to open a document.
Cheers,
Alex
Re: Password dialog/prompt
Posted: Wed Sep 13, 2017 9:50 am
by pHol
Hi Alex!
Here is some fake code that will show you kind of what it is I am trying to do. My issue is that when I input the wrong password into my own password dialog, the original dialog is opened at the line "Op.Do();". I have tried to put a try-catch surrounding this line to have an event call that the password was wrong but this did not work. Is there a way to intercept the message that the password was wrong before the original dialog is shown or am I doing something wrong with the AuthCallback? (I had written a better explanation to my problem, but I was a way from my computer for a while and got logged out of the forum and all that I had written was gone. Hope this will explain it enough)
The method
is copied from
https://sdkhelp.pdf-xchange.com/view/PXV:op_openDoc with the addition of adding password if there is one inputted.
Code: Select all
public class AuthCallback : IPXC_DocAuthCallback
{
private uint code = 0;
public bool HasPassword => code != 0;
public void AuthDoc(IPXC_Document pDoc, uint nFlags) => code = pDoc.GetSecurityHandlerType(false);
}
public class Program
{
private AxPXV_Control _pdfControl;
private void /* event from password dialog to get inputted password */ (object sender, PasswordEnteredEventArgs e)
{
OpenDocument(e.FilePath, e.Password);
}
private bool IsPasswordProtected(string filePath)
{
AuthCallback callback = new AuthCallback();
PDFXEdit.IPXC_Inst pxcInst = (PDFXEdit.IPXC_Inst)Inst.GetExtension("PXC");
pxcInst.OpenDocumentFromFile(filePath, callback);
return callback.HasPassword;
}
private void CheckForPasswordAndOpenDocument(string filePath)
{
if (IsPasswordProtected(filePath))
{
// show own password dialog
}
else
{
OpenDocument(filePath, "");
}
}
private void OpenDocument(string filePath, string password)
{
_pdfControl.OpenDocFrom(CreateDocumentFromFilePath(filePath, password));
}
private IPXC_Document CreateDocumentFromFilePath(string filePath, string password = "")
{
int nID = Inst.Str2ID("op.openDoc", false);
PDFXEdit.IOperation Op = Inst.CreateOp(nID);
PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
PDFXEdit.IAFS_Name name = fsInst.DefaultFileSys.StringToName(filePath);
var input = Op.Params.Root["Input"];
input.v = name;
PDFXEdit.ICabNode options = Op.Params.Root["Options"];
options["NativeOnly"].v = true;
if (!string.IsNullOrEmpty(password)) options["Password"].String = password;
Op.Do();
PDFXEdit.IPXC_Document doc = (PDFXEdit.IPXC_Document)Op.Params.Root["Output"].v;
return doc;
}
}
Sincerely,
Philip
Re: Password dialog/prompt
Posted: Wed Sep 13, 2017 2:04 pm
by Sasha - Tracker Dev Team
Hello Philip,
Try specifying the NoAuth parameter as true.
Cheers,
Alex