Retrieve Page Count from Multi Page Tiff files

Hello everyone

Is there an easy way to count the number of pages on .tif files on every file in a folder?

Just to ensure that we have understood in the right way: do you refer to so-called multi-page tiffs and want to retrieve that page count per tif file?

1 Like

Hi @sidb ,

this is for get Directory from all subfolder

stPath = "C:\Users\root\Downloads\Test"

Directory.GetFiles(stPath,“*.tiff”,SearchOption.AllDirectories)

Output


Thanks,
Rajkumar

That’s correct

have a look here:

System.Drawing.Image.FromFile(YourFullFilePath).GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)

To retrieve all tiff files from a folder we can use e.g. the Directory.GetFiles(… ) Method.
When we can rely on only one filetype extension.

Some files can have the extension TIFF, others also Tif with only one f. We can handle this as following:

arrFullTifFilePath | String Array - String() =

(From fi In New DirectoryInfo(ImageFolder).GetFiles()
Where {".TIF",".TIFF"}.contains(fi.Extension.toUpper())
Select f = fi.FullName).toArray

So a initial modelling could look like this:
Variables:
grafik

Flow:

pgCount = System.Drawing.Image.FromFile(item).GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)
String.Format("File: {0} has PageCount {1}", Path.GetFileName(item), pgCount)

Output:
grafik

Demo files:
TIFF_MultiPageTiff_GetPageCount.zip (2.1 KB)

1 Like

For the case that the total Count of all Tiff files is needed we can do within a signle assign activity:

Assign Activity:
TotalCount | Int32 =

(From fi In New DirectoryInfo(ImageFolder).GetFiles()
Where {".TIF",".TIFF"}.contains(fi.Extension.toUpper())
Select cnt = System.Drawing.Image.FromFile(fi.FullName).GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)).Sum()
1 Like

Hi, thank you for replying.

I am able to retrieve all files from the folder. However, I get an error when trying to do a page count.

I have a For Each with TypeArgument as Object. Inside the For Each I have included the page count you expression you kindly provided:

PgCount = System.Drawing.Image.FromFile(file).GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)

This is the error I see: Option Strick On disallows implicit conversions from ‘Object’ to ‘String’

set the typeargument to string

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.