Skip to main content

How to read image height from script

Article # 3035735 - Page views: 61


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).



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.



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.


Level of Complexity 



Applies to  

Product Version Build Environment Hardware
Kofax Transformation Modules All      



Add any references to other internal or external articles



Article # 3035735
  • Was this article helpful?