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

Determine whether a PDF file is read only

New Here ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

Hello,

I am creating a diagnostic tool for PDFs and the output from the diagnostic tool is a tab delimited file.  I would like to use Javascript to add a flag for whether or not the document is read only.  By read only, I mean any of the following:

1.  If you go to the location of the PDF file, right click on the icon of the PDF file, click Properties, and then on the General tab in the Attributes section at the bottom, the Read-only checkbox is checked.

2.  The file is open by another user

3.  The file is locked

What has not worked is the solution offered in this post:

Determining if PDF is read only

appRightsValidate({nValidateOption: 1}); 

Any ideas are appreciated.

Thanks,

Chris

TOPICS
Acrobat SDK and JavaScript

Views

2.1K

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 , Apr 16, 2018 Apr 16, 2018

The "Read Only" you are describing is a file system property, not a PDF property. Try67 provided an indirect method for determining this, but it isn't exact. The only way to get direct info on this is from the OS. It cannot be done with JavaScript.

Votes

Translate

Translate
Community Expert ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

The only way I can think of is to edit the file in some way (or just set its dirty property as true) and then try to save it using the saveAs method. If it's set as read-only, or another user has it open, it will throw an exception which you could then catch and handle further.

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 ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

The "Read Only" you are describing is a file system property, not a PDF property. Try67 provided an indirect method for determining this, but it isn't exact. The only way to get direct info on this is from the OS. It cannot be done with JavaScript.

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Hi , I made my file Read-Only by changing its permissions and then edited it and tried saving it using saveAs  as below 

 

 

 try {
    var name = this.documentFileName;
    var destPath = "/tmp/" + name;
  
     this.saveAs({ cPath: destPath});
     
} catch(e) {

app.alert(e); 

}

Without throwing any error file is getting saved  

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

LATEST

Read-only does not prevent the file from being saved elsewhere, only under the same name.

Try this code:

try {
     this.saveAs({ cPath: this.path});     
} catch(e) {
	app.alert(e); 
}

 

It should produce this error message:

 

try67_0-1590506637834.png

 

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