ImageControls:
Product
Support Overview
ImageControls 3:
Product
Support Overview
Application
Notes
Downloads
Library
Error
Codes
FAQs
Revision
Levels
Supported
Configurations
Technical
Documentation
OTHER TOOLS:
Knowledgebase
Support
Request
PRODUCT INFO:
Product
Overview
IC Toolkit 3.1 is the most recent release of the ImageControls Toolkit.
If you are running a previous version of Kofax ImageControls, refer to the ImageControls How to Buy Web page for details on how to obtain the appropriate ImageControls 3 release for your configuration.
ImageControls 2.0 allows you to insert and append pages to a multipage TIFF files. However, what is missing is the ability to delete individual pages from a multipage TIFF file. While a specific method is not provided for this purpose, the ability is still there. This article will address this particular issue.

There is only one form in the project. I have used control arrays whenever possible to simplify the code. Since you will be scanning from disk, you will need to make sure that you have a File Import Source selected as the default in the Kofax Source Manager (KSM). This can be either the default Software File Import Source or a Hardware File Import From Disk Source.
Option Explicit
Dim g_FileName As String 'Global Filename
Dim g_PSCounter As Integer 'Page Start event counter
Dim g_PECounter As Integer 'Page End event counter
Private Sub Form_Load()
'*** You will need to make sure that you have selected
'*** a File Import source in the Source Manager. This
'*** can be either the default Kofax Software Import
'*** Source or a Hardware Import From Disk Source.
With Kscan1
If .DeviceReserved Then
.Action = KSACTIONUNRESERVE
End If
.Action = KSACTIONRESET
.Action = KSACTIONRESERVE
End With
End Sub
After Adding and sizing the Kview control, go to the Properties window and set the FitHeight and FitWidth properties to true so that you will be able to see the entire image. I also set the BandingMode property to Mouse Up Auto-Zoom and BandingModeRight to Pan. The larger SSCommand buttons are in a separate array from the two containing the arrow pictures.
Following is the entire code listing for the project. All reserving and resetting is done in the Form_Load event. Files are opened using a CommonDialog control. The returned filename is then assigned to the global string g_FileName. Once the file is loaded the user can peruse the individual pages using the two arrow buttons. When a page is to be deleted, the Delete button is pressed and a Kscan Action Start (KSACTIONSTART) is initialized in batch mode and the IOWriteMode to Append. If however, no file has yet been loaded then a message box will be presented telling the user this. If the current displayed file only has one page then the user will be given a choice whether to delete the file. There are two separate counters used in the batch process:
g_PECounter g_PSCounter
These are nessesary to compensate for pre-scan cache (DeviceCache property) settings of greater than 0. The g_PSCounter is used to set the PSPage property of the input file being scanned. The g_PECounter is used to keep track of the current page being written out to disk. When the g_PECounter equals the current displayed page (Kview1.Page), the PEFileName property is set to "" thereby causing that page to not be written. This effectively deletes the page.
In the Batch_End event, the old file is backed up the temporary file is copied to the current filename and the temporary file is deleted.
In the Batch_End event, the old file is backed up the temporary
file is copied to the current filename and the temporary file
is deleted.
Private Sub Kscan1_BatchStart() '*** We need separate counters for the Page Start '*** and Page End events to accomodate for any '*** DeviceCache. g_PSCounter = 1 g_PECounter = 1 End SubPrivate Sub Kscan1_PageStart() '*** Scan in the individual pages in a multipage TIFF With Kscan1 .PSFileName = g_FileName If g_PSCounter > .PSPageCount Then .PSFileName = "" Else .PSPage = g_PSCounter g_PSCounter = g_PSCounter + 1 End If End With End SubPrivate Sub Kscan1_PageEnd() '*** Simply don't write out the KView current page With Kscan1 If g_PECounter = KView1.Page Then .PEFileName = "" Else .PEFileName = "temp.tif" End If End With g_PECounter = g_PECounter + 1 End Sub
Private Sub Kscan1_BatchEnd()
Dim ctr As Integer
Dim BackFile As String
'*** Set the KView to point to the page just before
'*** the one that was deleted
ctr = KView1.Page - 1
If ctr = 0 Then ctr = 1
'*** Create a backup of the original file
BackFile = g_FileName
Mid$(BackFile, Len(BackFile) - 2, 3) = "bak"
On Error GoTo BackFileErr
Name g_FileName As BackFile
'*** Delete the temporary file
FileCopy "temp.tif", g_FileName
Kill "temp.tif"
'*** Refresh the KView with the new file
KView1.filename = g_FileName
KView1.Action = KVACTIONOPENIMAGE
KView1.Page = ctr
Label1(0).Caption = "Total Pages :" & Str$(KView1.MultiPageCount)
Label1(1).Caption = "Current Page:" & Str$(KView1.Page)
KView1.Refresh
Exit Sub
BackFileErr:
'*** File already exists so delete it
If Err = 58 Then
Kill BackFile
End If
Resume
End Sub
Private Sub SSCommand1_Click(Index As Integer)
Dim Status As Integer
Select Case Index
Case 0
'*** Open a multipage TIFF
With CommonDialog1
.DialogTitle = "File Open"
.Flags = cdlOFNFileMustExist
.Filter = "TIFF (*.tif)|*.tif"
.CancelError = True
On Error Resume Next
.ShowOpen
If Not Err = cdlCancel Then
g_FileName = .filename
KView1.filename = g_FileName
KView1.Refresh
Label1(0).Caption =_
"Total Pages :" & Str$(KView1.MultiPageCount)
Label1(1).Caption = "Current Page:" &_
Str$(KView1.Page)
End If
End With
Case 1
'*** First check if an image has been loaded,
'*** then check whether the image only has one
'*** page and delete it if the user wishes else,
'*** start the scan from disk operation.
If KView1.filename = "" Then
MsgBox "A file has not yet been loaded"
ElseIf KView1.MultiPageCount = 1 Then
Status = MsgBox("This file has only one page._
Do you want to delete it?", vbYesNo)
If Status = vbYes Then
Kill g_FileName
KView1.filename = ""
KView1.Clear
End If
Else
With Kscan1
.IOWriteMode = KGIOWRITEMODEAPPEND
.DeviceMethod = KSDEVICEMETHODBATCH
.Action = KSACTIONSTART
End With
End If
Case 2 Kscan1.Action = KSACTIONUNRESERVE End End Select End Sub
Private Sub SSCommand2_Click(Index As Integer) '*** Move through the pages With KView1 Select Case Index Case 0 If .Page > 1 Then .Page = .Page - 1 .Refresh Label1(1).Caption = "Current Page:" & Str$(.Page) End If Case 1 If .Page < .MultiPageCount Then .Page = .Page + 1 .Refresh Label1(1).Caption = "Current Page:" &_ Str$(KView1.Page) End If End Select End With End Sub
The Kofax ImageControls support group is skilled in Visual Basic and Visual C++ development and can assist developers in building their custom imaging applications. Our engineers can also point developers to source code samples on the Kofax FTP site.
The ImageControls 3 Technical Support Web pages have been kept up to date. We encourage ImageControls developers to investigate the information in these Web pages before looking for other sources of support. Use the menu options in the upper left side of this page to access additional product support Web pages for this product.
For details regarding technical support available for all Kofax products, please review the current Support Overview & Options and Product Support Eligibility Matrix Web pages.
