Skip to main content
jamesh45843898
Participant
September 5, 2018
Question

Saving PDF as Plain text

  • September 5, 2018
  • 1 reply
  • 2291 views

Hello.  I am attempting to save all PDFs within a folder as text.  To do this i am running an action calling a JavaScript and using this.saveAs

When the script runs attempting to save as Plain text, some PDFs fail as they cannot be tagged.  I am therefore curious if a JS can be implemented such that it attempts to save as plain text, and if that fails save as accessible text.

this.saveAs("**filepath**”+ this.documentFileName + "_accessformat.txt","com.adobe.acrobat.accesstext");

this.saveAs("**filepath**”+ this.documentFileName + "_accessformat.txt","com.adobe.acrobat.plain-text");

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 5, 2018

You can try it like this:

try {

     this.saveAs("**filepath**”+ this.documentFileName + "_accessformat.txt","com.adobe.acrobat.plain-text");

} catch (e) {

     this.saveAs("**filepath**”+ this.documentFileName + "_accessformat.txt","com.adobe.acrobat.accesstext");

}

Joel Geraci
Community Expert
Community Expert
September 5, 2018

You'll probably also want to confirm that there is any text at all by using...

this.getPageNumWords(n) // n is the zero-based page number

... on each page.

Some PDF files are image only.

try67
Community Expert
Community Expert
September 5, 2018

In that case it will just output an empty file. It shouldn't cause an error...