Seeking Scripting Guidance

aschectman
aschectman Posts: 4
edited February 11 in Peer Support

Follow up to this post. Now with a specific example/goal.

I need to count/tally instances of all variations of a certain string (regex: W\d{2}X\d{2}). Requesting help with this from an LLM (per reply/suggestion to previous post) yields JS that appears valid but raises errors.

// Bluebeam Revu eXtreme Script
function searchRegexInDocument() {
  var regexPattern = "W\\d{2}X\\d{2}";
  var doc = PDFNet.PDFDoc.createFromURL(this.document.filepath);
  doc.initSecurityHandler();
  var txtSearch = new PDFNet.TextSearch();
  txtSearch.begin(doc, regexPattern, PDFNet.TextSearch.Mode.e_reg_expression);
  var result;
  var matchCount = 0;
  
  while ((result = txtSearch.run()) !== PDFNet.TextSearch.ResultCode.e_done) {
    if (result === PDFNet.TextSearch.ResultCode.e_found) {
    matchCount++;
    }    } 
  
  console.log("Total matches found: ", matchCount);}

// Example usagesearchRegexInDocument();

Asking the LLM why this raises errors yields basic troubleshooting:

  1. Initialization: Make sure the PDFNet library is properly initialized before running the script. This typically involves calling PDFNet.initialize() with your license key.
  2. Script Environment: Bluebeam Revu eXtreme might have specific requirements for running scripts. Ensure that the script is executed in the correct environment and that all necessary permissions are granted.

PDFNet.initialize() is not a recognized method, as I suspect most others in the code aren't either. No issues with permissions have been encountered or indicated, nor do there appear to be ways of altering such parameters within Revu.

How might I go about assessing and fixing this code? Bluebeam's scripting manual is more of a reference document for supported methods so not the best guide. Currently referencing the Adobe Acrobat JS API and attempting different methods but any help or guidance would be appreciated in the meantime.

Tagged:

Best Answer

  • Peter Noyes
    Peter Noyes Posts: 54
    Answer ✓

    The above code is code meant to run against the library PDFTron. It isn't meant to run against the JavaScript supported by Revu or Adobe.

    Unfortunately, today Revu doesn't expose functionality to programmatically access the text of a PDF document, but it could be possible in a future update. Improving JavaScript is an area of active interest for us.

Answers