Skip to main content
New Participant
August 6, 2018
Answered

How to check PDF is password protected or not in c# or Javascript or Jquery?

  • August 6, 2018
  • 1 reply
  • 9028 views

I want to do the following in web application developed using .NET(JQUERY, ANGULAR):

1. Check PDF is password protected or not

2. Check PDF is corrupted or not

Please help with sample codes and examples

This topic has been closed for replies.
Correct answer Thom Parker

Are there any methods or properties in AxAcroPDFlib library to check PDF's security like password protected or not?


The AxAcroPDFLib is client side, so you're talking about having something that will run on the browser. In that vein. I do not know if there are any extensions to browser JS for examining a PDF. I doubt it. The Acrobat browser API (AxAcroPDFLib) is weak. It does not contain any objects of function that provide details on security. But the Acrobat JavaScript "doc.Security" object does provides information on PDF security. To use this function you need to run a script inside the  Acrobat/Reader scripting environment. This can be done from the IAC.  I don't know for sure that this can be used from the browser, but if it is possible to write a VBA script for IE, then you can call the JS function through the "JavaScript Object" in the IAC.

You can read about it here: Acrobat DC SDK Documentation

1 reply

Thom Parker
Community Expert
Community Expert
August 6, 2018

You cannot know either of these things without a tool that parses a PDF file, for example, a viewer like Acrobat. However, you could write a relatively simple program to examine the PDF trailer to find out if there is security applied to the PDF.

.Net would work for this because you can open files and get byte level info, but you can't get any of this info from JavaScript. JQuery is just a layer on top of JS so the same applies.

And finally, there is absolutely no way to know if the PDF is corrupted without a tool that fully parses the PDF.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
vinothktAuthor
New Participant
August 6, 2018

Thanks, I would go with C#. Please can you help what do I need to check PDF security in C#. what is recommended PDF trailor and API?

Appreciate if you can share some sample coding.

Thom Parker
Community Expert
Community Expert
August 6, 2018

I think C# will work fine, but I have never written any code for parsing a PDF trailer, so that's something you'll need to do yourself.

To do this you need to read the PDF Specification as it relates to the trailer. In this case you shouldn't need an API. You'll need to write code to parse the trailer.

On the other hand, there are some free PDF libraries, such as Quick PDF from FoxIt. You may be able to get the info you want with one of these, which would be much simpler that parsing it yourself. But again, I haven't done this myself.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often