Skip to main content
Kofax

How to read image height from script

Article # 3035735 - Page views: 51

Issue

We are using KTM script to bind two images into a single image.
From time to time, there is an error when copying an existing image to the new one (image.CopyRect method).
The error is thrown at this instruction:

NewImg.CopyRect(pXDoc.CDoc.Pages(0).GetImage, 0, 0, 0, 0, pXDoc.CDoc.Pages(0).Width, pXDoc.CDoc.Pages(0).Height)

I have debugged the script and it seems that there is a difference between the image dimensions on disk (height = 1188) and image dimensions read by KTM script (1204).
If I execute the exact same script, but hardcoding the image dimensions to the ones from disk (2224, 1188), the script is running fine. If I set the height to a value higher than 1188, it throws the error -> InvalidArgument(522).

 

Cause

When manipulating images (merge/split etc.) after they were processed in KTM Server - and when the XDocument file was created - it can happen that the actual dimensions and the ones in XDocument do not match.

 

Solution

As it is difficult to reload the image to get the new dimensions and retain the already extracted data, you can use external libraries to get the actual dimensions. You can use e.g. Shell.Application object, or WIA.ImageFile.

See e.g. https://social.msdn.microsoft.com/Forums/office/en-US/5f375529-a002-4312-a54b-b70d6d3eb6ae/how-to-retrieve-image-dimensions-using-vba-?forum=accessdev
or
https://myengineeringworld.net/2018/02/image-size-pixels-vba.html

 

Level of Complexity 

Moderate

 

Applies to  

Product Version Build Environment Hardware
Kofax Transformation Modules All      

 

References

Add any references to other internal or external articles

 

 

Article # 3035735
  • Was this article helpful?