Images-to-PDF icon indicating copy to clipboard operation
Images-to-PDF copied to clipboard

Merging in view files not working with encyption

Open McModknower opened this issue 3 years ago • 8 comments

The merge function in the view files segment can't use encrypted input files.

Steps to reproduce

  1. Create a password protected pdf
  2. got to "View Files"
  3. Select some pdfs including the encrypted one
  4. click on the merge icon
  5. input a valid name an click ok

Expected behaviour

A promt for the password of a pdf appears

Actual behaviour

the snackbar plops up with the message that it couldn't access the PDFs

Would you like to work on the issue?

when no one else takes it and everything else i'm currently working on here is done

McModknower avatar Oct 09 '20 14:10 McModknower

We can check all pdf files for encryption and create a prompt for password only if any PDF is encrypted. We can check if a pdf is encrpyted using Apache PDFBox library - https://pdfbox.apache.org/

Sample Code:

try { document = PDDocument.load( "C:\abc.pdf");

if(document.isEncrypted())
{
  //Then the pdf file is encrypeted.
  // Display a prompt for password of the file.
}

}

Hope it helps !

ganeshbch avatar Oct 09 '20 23:10 ganeshbch

Thank you for providing the code pointers for this library.

But, we also have a encryption utility here which can check if document is encrypted: https://github.com/Swati4star/Images-to-PDF/blob/master/app/src/main/java/swati4star/createpdf/util/PDFEncryptionUtility.java#L127

Swati4star avatar Oct 10 '20 06:10 Swati4star

I would like to work on this issue. I have a doubt regarding the expected behaviour. If we are trying to merge more than 1 password encrypted files then should there be a prompt asking to unlock each and every pdf which is password protected before merging? @Swati4star @McModknower can any of you clarify me this so that I can start the work?

HaripriyaB avatar Oct 11 '20 15:10 HaripriyaB

Yeah @HaripriyaB So, whenever user selects a encrypted file, we can show a promt "This PDF is password protected. Please enter your password to select this" and a edittext to allow user to enter password. Add 2 options to this dialog: "Submit" and "Remove File".

If the password is incorrect, show the above prompt again.

Swati4star avatar Oct 11 '20 15:10 Swati4star

Yeah @HaripriyaB So, whenever user selects a encrypted file, we can show a promt "This PDF is password protected. Please enter your password to select this" and a edittext to allow user to enter password. Add 2 options to this dialog: "Submit" and "Remove File".

If the password is incorrect, show the above prompt again.

Thanks @Swati4star 😊 I'll start working on it and if I need some more clarification I'll reach out to you.

HaripriyaB avatar Oct 11 '20 15:10 HaripriyaB

I have a doubt. When I tried to removePassword(already existing function) of a file it creates a new file which is the decrypted version of that file and the encrypted file still exists. I want to ask if there is any way to decrypt the file while merging in runtime? If not then I'm planning to implement it as follows:

  1. Remove password of the file and add the newly created file to the list of files to be merged
  2. Remove the encrypted file from the list fo files to merge.
  3. After merging, the decrypted files will be deleted from the list of files present. So, After merging there will be one merged file and no other change done to any of the files.

@Swati4star Pls confirm.

HaripriyaB avatar Oct 13 '20 09:10 HaripriyaB

@HaripriyaB your approach sounds good. In the 1st step, i hope we don't show to user that we are doing all this in background

Swati4star avatar Oct 15 '20 14:10 Swati4star

Hii @Swati4star . Wanted to work on this issue and would soon raise a PR with the changes. Could you please assign this issue to me?

shubhamshah14102 avatar Oct 01 '22 05:10 shubhamshah14102