Skip to main content
jamesh45843898
Participant
Sep 5, 2018 9:32 PM UTC
Question

Saving PDF as Plain text

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

try67
Community Expert
Community Expert
Sep 5, 2018 10:36 PM UTC

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");

}

Translate
Joel Geraci
Community Expert
Community Expert
Sep 5, 2018 11:05 PM UTC

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.

Translate
try67
Community Expert
Community Expert
Sep 5, 2018 11:39 PM UTC

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

Translate