Seeking Scripting Guidance

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:
- Initialization: Make sure the PDFNet library is properly initialized before running the script. This typically involves calling
PDFNet.initialize()
with your license key. - 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.
Best 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.
2
Answers
-
Close example from the Adobe Acrobat forum:
Solved: JavaScript search or find or get a number or numbe... - Adobe Community - 13404546
Only throws one syntax error:
SyntaxError: Unexpected token '}'
at Script [72] [temp]:1:2 -> }Indicates it stops at the end of a loop, as no methods are called out as not found.
0
Categories
- All Categories
- Certifications Overview ↗
- Bluebeam Certified Professional (BCP) ↗
- BCP User Group
- BCI User Group
- Welcome Guide
- Join the Discussion
- 3.7K Discussion Topics
- 440 Peer Support
- 704 Product Ideas & Feedback
- 2.5K Community Hub
- 12 What's New?
- Release Notes Website ↗
- Built Blog ↗
- Product Support
- 69 Bluebeam User Groups
- User Groups by Location
- United States
- Canada
- Europe
- Asia Pacific
- User Groups by Interest
- Architecture & Design
- Construction
- Engineering
- Subcontractors & Trades
- User Groups by Specialty Role
- Academic Educators
- Bluebeam Certified Instructors (BCIs)
- Bluebeam Certified Professionals (BCPs)
- Construction Owners & Owner Representatives
- Fresno State Student BUG (Fresno BUG)
- Global Bluebeam User Group Champions
- Government
- Product Ideas & Feedback