@@ -144,6 +144,12 @@ Public Sub DevMenu_Show(Optional pXFolder As CscXFolder=Nothing, Optional pXDoc
144
144
145
145
If Not IsDesignMode() Then Exit Sub
146
146
147
+ ' Keep an exported copy of the project script updated.
148
+ ' Called via eval and ignoring errors so this will work if it is in the project, and no error if it is not.
149
+ On Error Resume Next
150
+ Eval( "Dev_ExportScriptAndLocators()" )
151
+ On Error GoTo 0
152
+
147
153
Debug.Clear
148
154
Dim Choices( 1000 ) As String , Choice As Integer , Items As Dictionary
149
155
Set Items=DevMenu_Items()
@@ -222,8 +228,14 @@ Public Sub DevMenu_Execute(sf As ScriptFunction, Optional pXFolder As CscXFolder
222
228
Set Param1=pXFolder
223
229
Else
224
230
If Not pXDoc Is Nothing Then
225
- Debug.Print( "Executing function using parent folder of xdoc." )
226
- Set Param1=pXDoc.ParentFolder 'This might not be valid for a function that tries to modify the folder
231
+ Debug.Print( "Executing function using parent folder of xdoc (overriding single-document mode and folder access permissions)." )
232
+ ' Normally if you go to the parent folder from a doc level event, then back down through the xdocinfos to the xdocs,
233
+ ' that would result in an error saying that it is not currently possible to access documents.
234
+ ' Disabling single doc mode will allow access to the xdocs
235
+ ' These commands are unsupported and have high potential to cause problems: They should never be touched at runtime.
236
+ pXDoc.ParentFolder.SetSingleDocumentMode( False )
237
+ pXDoc.ParentFolder.SetFolderAccessPermission( 255 )
238
+ Set Param1=pXDoc.ParentFolder
227
239
End If
228
240
End If
229
241
End Select
@@ -284,61 +296,65 @@ End Function
284
296
285
297
' Functions to test from DevMenu
286
298
287
- Public Sub ExportPagesAsTiffs(pXDoc As CscXDocument )
288
- Dim fso As New FileSystemObject
289
- Dim ExportPath As String
290
- ExportPath=Project.ScriptVariables( "ExportPath" )
291
-
292
- If Not fso.FolderExists(ExportPath) Then ExportPath=fso.BuildPath(fso.GetFile(Project.FileName).ParentFolder, "ExportedImages" )
293
- If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
299
+ Public Sub FolderAsTiffs(pXFolder As CscXFolder )
300
+ Dim DocIndex As Integer
301
+ For DocIndex= 0 To pXFolder.GetTotalDocumentCount()- 1
302
+ Debug.Print( "Executing on document " & DocIndex+ 1 & "/" & pXFolder.DocInfos.Count() )
303
+ ExportDocAsMultipageTiffs(pXFolder.DocInfos(DocIndex).XDocument)
304
+ Next
305
+ End Sub
294
306
295
- ' Create a folder for this document named by the filename of the first source file
296
- Dim DocName As String
297
- DocName=fso.GetBaseName(pXDoc.CDoc.SourceFiles( 0 ).FileName)
298
- ExportPath=fso.BuildPath(ExportPath,DocName)
299
- If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
307
+ Public Sub ExportDocAsIndividualTiffs(pXDoc As CscXDocument)
308
+ ExportDocAsTiff(pXDoc, GetExportPath(), False )
309
+ End Sub
300
310
301
- Debug.Print( "Exporting " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
302
- Dim PageIndex As Integer
303
- For PageIndex= 0 To pXDoc.CDoc.Pages.Count- 1
304
- If (PageIndex+ 1 ) Mod 10 = 0 Then Debug.Print( " Processing page " & PageIndex + 1 & "/" & pXDoc.CDoc.Pages.Count & " from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
305
- pXDoc.CDoc.Pages(PageIndex).GetImage().Save(fso.BuildPath(ExportPath,DocName & "-Page-" & Format(PageIndex+ 1 , "000" ) & ".tif" ),CscImgFileFormatTIFFOJPG)
306
- pXDoc.CDoc.Pages(PageIndex).UnloadImage()
307
- Next
308
- Debug.Print( "Finished " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
311
+ Public Sub ExportDocAsMultipageTiffs(pXDoc As CscXDocument)
312
+ ExportDocAsTiff(pXDoc, GetExportPath(), True )
309
313
End Sub
310
314
311
- Public Sub ExportPagesAsMultipageTiff(pXDoc As CscXDocument)
312
- ' Saves a doc as a multipage tiff
315
+ Public Function GetExportPath() As String
313
316
Dim fso As New FileSystemObject
314
317
Dim ExportPath As String
315
318
ExportPath=Project.ScriptVariables( "ExportPath" )
316
319
317
320
If Not fso.FolderExists(ExportPath) Then ExportPath=fso.BuildPath(fso.GetFile(Project.FileName).ParentFolder, "ExportedImages" )
318
321
If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
322
+ Return ExportPath
323
+ End Function
319
324
320
- ' Multipage document named by the filename of the first source file
325
+ Public Sub ExportDocAsTiff(pXDoc As CscXDocument, ExportPath As String , Optional MultiPage As Boolean = True )
326
+ Dim fso As New FileSystemObject
321
327
Dim DocName As String , TempPath As String , TiffPath As String
322
328
DocName=fso.GetBaseName(pXDoc.CDoc.SourceFiles( 0 ).FileName)
323
- TiffPath=fso.BuildPath(ExportPath,DocName & ".tif" )
324
- TempPath=TiffPath & ".tmp"
329
+ If MultiPage Then
330
+ ' Multipage document named by the filename of the first source file
331
+ TiffPath=fso.BuildPath(ExportPath,DocName & ".tif" )
332
+ TempPath=TiffPath & ".tmp"
333
+ Else
334
+ ' Create a folder for this document named by the filename of the first source file
335
+ ExportPath=fso.BuildPath(ExportPath,DocName)
336
+ If Not fso.FolderExists(ExportPath) Then fso.CreateFolder(ExportPath)
337
+ End If
338
+
325
339
326
340
Debug.Print( "Exporting " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
327
341
Dim PageIndex As Integer , img As CscImage, imgformat As CscImageFileFormat
328
342
For PageIndex= 0 To pXDoc.CDoc.Pages.Count- 1
329
343
If (PageIndex+ 1 ) Mod 10 = 0 Then Debug.Print( " Processing page " & PageIndex + 1 & "/" & pXDoc.CDoc.Pages.Count & " from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
330
- Set img=pXDoc.CDoc.Pages(PageIndex).GetImage()
331
- imgformat=IIf(img.BitsPerSample= 1 And img.SamplesPerPixel= 1 ,CscImageFileFormat.CscImgFileFormatTIFFFaxG4,CscImageFileFormat.CscImgFileFormatTIFFOJPG)
332
-
333
- img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepFileOpen, TempPath, 0 , 0 )
334
- img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepExistingPages, TempPath, 0 , 0 )
335
- img.Save(TempPath, imgformat)
336
344
337
-
338
- pXDoc.CDoc.Pages(PageIndex).UnloadImage()
345
+ If MultiPage Then
346
+ Set img=pXDoc.CDoc.Pages(PageIndex).GetImage()
347
+ imgformat=IIf(img.BitsPerSample= 1 And img.SamplesPerPixel= 1 ,CscImageFileFormat.CscImgFileFormatTIFFFaxG4,CscImageFileFormat.CscImgFileFormatTIFFOJPG)
348
+ img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepFileOpen, TempPath, 0 , 0 )
349
+ img.StgFilterControl(imgformat, CscStgControlOptions.CscStgCtrlTIFFKeepExistingPages, TempPath, 0 , 0 )
350
+ img.Save(TempPath, imgformat)
351
+ Else
352
+ pXDoc.CDoc.Pages(PageIndex).GetImage().Save(fso.BuildPath(ExportPath,DocName & "-Page-" & Format(PageIndex+ 1 , "000" ) & ".tif" ),CscImgFileFormatTIFFOJPG)
353
+ pXDoc.CDoc.Pages(PageIndex).UnloadImage()
354
+ End If
339
355
Next
340
356
341
- If pXDoc.CDoc.Pages.Count> 0 Then
357
+ If MultiPage And pXDoc.CDoc.Pages.Count> 0 Then
342
358
' Close the multipage tiff file that was kept open
343
359
Set img=pXDoc.CDoc.Pages( 0 ).GetImage()
344
360
img.StgFilterControl(CscImageFileFormat.CscImgFileFormatTIFFFaxG4, CscStgControlOptions.CscStgCtrlTIFFCloseFile, TempPath, 0 , 0 )
@@ -352,6 +368,8 @@ Public Sub ExportPagesAsMultipageTiff(pXDoc As CscXDocument)
352
368
Debug.Print( "Finished " & pXDoc.CDoc.Pages.Count & " pages from document # " & pXDoc.IndexInFolder+ 1 & " (" & DocName & ")" )
353
369
End Sub
354
370
371
+
372
+
355
373
Private Sub Batch_Open( ByVal pXRootFolder As CASCADELib.CscXFolder)
356
374
' Invoke DevMenu by testing the Batch_Open function (lightning bolt)
357
375
DevMenu_Show(pXRootFolder)
0 commit comments