Password dialog/prompt

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Password dialog/prompt

Post 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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Password dialog/prompt

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Password dialog/prompt

Post 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

Code: Select all

CreateDocumentFromFilePath
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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Password dialog/prompt

Post by Sasha - Tracker Dev Team »

Hello Philip,

Try specifying the NoAuth parameter as true.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply