I have a form that asks the user to upload a PDF, but if it's a password protected PDF the uploader says there is no file in the form.
(The IIS logs say: Document_can_not_be_decrypted.)
I am already using DynamicPDF to check the page number, is there a way that I can also check to see if the PDF is password protected, at the same time?
test if pdf is encrypted
Re: test if pdf is encrypted
Support · Jan 16, 2017Hello,
Yes, you are getting error because of loading the secured/encrypted PDF without providing the correct owner password.
You can check whether the PDF is secured or not using SecurityInfo property of PdfDocument class. You will need to load the input PDF using PdfDocument class and then use this property to get the security information. You can refer to the documentation on PdfDocument class here
and documentation on SecurityInfo property here
.
Thanks,
ceTe Software Support Team.
Re: test if pdf is encrypted
Forum member · Jan 17, 2017I am confused, how do you check the security if you cannot load the PDF?
The new error when using DynamicPDF.PdfDocument trying to LoadPDF, "Please_pass_a_proper_file_path_or_Byte_Array_or_if_encrypted_pass_proper_Password"
using the documentation example
Dim Pdf
Set Pdf = Server.CreateObject( "DynamicPdf.PdfDocument" )
Pdf.LoadPdf c:\temp\somepdf.pdf"
but that LoadPdf is where it fails, so I can not check the "DPDF_SecurityInfo", unless I am just not understanding something.
Re: test if pdf is encrypted
Support · Jan 17, 2017Hello,
Sorry for the confusion. The solution we provided earlier to check for security is for protected/encrypted PDFs that do not require an owner password (there are PDFs out there that are encrypted without an owner password).
In your case the protected PDFs have an actual password, and you are right in that without the password you won’t be able to call the LoadPdf without getting an exception. The only solution for this case is to use the On Error Resume Next statement in ASP to catch and handle the error appropriately.
Dim MyDocument
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
On Error Resume Next
Dim MyPdfDocument
Set MyPdfDocument = Server.CreateObject( "DynamicPDF.PdfDocument" )
MyPdfDocument.LoadPdf Server.MapPath( "./Encrypt.pdf")
If Err.Number <> 0 Then
'catch and handle the error appropriately
Response.Write "Error occurred loading pdf: " & Err.Description
Response.End
End If
MyDocument.AppendPdf MyPdfDocument
MyDocument.DrawToWeb
Set MyDocument = Nothing
Thanks,
ceTe Software Support Team.