Skip to main content
cjboccio
New Participant
April 16, 2018
Answered

Determine whether a PDF file is read only

  • April 16, 2018
  • 2 replies
  • 3544 views

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

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

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.

2 replies

Thom Parker
Thom ParkerCorrect answer
Community Expert
April 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.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
May 26, 2020

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  

try67
Community Expert
May 26, 2020

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
Community Expert
April 16, 2018

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.