ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Encrypted PDF-files
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jenswahl

Germany
71 Posts

Posted - Dec 29 2022 :  05:39:16  Show Profile  Reply
Hello,

is there any way to check if a PDF file needs a password or not? Unfortunately I was not been able to find anything in the help and demos.
We can pass the password in LoadFromFilePDF. But I would like to have the possibility to query the password before (input by the user).

Kind Regards,

Jens



www.inntalsoftware.de/en/

xequte

38176 Posts

Posted - Jan 03 2023 :  21:57:05  Show Profile  Reply
Hi Jens

You can use:

// Determine if a file is password protected
function PdfFileIsPasswordProtected(const Filename: string): Boolean;
var
  iev: TImageEnView;
begin
  Result := False;
  try
    iev := TImageEnView.Create(nil);
    try
      iev.PdfViewer.Enabled := True;
      iev.IO.LoadFromFilePDF( Filename, -1, -1, '' );
    finally
      iev.Free;
    end;
  except
    on e: Exception do
      if e.Message = RsPdfErrorPassword then  // Defined in iexPdfiumCore = 'Invalid password'
        Result := True;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jenswahl

Germany
71 Posts

Posted - Jan 04 2023 :  01:42:35  Show Profile  Reply
Thank you Nigel for the code. I will try it.

Kind Regards,

Jens

www.inntalsoftware.de/en/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: