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

Saving PDF as Plain text

New Here ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

934

Likes

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 ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

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

}

Likes

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 ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

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.

Likes

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 ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

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

Likes

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 ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

I'd call an unnecessary empty file an error. If you saw a 0k text file in the output, wouldn't you go find the input PDF and check it out for yourself?

Likes

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 ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

LATEST

Not really. An empty text file is not a corrupt file (like an empty PDF). I

will just assume the PDF has no text.

In fact, it's better than no file at all, because I at least would know

that the file was processed...

Likes

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