• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

6.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 07, 2018 Aug 07, 2018

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 sc

...

Votes

Translate

Translate
Community Expert ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

LATEST

Another thought.  There is a bridge between Acrobat JavaScript and Browser JavaScript for a PDF displayed in Acrobat/Reader on the browser. This bridge only works if there is supporting JS in the PDF. So if your documents are under your control you could use this bridge to get the security info.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines