简体   繁体   中英

How to open password protected PDF using MuPDF

I want to open password protected PDF files using MuPDF but I don't know if MuPDF provides any convenient method to do so. I am showing the simple PDFs as following and it is working fine:

File file = [PATH TO THE FILE];

if (file.exists()) {
    Intent intent = new Intent(MainActivity.this, MuPDFActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.fromFile(file));
    startActivity(intent);
} 

I have tried to search for it on Google but I could not find any information about it.

I did this by customizing the MuPDFActivity.java class.

While reading the code in onCreate method i came to know that it is has condition which checks that whether it needs password or not as:

if (core != null && core.needsPassword()) {

and then it shows dialog withe EditText to input the password. Then password is verified via the function.

core.authenticatePassword(mPassword)

I sent the password of the file as String extra to MuPDFActivity class and remove passed it directly to the function.

if (core != null && core.needsPassword()) {
   if (core.authenticatePassword(mPassword)) {
      createUI(savedInstanceState);
   } else {
      requestPassword(savedInstanceState);
   }
   return;
}

You can ask me for complete code if anyone will need help.

Thanks.

要使用 mupdf 打开受密码保护的 pdf,您需要通过终端提供密码,如下所示:

mudpf -p DOCUMENT_PASSWORD filename.pdf   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM