[0002] W3602 : Error 0 on line 10, column 9: AlambicEdit.AlambicEditPDF.1: Error deleting page 0: One or more pages are in use and could not be deleted.
I believe this is a known issue with JavaScript and the AlambicEdit API.
Try this in VBScript:
Dim myPDF : Set myPDF = Watch.GetPDFEditObject
Dim pageType
Dim i
myPDF.Open Watch.GetJobFilename, False
For i = 0 To myPDF.Pages.Count
pageType = Trim(myPDF.Pages(i).ExtractText2(1.125,0.14583,4.10416,0.57291))
Watch.Log i & " " & pageType, 2
If pageType <> "Invoice" Then
myPDF.Pages.Delete i
End If
Next
myPDF.Save True
myPDF.Close
Set myPDF = Nothing
Thank you Jim. I got the same error though in VBScript.
But I managed to understand why. As I delete pages from the PDF, I needed a way to update the total page count in my for loop otherwise I start querying indexes which no longer exist.
Hence I reworked my script by using a do-while loop, giving me the opportunity to update my page count before the next loop index.