Splitting PDF with script

I have some large PDF’s of invoices I would like to split into smaller files. They need to be split on the beginning of a customer invoice. I have a script for finding the beginning of an invoice in vbscript and I have a script for extracting pages from the PDF based on start and stop page, but it is in javascript. Wondering if anyone could give me the equivalent command from one language to the other so I can get this done with one script.

Here’s what I have for finding the beginning of the invoice
if instr(myPDF.Pages.Item(i).ExtractText2(7.6146, 10.5833, 8.3438, 10.7188)," 1 of") > 0 then

And here’s what I have for extracting the pages to a new pdf.
mypdf.Pages.ExtractTo(splitname,startpage,splitend-1,true);

TIA,

Brian

In Javascript, you use indexOf() to mimic VB’s instr() method:

if(mypdf.Pages.Item(i).ExtractText2(7.6146, 10.5833, 8.3438, 10.7188).indexOf(" 1 of")>=0){
  mypdf.Pages.ExtractTo(splitname,startpage,splitend-1,true);
}

Couple of things to note: JavaScript’s indexOf() is 0-based, so that why we use >=0 in the comparison. Also, JS is case sensitive, so myPDF is not the same as mypdf. Make sure to adapt your scripts accordingly.

Is there a link to documentation of methods that can be used in javascript for pdf’s?

PlanetPress Workflow 2021.2 User Guide - AlambicEdit API reference

I am not seeing what is wrong with this statement

codelineext = mypdf.Pages().Item(splitend).ExtractText2(0, 0, 6.3542, 0.1354);
Watch.Log (codelineext, 3);
codeline = codelineext.trim();

My log shows the following:

[0002] INCTC INV 000198 3 AV 0.426 T1 0011526486 00015239-8 0000000198 Page 1 of 2 110121

when the next line runs to trim I get this error:

[0002] W3602 : Error 0 on line 58, column 9: Microsoft JScript runtime error: Object doesn’t support this property or method

Either you are running an old version of Workflow, or you haven’t set your Script Language to use Enhanced JScript (which supports the trim() method, whereas regular JScript doesn’t).

What version of Workflow do I need to be on? If that’s not the problem, how do I set Script Language for Enhanced JScript?

The feature was introduced in Connect 2019.2.
To set the language to Enhanced JScript, open your script task and select the Enhanced JScript option from the Language menu.