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

Looking to run a script in Acrobat DC Pro

Community Beginner ,
Jun 14, 2023 Jun 14, 2023

Hello. Thank you for taking the time to read this. As the title says, I am attempting to run a script in Acrobat which technically runs as it says complete but the process takes about a second to run. For context, I am attempting to set the document properties, OCR, and search for predefined terms, and highlight when those terms are found within the document. Here is what the code looks like. Any information that you may be able to provide would be appreciated. 

// Clear Document Properties
this.info.Author = "";
this.info.Title = "";
this.info.Subject = "";
this.info.Keywords = "";
this.info.Creator = "";
this.info.Producer = "";
this.info.PageLayout = "Default";
this.info.Zoom = "Default";

// Set Initial View to Bookmarks Panel and Page
this.viewerPreferences = {
  pageMode: "bookmarks",
  nonFullScreenPageMode: "bookmarks"
};

// OCR the Document
var nNumPages = this.numPages;
for (var i = 0; i < nNumPages; i++) {
  var oPage = this.getPageNth(i);
  oPage.getText({ nStart: 0, nEnd: -1 });
}

// Highlight the Search Terms
var colHilite = color.yellow;
var aSearchTerms = ["Addendum", "Appendices", "Appendix", "Attachment", "Below", "Cited", "Describe", "Deviation", "Figure", "File", "Footnote", "Graph", "Lab", "Method", "Notebook", "Protocol", "Provide", "Reference", "Report", "Section", "See", "Shown", "Study", "Table"];

for (var i = 0; i < nNumPages; i++) {
  var oPage = this.getPageNth(i);
  for (var j = 0; j < aSearchTerms.length; j++) {
    var sSearchTerm = aSearchTerms[j];
    var aMatches = oPage.getAnnots({ type: "Text", subtype: "Highlight", quadPoints: [[], [], [], []], search: { query: sSearchTerm, matchCase: false, wholeWord: true } });
    if (aMatches != null) {
      for (var k = 0; k < aMatches.length; k++) {
        var oMatch = aMatches[k];
        oMatch.type = "Highlight";
        oMatch.strokeColor = colHilite;
      }
    }
  }
}

// Save the Document with the Same Name
var sFilePath = this.path;
var sFileName = this.documentFileName;
var oSaveAs = new File(sFilePath + "/" + sFileName);
this.saveAs(oSaveAs);

 

TOPICS
JavaScript , PDF
2.0K
Translate
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 ,
Jun 14, 2023 Jun 14, 2023

Hi @nickl14077405 ,

 

Have you checked in the Developer's Console (CRT+J keyboard combination to open it) if the script is throwing any errors?

 

How long is this PDF document in terms of pages? Is it propperly tagged and tab-structured (if applicable)?

 

And how/where are you executing this script from (i.e. Document Level script, as a Mouse-Up Action button, a custom validation script) ?

 

Also, in the saving portion of your script, is it actually saving the document with the desired file name and desired folder (directory path) ?

Translate
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 ,
Jun 14, 2023 Jun 14, 2023
quote

Hi @nickl14077405 ,

 

Have you checked in the Developer's Console (CRT+J keyboard combination to open it) if the script is throwing any errors? 

I get this error message. 

Exception in line 20 of function top_level, script Batch:Exec

TypeError: this.getPageNth is not a function
20:Batch:Exec

 

How long is this PDF document in terms of pages? Is it propperly tagged and tab-structured (if applicable)? 

This particular document is 88 pages but some documents are upwards of 3000. These are Clinical Study Reports that I am publishing.

 

And how/where are you executing this script from (i.e. Document Level script, as a Mouse-Up Action button, a custom validation script) ?

I am using action wizard as I do not know how to run it in the console.

 

Also, in the saving portion of your script, is it actually saving the document with the desired file name and desired folder (directory path) ? Generally yes. I have this set up in another action not using JS but I got curious and wanted to see if it were possible to run this as a script. Thank you for taking the time to reply. 


By @ls_rbls

 

Translate
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 ,
Jun 14, 2023 Jun 14, 2023

I don't know where you got that code from (AI?), but about half of it is made up and will not work in Acrobat.

Translate
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 ,
Jun 14, 2023 Jun 14, 2023

Hello @try67 as I am very new to writing scripts I did get some help from ChatGPT which is probably frowned upon but I didn't know where to start. 

Translate
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 ,
Jun 15, 2023 Jun 15, 2023

Yes, I thought so. ChatGPT is very good in some things, but in the things it's not good, it's very good at faking it and making it appear like it knows what it's talking about, when in fact it doesn't at all...

Translate
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
LEGEND ,
Jun 15, 2023 Jun 15, 2023

Yes, ChatGPT's job is to merge together the info it finds, and sound convincing. Of course, if something is impossible it won't find the info, but it will still have a go, and it still sounds convincing. This has caused people much, much embarrassment and even legal consequences.

Translate
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 ,
Jun 14, 2023 Jun 14, 2023

You can't run OCR with a script.

Translate
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 ,
Jun 15, 2023 Jun 15, 2023
LATEST

Ahh, this makes sense. I appreciate you letting me know. 

Translate
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 ,
Jun 15, 2023 Jun 15, 2023

You should use an Action containing:

1. OCR

2. run a JavaScript

3. Save as


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
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