Page 1 of 1

Columns Display Age-Colour & Number Pages PDF Word

Posted: 26 Apr 2026 21:32
by SAM0MAS
This is an update to the original post to add a 'Pages' column for displaying the number of pages in PDF & Word files, and an 'Age' column with colour-coding similar to the OneCommander style I use at work. I recently started learning XYplorer and plan to make it my main file manager once I'm fully comfortable with it and finish configuring everything.

There is a similar post here:
viewtopic.php?p=212489&hilit=file+page+number#p212489
but it only covers PDFs.

Both tasks were completed with great help from XYplore community - especially thanks to @highend and @admin for their support and swift actions, and of course to Claude AI, my coding buddy ;)

  • Pages
F9 Configuration > Custom Column > Caption 'any name e.g. Pages' > Format Text > Item type Files > Item filter *.pdf, *.doc*

Code: Select all

$ext = recase(gpc("<cc_item>", "ext"), "lower");

if ($ext == "pdf") {
  $result = runret(lax("C:\Tools\Poppler\poppler-25.12.0\Library\bin\pdfinfo.exe" "<cc_item>"), , 65001);
  $line = regexmatches($result, "Pages:\s+\d+");
  return regexmatches($line, "\d+");
}

if ($ext == "docx" || $ext == "doc") {
  $result = runret("powershell -NoProfile -Command ""Add-Type -AssemblyName System.IO.Compression.FileSystem; try { $z=[System.IO.Compression.ZipFile]::OpenRead('<cc_item>'); $e=$z.GetEntry('docProps/app.xml'); if(!$e){$z.Dispose();exit}; $s=$e.Open(); $r=New-Object System.IO.StreamReader($s); $c=$r.ReadToEnd(); $r.Close(); $z.Dispose(); [xml]$x=$c; $p=$x.Properties.Pages; if($p -match '^\d+$'){$p}else{''} } catch {''}"" ", , 65001);
  return regexreplace(trim($result), "\D", "");
}
  • Age-colour
> Format Icon

Code: Select all

$dateM = property("#date.m", "<cc_item>");
$diff  = datediff($dateM, , "n");

$h  = floor($diff / 60);
$d  = floor($diff / 1440);
$M = floor($diff / 43200);
$y  = floor($diff / 525600);
$rm = $diff - ($h * 60);

if ($diff < 0)          { $label = "future"; }
elseif ($diff < 60)     { $label = $diff . "'"; }
elseif ($diff < 1440)   { if ($rm > 0) { $label = $h . " h " . $rm . "'"; } else { $label = $h . " h"; } }
elseif ($diff < 2880)   { $label = "1 d"; }
elseif ($diff < 10080)  { $label = $d . " d"; }
elseif ($diff < 43200)  { $label = $d . " d"; }
elseif ($diff < 525600) { $label = $M . " M"; }
else                    { $label = $y . " y"; }

if ($diff < 0) {
    $r = 170; $g = 238; $b = 221;
} elseif ($diff <= 1440) {
    $t = $diff / 1440;
    $r = floor(244 - (4  * $t));
    $g = floor(167 + (90 * $t));
    $b = floor(158 - (36 * $t));
} elseif ($diff <= 10080) {
    $t = ($diff - 1440) / 8640;
    $r = floor(240 - (90 * $t));
    $g = floor(225 - (8  * $t));
    $b = floor(122 + (28 * $t));
} elseif ($diff <= 43200) {
    $t = ($diff - 10080) / 33120;
    $r = floor(150 - (21 * $t));
    $g = floor(221 - (14 * $t));
    $b = floor(150 + (74 * $t));
} elseif ($diff <= 525600) {
    $t = ($diff - 43200) / 482400;
    $r = floor(125 + (32 * $t));
    $g = floor(207 - (23 * $t));
    $b = floor(224 + (16 * $t));
} else {
    $t = min(($diff - 525600) / 525600, 1);
    $r = floor(157 + (39 * $t));
    $g = floor(184 - (22 * $t));
    $b = floor(240 - (16 * $t));
}

$color = hex($r, 2) . hex($g, 2) . hex($b, 2);
$bar = ">draw.bar 100, " . $color . ", " . $color;
return $bar . " | " . $label;

Re: Column Display Number Pages Word

Posted: 26 Apr 2026 22:06
by jupe
For doc files if you have word installed you should be able to just add a Property column called Pages.

You can't color just the age column, but you can show colored age icons, right click date column header, and at the bottom select Circles, they are shown at start of line, if you want them in date column right click the date circle icon.

Re: Column Display Number Pages Word

Posted: 26 Apr 2026 22:42
by highend
There is a system property for that (somewhat unreliable though because it works better for .docx than .doc and apart from that it depends on printer settings, margins, etc...)
return property("System.Document.PageCount", <cc_item>);

Afaik it's not possible to draw bars and a number in the same cell at the same time but I could be wrong...

Colors for file / folder age can be done:

Code: Select all

    $modified = property("#date.m", "<cc_item>");
    $diff     = datediff($modified, , "n"); // Difference in minutes
    switch (true) {
        case $diff == 0:    return ''; // draw nothing
        case $diff < 1439:  return '>draw.bar ' . 100 . ', 66CC66, BBEEBB'; // less than a day
        case $diff < 2879:  return '>draw.bar ' . 100 . ', FFBB00, FFEE88'; // 1 day
        case $diff < 10079: return '>draw.bar ' . 100 . ', DD4444, FFAAAA'; // 2 - 7 days
        // ...
        default:            return '>draw.bar ' . 100 . ', DD44AA, FFAADD';
    }
For age:

Code: Select all

    $modified = property("#date.m", "<cc_item>");
    $diff     = datediff($modified, , "n"); // Difference in minutes
    switch (true) {
        case $diff == 0:    return ''; // draw nothing
        case $diff < 1439:  return '>draw.bar ' . 100 . ', 66CC66, BBEEBB'; // less than a day
        case $diff < 2879:  return '>draw.bar ' . 100 . ', FFBB00, FFEE88'; // 1 day
        case $diff < 10079: return '>draw.bar ' . 100 . ', DD4444, FFAAAA'; // 2 - 7 days
        // ...
        default:            return '>draw.bar ' . 100 . ', DD44AA, FFAADD';
    }

Re: Column Display Number Pages Word

Posted: 27 Apr 2026 01:32
by SAM0MAS
jupe wrote: 26 Apr 2026 22:06 For doc files if you have word installed you should be able to just add a Property column called Pages.
I tried 'Select Property > Pages', but it displays the page count inaccurately, and some files show no number at all. I'd like to combine PDF and Word page counts into a single column - which I've managed to do - but the Word page info is still not accurate.
jupe wrote: 26 Apr 2026 22:06 You can't color just the age column, but you can show colored age icons, right click date column header, and at the bottom select Circles, they are shown at start of line, if you want them in date column right click the date circle icon.
That's what I'm using now. I wanted have one combined column instead of two.

Re: Column Display Number Pages Word

Posted: 27 Apr 2026 01:48
by SAM0MAS
highend wrote: 26 Apr 2026 22:42 There is a system property for that (somewhat unreliable though because it works better for .docx than .doc and apart from that it depends on printer settings, margins, etc...)
return property("System.Document.PageCount", <cc_item>);

Afaik it's not possible to draw bars and a number in the same cell at the same time but I could be wrong...
In my case it shows the correct page count for some .docx files, but the count is wrong for others .docx

Thanks for the script. As you pointed it out, XYplorer doesn't seem to support combining an Image and text within a single column. This is the closest result I've managed to achieve so far.
xyplorer_pages-count_age-colour.png

Re: Column Display Number Pages Word

Posted: 28 Apr 2026 16:43
by highend
with v27.20.1220/v28.30.0404 you can now create an age column like in your picture...

You have to add / adapt numbers for your ranges and colors as well ofc
E.g.:

Code: Select all

    $dateM = property("#date.m", "<cc_item>");
    $diff  = datediff($dateM, , "n");
    switch (true) {
        case $diff == 0:     return ''; // draw nothing
        case $diff < 1440:   return '>draw.bar ' . 100 . ', F6A29D, BBEEBB|' . datediff($dateM, , "h") . "'||r"; // < 1 d
        case $diff < 43200:  return '>draw.bar ' . 100 . ', 9DF6A0, FFAAAA|' . datediff($dateM, , "d") . " d||r"; // < 1 m
        case $diff < 129600: return '>draw.bar ' . 100 . ', 9DDBF6, FFAAAA|' . datediff($dateM, , "m") . " M||r"; // < 3 m
        case $diff < 259200: return '>draw.bar ' . 100 . ', 9FB3F6, FFAAAA|' . datediff($dateM, , "m") . " M||r"; // < 6 m
        case $diff < 525600: return '>draw.bar ' . 100 . ', B4B7F8, FFAAAA|' . datediff($dateM, , "m") . " M||r"; // < 1 y
        default:             return '>draw.bar ' . 100 . ', E1D8FB, FFAADD|' . datediff($dateM, , "y") . " y||r"; // > 1 y
    }

Re: Column Display Number Pages Word

Posted: 28 Apr 2026 22:07
by SAM0MAS
highend wrote: 28 Apr 2026 16:43 with v27.20.1220/v28.30.0404 you can now create an age column like in your picture...
Thank you for your efforts, but this script yields the same result as the previous one - an image/graphic without the accompanying text (tested on v28.30.0400). I have tried all Format options in F9 > Custom Columns. Have you managed to get image + text to appear in the same cell/column? If so, how did you do it?

Re: Column Display Number Pages Word

Posted: 28 Apr 2026 22:30
by highend
v28.30.0404 not v28.30.0400...

Re: Column Display Number Pages Word

Posted: 29 Apr 2026 00:10
by SAM0MAS
highend, you're legend! That was really fast - thank you.

Are you by any chance part of the XYplorer developer team? ;)
I'm wondering whether it might be possible to fix the Word .doc* page-count issue? Kindly let me know if I need raise a ticket in the Bug Reports thread: viewforum.php?f=2
xyplorer_pages-count_age-colour_v1.png

Re: Column Display Number Pages Word

Posted: 29 Apr 2026 01:05
by highend
As I already said, the system property System.Document.PageCount is unreliable and this is not an XY bug.
There would be ways to get the page count nonetheless but they are rather slow and wouldn't make much sense in a live display environment

Ask the OneCommander developer how he's done it, maybe it can be utilized for XY then...

Re: Column Display Number Pages Word

Posted: 29 Apr 2026 09:19
by admin
Btw, if you don't like that white menu bar in dark mode: You can add "All Menus (Group)" to the toolbar as first row to get a nice looking dark menu (and then hide the white one).

Re: Column Display Number Pages Word

Posted: 30 Apr 2026 02:10
by SAM0MAS
Splendid! Thank you admin for your helpful advice - it looks great now.
xyplorer_pages-count_age-colour_perfect.png

Re: Column Display Number Pages Word

Posted: 30 Apr 2026 02:25
by SAM0MAS
highend wrote: 29 Apr 2026 01:05 As I already said, the system property System.Document.PageCount is unreliable and this is not an XY bug.
There would be ways to get the page count nonetheless but they are rather slow and wouldn't make much sense in a live display environment

Ask the OneCommander developer how he's done it, maybe it can be utilized for XY then...
You were right - the inconsistent .doc* page counts aren't caused by XYplorer. I tested the same .doc* files in OneCommander and saw identical results. There are options like run on demand or using triggers, but since this isn't a critical feature, I'm not too concerned.