RTTSoftware Support Forum

PDF-ShellTools => General => Topic started by: nightslayer23 on September 09, 2015, 08:42:21 AM

Title: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on September 09, 2015, 08:42:21 AM
Hi guys,

Would you happen to know a way to get windows explorer to display the PDF page size in Windows Explorer Details view?
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on September 09, 2015, 08:43:14 AM
Getting the number of page for a multipage PDF would also be ideal..
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on September 10, 2015, 12:03:47 AM
PDFs can be formed by pages with different sizes, in the same document, so I'm going to assume the PDFs in question are not in this situation and/or knowing the page size of the first page is sufficient to your needs.

First you need to create a custom field, that will hold the page size, in order to cache the value. Calculating this on the fly is, because of the time it takes, not suited to the Shell responsiveness requirements.
This a done using the PDF-ShellTools manager, custom fields editor (http://www.rttsoftware.com/Manuals/ST/English/CustomFields.htm), for the property handler extension. There is only the need to add a new custom field and name it with appropriated label (e.g. "page size") and name (e.g. PageSize). Check the first attached screenshot for details.
You may also click the advanced button and define this new metadata field as read only.
Click the "apply changes" button to register this new property in the system. It is now possible to set visible the "page size" column in the details view of the Windows Explorer, but it will show empty because we first need to fill it.

To fill this new metadata property we will use a My Scripts (http://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/MyScripts.htm) script.
Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    var file = pdfe.SelectedFiles(i);
    var Page = file.Pages(0);
    if (Page) {
        var w = Math.min(Page.Width, Page.Height);
        var h = Math.max(Page.Width, Page.Height);
        var PSizeStr = w.toFixed() + 'x' + h.toFixed();
        var FileMetadata = file.Metadata;
        if (FileMetadata.PageSize !== PSizeStr) {
            FileMetadata.PageSize = PSizeStr;
            if (FileMetadata.CommitChanges()) {
                pdfe.echo(file.Filename + ' : (' + PSizeStr + ') [OK]');

            } else {
                pdfe.echo(file.Filename + ' [commit changes failed]', 0xFF0000);
            }
        } else {
            pdfe.echo(file.Filename + ' : (' + PSizeStr + ') [already set]');
        }
    }
}
pdfe.echo("Done");

I've attached it bellow, so you just need to unzip and import it, from the manager, context menu extension, my scripts functionality.

Now you just need to run this script on all the PDFs you need to know the page size, to have these PDFs metadata to include a new PageSize named property that hold the document first page size in the Width x Height [millimeters] format (the script can be easily changed to use different units).

All these processed PDFs will now show in the Windows Explorer details view (if the "page size" column is set visible), the value that you can now use to easily sort/manage these PDFs.

For new/not yet process PDFs, you just need to run the script on these PDFs too.
Let me know if you are missing to understand any of the steps.

Regarding your second question, about showing the number of pages for PDF documents. After having the PDF-ShellTools installed, the Windows property system "pages" column will show the number of pages for PDFs too, as it is one of the PDF metadata properties ready available from the PDF-ShellTools PDF property handler shell extension. You just need to set visible that column in the Windows Explorer details view.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: P. Allan on September 10, 2015, 08:14:52 PM
Very nice example for a newbie like me with scripts.  :)

You describe, that it is easy to change units.

How is that done?

Regards
Peder
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on September 10, 2015, 10:52:30 PM
You describe, that it is easy to change units.

How is that done?

There's just the need to add the relevant units conversion math to the script. In the script we have the page width and height in millimeters (the default units returned from the Page object (http://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/MyScriptsAPI.htm#IPDFPage), width and height properties).
From the above script, the relevant code lines are:
Code: [Select]
var w = Math.min(Page.Width, Page.Height);
var h = Math.max(Page.Width, Page.Height);
var PSizeStr = w.toFixed() + 'x' + h.toFixed();

So, let's say we want to have our "width x height" value in inches. The code becomes:
Code: [Select]
//1 inch = 25.4 mm
var w = Math.min(Page.Width, Page.Height) / 25.4;
var h = Math.max(Page.Width, Page.Height) / 25.4;
//Decimals now matter, so better specify the number of significant digits when converting to string
var PSizeStr = w.toPrecision(3) + 'x' + h.toPrecision(3);

And the script will now fill our custom page size property with values in inches. ;)
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 23, 2017, 05:24:32 AM
Sometimes the PDFs I'm needing to look at are actually mixed sizes..

Is there a way to look at each page and then list the page sizes it finds?

I've managed to get the output to display as their A1,A2,A4 etc.. but it doesn't alert or display a multi-sized file.

This would be ultra handy if possible..
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 24, 2017, 03:38:32 AM
How do we get it to display the dimensions in the correct orientation..?

I want say, A1's that are Portrait to display as: 594 x 841 and A1's that are Landscape to display as 841 x 594..
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 24, 2017, 11:38:24 PM
Sometimes the PDFs I'm needing to look at are actually mixed sizes..

Is there a way to look at each page and then list the page sizes it finds?

I've managed to get the output to display as their A1,A2,A4 etc.. but it doesn't alert or display a multi-sized file.

This would be ultra handy if possible..
And show this info in a Windows Explorer column? How to format such data?
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 24, 2017, 11:40:40 PM
How do we get it to display the dimensions in the correct orientation..?

I want say, A1's that are Portrait to display as: 594 x 841 and A1's that are Landscape to display as 841 x 594..
In the above script, change the lines
var w = Math.min(Page.Width, Page.Height);
var h = Math.max(Page.Width, Page.Height);

to
var w = Page.Width;
var h = Page.Height;

Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 25, 2017, 06:08:04 AM
Quote
And show this info in a Windows Explorer column? How to format such data?
Commas?
A1,A4,A3 etc.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 25, 2017, 06:17:51 AM
How do we get it to display the dimensions in the correct orientation..?

I want say, A1's that are Portrait to display as: 594 x 841 and A1's that are Landscape to display as 841 x 594..
In the above script, change the lines
var w = Math.min(Page.Width, Page.Height);
var h = Math.max(Page.Width, Page.Height);

to
var w = Page.Width;
var h = Page.Height;


thank you. I did do this already, kind of worked. Sometimes it works, sometimes not. Must be some glitch where if a pdf has been rotated to landscape, it takes on the original length and width and not the update rotation. I wanted to be able to differentiate Landscape and Portrait files from one another but it doesn't seem possible for some reason.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 26, 2017, 12:46:26 AM
Quote
And show this info in a Windows Explorer column? How to format such data?
Commas?
A1,A4,A3 etc.
A quick modification of the included "List paper sizes used" sample script for you to play.
Code: [Select]
STDSizes=[
{'Size': 'A0','width':841,'height':1189},
{'Size': 'A1','width':594,'height':841},
{'Size': 'A2','width':420,'height':594},
{'Size': 'A3','width':297,'height':420},
{'Size': 'A4','width':210,'height':297},
{'Size': 'A5','width':148,'height':210},
{'Size': 'A6','width':105,'height':148},
{'Size': 'A7','width':74,'height':105},
{'Size': 'A8','width':52,'height':74},
{'Size': 'A9','width':37,'height':52},
{'Size': 'A10','width':26,'height':37},

{'Size': 'B0','width':1000,'height':1414},
{'Size': 'B1','width':707,'height':1000},
{'Size': 'B2','width':500,'height':707},
{'Size': 'B3','width':353,'height':500},
{'Size': 'B4','width':250,'height':353},
{'Size': 'B5','width':176,'height':250},
{'Size': 'B6','width':125,'height':176},
{'Size': 'B7','width':88,'height':125},
{'Size': 'B8','width':62,'height':88},
{'Size': 'B9','width':44,'height':62},
{'Size': 'B10','width':31,'height':44},

{'Size': 'C0','width':917,'height':1297},
{'Size': 'C1','width':648,'height':917},
{'Size': 'C2','width':458,'height':648},
{'Size': 'C3','width':324,'height':458},
{'Size': 'C4','width':229,'height':324},
{'Size': 'C5','width':162,'height':229},
{'Size': 'C6','width':114,'height':162},
{'Size': 'C7','width':81,'height':114},
{'Size': 'C8','width':57,'height':81},
{'Size': 'C9','width':40,'height':57},
{'Size': 'C10','width':28,'height':40},

{'Size': '4A0','width':1682,'height':2378},
{'Size': '2A0','width':1189,'height':1682},

{'Size': 'Letter','width':215.9,'height':279.4},
{'Size': 'Legal','width':215.9,'height':355.6},
{'Size': 'Junior Legal','width':203.2,'height':127},
//{'Size': 'Ledger','width':432,'height':279},
{'Size': 'Tabloid','width':279,'height':432},

{'Size': 'PA4','width':210,'height':280},

{'Size': 'Arch A','width':229,'height':305},
{'Size': 'Arch B','width':305,'height':457},
{'Size': 'Arch C','width':457,'height':610},                           
{'Size': 'Arch D','width':610,'height':914},
{'Size': 'Arch E','width':914,'height':1219},
{'Size': 'Arch E1','width':762,'height':1067},
{'Size': 'Arch E2','width':660,'height':965},
{'Size': 'Arch E3','width':686,'height':991},

{'Size': '2R','width':64,'height':89},
{'Size': 'LD,DSC','width':89,'height':119},
{'Size': '3R,L','width':89,'height':127},
{'Size': 'LW','width':89,'height':133},
{'Size': 'KGD','width':102,'height':136},
{'Size': '4R,KG','width':102,'height':152},
{'Size': '2LD,DSCW','width':127,'height':169},
{'Size': '5R,2L','width':127,'height':178},
{'Size': '2LW','width':127,'height':190},
{'Size': '6R','width':152,'height':203},
{'Size': '8R,6P','width':203,'height':254},
{'Size': 'S8R,6PW','width':203,'height':305},
{'Size': '11R','width':279,'height':356},
{'Size': 'A3+,Super B','width':330,'height':483}
];

STDSizes.sort(function(a, b) {
    return (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0);
});

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

var eps = 1; //size compare tolerance [mm]
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    pdfe.echo('Processing ' + pdfe.SelectedFiles(i).Filename);
    var PaperSizes = {};
    var Pages = pdfe.SelectedFiles(i).Pages;
    for (var ii = 0; ii < Pages.Count; ii++) {
        var Page = Pages(ii);
        if (Page) {
            var w = Math.min(Page.Width, Page.Height);
            var h = Math.max(Page.Width, Page.Height);
            for (var n = 0; n < STDSizes.length; n++) {
                hdif = h - STDSizes[n].height;
                if (Math.abs(hdif) < eps && Math.abs(w - STDSizes[n].width) < eps) {
                    SizeID = STDSizes[n].Size;
                    if (!PaperSizes[SizeID]) {
                        var PaperSize = clone(STDSizes[n]);
//                        PaperSize.Size += ' (' + PaperSize.width + 'x' + PaperSize.height + ')';
                        PaperSize['count'] = 1;
                        PaperSizes[SizeID] = PaperSize;
                    } else {
                        PaperSizes[SizeID].count += 1;
                    }
                    break;
                } else if (hdif > 0) { //stop search if page height>current stdSize height
                    var SizeID = w.toFixed() + 'x' + h.toFixed();
                    var PaperSize = {
                        'Size': SizeID,
                        'width': Math.floor(w * 10) / 10,
                        'height': Math.floor(h * 10) / 10,
                        'notStd': true
                    }

                    STDSizes.splice(n, 0, PaperSize);
                    PaperSize['count'] = 1;
                    PaperSizes[SizeID] = PaperSize;
                    break;
                }
            }
        }
    }

    //sort descending by page size count. Standard sizes and higher heights first
    PaperSizes = sortObj(PaperSizes, function(a, b) {
        if (a['notStd'] == b['notStd']) {
            return (a.count > b.count) ? -1 : ((b.count > a.count) ? 1 : (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0));
        } else if (!a['notStd']) return -1;
        return 1;
    });

    //output results
    pdfe.echo(pdfe.SelectedFiles(i).Filename, 0, 2);
    pdfe.echo(' Size details:');
    for (var n = 0; n < PaperSizes.length; n++) {
        pdfe.echo('   ' + PaperSizes[n].Size + ' = ' + PaperSizes[n].count);
    }

    var sizesStr='';
    for (var n = 0; n < PaperSizes.length; n++) {
    sizesStr=sizesStr+PaperSizes[n].Size+',';   
    }
    pdfe.echo(' Sizes list: ' + sizesStr.substr(0,sizesStr.length-1));   
   
}

pdfe.echo("Done");

//======================================================================
function clone(obj) {
    if (obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for (var key in obj)
    temp[key] = clone(obj[key]);
    return temp;
}

function sortObj(object, sortFunc) {
    var rv = [];
    for (var k in object) {
        if (object.hasOwnProperty(k)) {
            rv.push(object[k]);
        }
    }
    rv.sort(sortFunc);
    return rv;
}
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 26, 2017, 01:00:25 AM
Sometimes it works, sometimes not. Must be some glitch where if a pdf has been rotated to landscape, it takes on the original length and width and not the update rotation. I wanted to be able to differentiate Landscape and Portrait files from one another but it doesn't seem possible for some reason.
Indeed, the page width/height properties are not taking into account the page rotation! I will have this fixed in the next release.
Meanwhile, you can also check the page rotation:

        if (Page.Rotation == 90 || Page.Rotation == 270) {
            var w = Page.Height;
            var h = Page.Width;
        } else {
            var w = Page.Width;
            var h = Page.Height;
        }
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 29, 2017, 03:42:27 AM
Quote
And show this info in a Windows Explorer column? How to format such data?
Commas?
A1,A4,A3 etc.
A quick modification of the included "List paper sizes used" sample script for you to play.
Code: [Select]
STDSizes=[
{'Size': 'A0','width':841,'height':1189},
{'Size': 'A1','width':594,'height':841},
{'Size': 'A2','width':420,'height':594},
{'Size': 'A3','width':297,'height':420},
{'Size': 'A4','width':210,'height':297},
{'Size': 'A5','width':148,'height':210},
{'Size': 'A6','width':105,'height':148},
{'Size': 'A7','width':74,'height':105},
{'Size': 'A8','width':52,'height':74},
{'Size': 'A9','width':37,'height':52},
{'Size': 'A10','width':26,'height':37},

{'Size': 'B0','width':1000,'height':1414},
{'Size': 'B1','width':707,'height':1000},
{'Size': 'B2','width':500,'height':707},
{'Size': 'B3','width':353,'height':500},
{'Size': 'B4','width':250,'height':353},
{'Size': 'B5','width':176,'height':250},
{'Size': 'B6','width':125,'height':176},
{'Size': 'B7','width':88,'height':125},
{'Size': 'B8','width':62,'height':88},
{'Size': 'B9','width':44,'height':62},
{'Size': 'B10','width':31,'height':44},

{'Size': 'C0','width':917,'height':1297},
{'Size': 'C1','width':648,'height':917},
{'Size': 'C2','width':458,'height':648},
{'Size': 'C3','width':324,'height':458},
{'Size': 'C4','width':229,'height':324},
{'Size': 'C5','width':162,'height':229},
{'Size': 'C6','width':114,'height':162},
{'Size': 'C7','width':81,'height':114},
{'Size': 'C8','width':57,'height':81},
{'Size': 'C9','width':40,'height':57},
{'Size': 'C10','width':28,'height':40},

{'Size': '4A0','width':1682,'height':2378},
{'Size': '2A0','width':1189,'height':1682},

{'Size': 'Letter','width':215.9,'height':279.4},
{'Size': 'Legal','width':215.9,'height':355.6},
{'Size': 'Junior Legal','width':203.2,'height':127},
//{'Size': 'Ledger','width':432,'height':279},
{'Size': 'Tabloid','width':279,'height':432},

{'Size': 'PA4','width':210,'height':280},

{'Size': 'Arch A','width':229,'height':305},
{'Size': 'Arch B','width':305,'height':457},
{'Size': 'Arch C','width':457,'height':610},                           
{'Size': 'Arch D','width':610,'height':914},
{'Size': 'Arch E','width':914,'height':1219},
{'Size': 'Arch E1','width':762,'height':1067},
{'Size': 'Arch E2','width':660,'height':965},
{'Size': 'Arch E3','width':686,'height':991},

{'Size': '2R','width':64,'height':89},
{'Size': 'LD,DSC','width':89,'height':119},
{'Size': '3R,L','width':89,'height':127},
{'Size': 'LW','width':89,'height':133},
{'Size': 'KGD','width':102,'height':136},
{'Size': '4R,KG','width':102,'height':152},
{'Size': '2LD,DSCW','width':127,'height':169},
{'Size': '5R,2L','width':127,'height':178},
{'Size': '2LW','width':127,'height':190},
{'Size': '6R','width':152,'height':203},
{'Size': '8R,6P','width':203,'height':254},
{'Size': 'S8R,6PW','width':203,'height':305},
{'Size': '11R','width':279,'height':356},
{'Size': 'A3+,Super B','width':330,'height':483}
];

STDSizes.sort(function(a, b) {
    return (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0);
});

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

var eps = 1; //size compare tolerance [mm]
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    pdfe.echo('Processing ' + pdfe.SelectedFiles(i).Filename);
    var PaperSizes = {};
    var Pages = pdfe.SelectedFiles(i).Pages;
    for (var ii = 0; ii < Pages.Count; ii++) {
        var Page = Pages(ii);
        if (Page) {
            var w = Math.min(Page.Width, Page.Height);
            var h = Math.max(Page.Width, Page.Height);
            for (var n = 0; n < STDSizes.length; n++) {
                hdif = h - STDSizes[n].height;
                if (Math.abs(hdif) < eps && Math.abs(w - STDSizes[n].width) < eps) {
                    SizeID = STDSizes[n].Size;
                    if (!PaperSizes[SizeID]) {
                        var PaperSize = clone(STDSizes[n]);
//                        PaperSize.Size += ' (' + PaperSize.width + 'x' + PaperSize.height + ')';
                        PaperSize['count'] = 1;
                        PaperSizes[SizeID] = PaperSize;
                    } else {
                        PaperSizes[SizeID].count += 1;
                    }
                    break;
                } else if (hdif > 0) { //stop search if page height>current stdSize height
                    var SizeID = w.toFixed() + 'x' + h.toFixed();
                    var PaperSize = {
                        'Size': SizeID,
                        'width': Math.floor(w * 10) / 10,
                        'height': Math.floor(h * 10) / 10,
                        'notStd': true
                    }

                    STDSizes.splice(n, 0, PaperSize);
                    PaperSize['count'] = 1;
                    PaperSizes[SizeID] = PaperSize;
                    break;
                }
            }
        }
    }

    //sort descending by page size count. Standard sizes and higher heights first
    PaperSizes = sortObj(PaperSizes, function(a, b) {
        if (a['notStd'] == b['notStd']) {
            return (a.count > b.count) ? -1 : ((b.count > a.count) ? 1 : (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0));
        } else if (!a['notStd']) return -1;
        return 1;
    });

    //output results
    pdfe.echo(pdfe.SelectedFiles(i).Filename, 0, 2);
    pdfe.echo(' Size details:');
    for (var n = 0; n < PaperSizes.length; n++) {
        pdfe.echo('   ' + PaperSizes[n].Size + ' = ' + PaperSizes[n].count);
    }

    var sizesStr='';
    for (var n = 0; n < PaperSizes.length; n++) {
    sizesStr=sizesStr+PaperSizes[n].Size+',';   
    }
    pdfe.echo(' Sizes list: ' + sizesStr.substr(0,sizesStr.length-1));   
   
}

pdfe.echo("Done");

//======================================================================
function clone(obj) {
    if (obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for (var key in obj)
    temp[key] = clone(obj[key]);
    return temp;
}

function sortObj(object, sortFunc) {
    var rv = [];
    for (var k in object) {
        if (object.hasOwnProperty(k)) {
            rv.push(object[k]);
        }
    }
    rv.sort(sortFunc);
    return rv;
}

At what point do I modify this sorry to add the information to the metadata? I am trying but struggling  :S
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 29, 2017, 11:52:33 PM
At what point do I modify this sorry to add the information to the metadata? I am trying but struggling  :S

You may replace the line
  pdfe.echo(' Sizes list: ' + sizesStr.substr(0,sizesStr.length-1));
by:
Code: [Select]
    sizesStr = sizesStr.substr(0, sizesStr.length - 1);
    var FileMetadata = pdfe.SelectedFiles(i).Metadata;
    if (FileMetadata.PageSize !== sizesStr) {
        FileMetadata.PageSize = sizesStr;
        if (FileMetadata.CommitChanges()) {
            pdfe.echo('(' + sizesStr + ') [OK]');
        } else {
            pdfe.echo('Set metadata property failed', 0xFF0000);
        }
    } else {
        pdfe.echo('(' + sizesStr + ') [already set]');
    }

Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 30, 2017, 01:44:54 AM
I get the following error:

Object doesn't support this property or method 144 8
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 30, 2017, 02:27:16 AM
Little mistake in these new code lines (I didn't tested it previously). I've edited my post with the correct code now.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on May 30, 2017, 04:13:25 AM
Sometimes it works, sometimes not. Must be some glitch where if a pdf has been rotated to landscape, it takes on the original length and width and not the update rotation. I wanted to be able to differentiate Landscape and Portrait files from one another but it doesn't seem possible for some reason.
Indeed, the page width/height properties are not taking into account the page rotation! I will have this fixed in the next release.
Meanwhile, you can also check the page rotation:

        if (Page.Rotation == 90 || Page.Rotation == 270) {
            var w = Page.Height;
            var h = Page.Width;
        } else {
            var w = Page.Width;
            var h = Page.Height;
        }


Would I make this a new script? And a new Metadata field?
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on May 31, 2017, 12:55:53 AM
Would I make this a new script? And a new Metadata field?
This is just a code snippet, not a complete script, for you to use in the script you told was not working correctly when the pages where rotated.
A new script, or metadata field, depends if you also need the info from the original script. If not, you may just adapt the original script to your needs and store the info in the same field.
But the first script only gets the size of the first page, so if you need to know all the different sizes of the document, the code needs to be changed.
The newest script, that returns the list of sizes using the names for the standard paper sizes, is not useful for this as and A4 sheet is still A4 size even if landscape.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on June 04, 2019, 05:04:03 AM
Hi again, could I request an add on to this script? Say keep everything as it is, but make another metadata entry for a Property Handle called "orientation" whereby, if the height > width of PDF size, then add metadata 'orientation' called "Portrait". Likewise, for if width > height then 'orientation' = "Landscape"
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on June 05, 2019, 01:13:03 AM
Check if the attached script, a modification of the first script to also fill a PageOrientation named property, does the job.
Don't forget to configure a metadata property named "PageOrientation", before testing.
The script code, for easy reference.
Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    var file = pdfe.SelectedFiles(i);
    var Page = file.Pages(0);
    if (Page) {
        var w = Math.min(Page.Width, Page.Height);
        var h = Math.max(Page.Width, Page.Height);
        var PSizeStr = w.toFixed() + 'x' + h.toFixed();
        var FileMetadata = file.Metadata;
        var Changed = false;
        if (FileMetadata.PageSize !== PSizeStr) {
            FileMetadata.PageSize = PSizeStr;
            Changed = true;
        }
        var PageOrientationStr;
        (Page.Height > Page.Width) ? PageOrientationStr = 'Portrait' : PageOrientationStr = 'Landscape';
        if (FileMetadata.PageOrientation !== PageOrientationStr) {
            FileMetadata.PageOrientation = PageOrientationStr;
            Changed = true;
        }
        if (Changed) {
            if (FileMetadata.CommitChanges()) {
                pdfe.echo(file.Filename + ' : (' + PSizeStr + ' - ' + PageOrientationStr + ') [OK]');

            } else {
                pdfe.echo(file.Filename + ' [commit changes failed]', 0xFF0000);
            }
        } else {
            pdfe.echo(file.Filename + ' : (' + PSizeStr + ' - ' + PageOrientationStr + ') [properties already set]');
        }
    }
}
pdfe.echo("Done");
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on March 02, 2020, 10:49:35 PM
this only works for the first page?
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on March 04, 2020, 12:17:47 AM
It's coded that way. Only the first page is checked for page orientation.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on March 13, 2020, 02:09:42 AM
It's coded that way. Only the first page is checked for page orientation.

Could we adjust the script to look at every page and display them as a list similar to the page size check?
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on March 17, 2020, 01:34:51 AM
Please give me a practical example, with an attached PDF or by describing the PDF pages size and orientation, of what you expect to be the result PageSize and PageOrientation metadata properties.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: nightslayer23 on March 30, 2020, 05:43:03 AM
So you have a PDF document with 50 pages, one of those pages is a portrait page but your print software requires everything be Landscape..

So instead of checking page one for orientation, it checks all pages.

If all come out to be landscape then landscape is the output. If all are portrait, portrait the output. If however the PDF has mixed orientation, MIXED could be the term.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on April 01, 2020, 02:55:36 AM
A modification of a previous script, that fills the PageSize property with the list of paper sizes, that now also calculates the PageOrientation property checking all the pages.
Code: [Select]
STDSizes=[
{'Size': 'A0','width':841,'height':1189},
{'Size': 'A1','width':594,'height':841},
{'Size': 'A2','width':420,'height':594},
{'Size': 'A3','width':297,'height':420},
{'Size': 'A4','width':210,'height':297},
{'Size': 'A5','width':148,'height':210},
{'Size': 'A6','width':105,'height':148},
{'Size': 'A7','width':74,'height':105},
{'Size': 'A8','width':52,'height':74},
{'Size': 'A9','width':37,'height':52},
{'Size': 'A10','width':26,'height':37},

{'Size': 'B0','width':1000,'height':1414},
{'Size': 'B1','width':707,'height':1000},
{'Size': 'B2','width':500,'height':707},
{'Size': 'B3','width':353,'height':500},
{'Size': 'B4','width':250,'height':353},
{'Size': 'B5','width':176,'height':250},
{'Size': 'B6','width':125,'height':176},
{'Size': 'B7','width':88,'height':125},
{'Size': 'B8','width':62,'height':88},
{'Size': 'B9','width':44,'height':62},
{'Size': 'B10','width':31,'height':44},

{'Size': 'C0','width':917,'height':1297},
{'Size': 'C1','width':648,'height':917},
{'Size': 'C2','width':458,'height':648},
{'Size': 'C3','width':324,'height':458},
{'Size': 'C4','width':229,'height':324},
{'Size': 'C5','width':162,'height':229},
{'Size': 'C6','width':114,'height':162},
{'Size': 'C7','width':81,'height':114},
{'Size': 'C8','width':57,'height':81},
{'Size': 'C9','width':40,'height':57},
{'Size': 'C10','width':28,'height':40},

{'Size': '4A0','width':1682,'height':2378},
{'Size': '2A0','width':1189,'height':1682},

{'Size': 'Letter','width':215.9,'height':279.4},
{'Size': 'Legal','width':215.9,'height':355.6},
{'Size': 'Junior Legal','width':203.2,'height':127},
//{'Size': 'Ledger','width':432,'height':279},
{'Size': 'Tabloid','width':279,'height':432},

{'Size': 'PA4','width':210,'height':280},

{'Size': 'Arch A','width':229,'height':305},
{'Size': 'Arch B','width':305,'height':457},
{'Size': 'Arch C','width':457,'height':610},                           
{'Size': 'Arch D','width':610,'height':914},
{'Size': 'Arch E','width':914,'height':1219},
{'Size': 'Arch E1','width':762,'height':1067},
{'Size': 'Arch E2','width':660,'height':965},
{'Size': 'Arch E3','width':686,'height':991},

{'Size': '2R','width':64,'height':89},
{'Size': 'LD,DSC','width':89,'height':119},
{'Size': '3R,L','width':89,'height':127},
{'Size': 'LW','width':89,'height':133},
{'Size': 'KGD','width':102,'height':136},
{'Size': '4R,KG','width':102,'height':152},
{'Size': '2LD,DSCW','width':127,'height':169},
{'Size': '5R,2L','width':127,'height':178},
{'Size': '2LW','width':127,'height':190},
{'Size': '6R','width':152,'height':203},
{'Size': '8R,6P','width':203,'height':254},
{'Size': 'S8R,6PW','width':203,'height':305},
{'Size': '11R','width':279,'height':356},
{'Size': 'A3+,Super B','width':330,'height':483}
];

STDSizes.sort(function(a, b) {
    return (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0);
});

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

var eps = 1; //size compare tolerance [mm]
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var PaperSizes = {};
    var File = pdfe.SelectedFiles(i);
    var Pages = File.Pages;
    var PortraitCount = 0;
    var LandscapeCount = 0;
    ProgressBar.position = i + 1;
    pdfe.echo(File.Filename);
    if (Pages.Count > 0) {
        for (var ii = 0; ii < Pages.Count; ii++) {
            var Page = Pages(ii);
            if (Page) {
                var w = Math.min(Page.Width, Page.Height);
                var h = Math.max(Page.Width, Page.Height);
                for (var n = 0; n < STDSizes.length; n++) {
                    hdif = h - STDSizes[n].height;
                    if (Math.abs(hdif) < eps && Math.abs(w - STDSizes[n].width) < eps) {
                        SizeID = STDSizes[n].Size;
                        if (!PaperSizes[SizeID]) {
                            var PaperSize = clone(STDSizes[n]);
                            PaperSize['count'] = 1;
                            PaperSizes[SizeID] = PaperSize;
                        } else {
                            PaperSizes[SizeID].count += 1;
                        }
                        break;
                    } else if (hdif > 0) { //stop search if page height>current stdSize height
                        var SizeID = w.toFixed() + 'x' + h.toFixed();
                        var PaperSize = {
                            'Size': SizeID,
                            'width': Math.floor(w * 10) / 10,
                            'height': Math.floor(h * 10) / 10,
                            'notStd': true
                        }

                        STDSizes.splice(n, 0, PaperSize);
                        PaperSize['count'] = 1;
                        PaperSizes[SizeID] = PaperSize;
                        break;
                    }
                }

                (Page.Height > Page.Width) ? PortraitCount++ : LandscapeCount++;
            }
        }

        //sort descending by page size count. Standard sizes and higher heights first
        PaperSizes = sortObj(PaperSizes, function(a, b) {
            if (a['notStd'] == b['notStd']) {
                return (a.count > b.count) ? -1 : ((b.count > a.count) ? 1 : (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0));
            } else if (!a['notStd']) return -1;
            return 1;
        });


        var FileMetadata = File.Metadata;
        var Changed = false;

        var sizesStr = '';
        for (var n = 0; n < PaperSizes.length; n++) {
            sizesStr = sizesStr + PaperSizes[n].Size + ',';
        }

        sizesStr = sizesStr.substr(0, sizesStr.length - 1);
        if (FileMetadata.PageSize !== sizesStr) {
            FileMetadata.PageSize = sizesStr;
            Changed = true;
        }

        var PageOrientationStr = 'Portrait';
        if (PortraitCount && LandscapeCount) PageOrientationStr = 'Mixed'
        else if (LandscapeCount) PageOrientationStr = 'Landscape';

        if (FileMetadata.PageOrientation !== PageOrientationStr) {
            FileMetadata.PageOrientation = PageOrientationStr;
            Changed = true;
        }

        if (Changed) {
            if (FileMetadata.CommitChanges()) {
                pdfe.echo('      (Paper sizes: ' + sizesStr + ' - Orientation: ' + PageOrientationStr + ') [OK]');
            } else {
                pdfe.echo('      [commit changes failed]', 0xFF0000);
            }
        } else {
            pdfe.echo('      (Paper sizes: ' + sizesStr + ' - Orientation: ' + PageOrientationStr + ') [properties already set]');
        }

    } else {
        pdfe.echo('      [not a PDF or has no pages]', 0xFF0000);
    }
}

pdfe.echo("Done");

//======================================================================
function clone(obj) {
    if (obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for (var key in obj)
    temp[key] = clone(obj[key]);
    return temp;
}

function sortObj(object, sortFunc) {
    var rv = [];
    for (var k in object) {
        if (object.hasOwnProperty(k)) {
            rv.push(object[k]);
        }
    }
    rv.sort(sortFunc);
    return rv;
}
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: timtak on March 21, 2021, 09:58:40 PM
Thank you. I got it working. Either because I installed the optional "Filter Handler Metadata Properties Extender" when I installed shell-scripts, or because I used a different script. I used the one downloaded from
https://www.rttsoftware.com/forum/index.php?action=dlattach;topic=507.0;attach=390
this time. It does not display A4 and the like but perhaps that is preferable because I can see the orientation without having to add another custom field.

I got the PDF-Shell script to run, and in the results of the run the sizes are displayed.

Code: [Select]
C:\Users\TT\Desktop\Temp\Ninja_English_001.pdf
  Size details:
    297x424 = 1
  Sizes list: 297x424
 C:\Users\TT\Desktop\Temp\Hyouka.pdf
  Size details:
    A4 = 2
  Sizes list: A4
 C:\Users\TT\Desktop\Temp\Yamaguchi_Niho_26.pdf
  Size details:
    A4 = 3
  Sizes list: A4
 C:\Users\TT\Desktop\Temp\calendar.pdf
  Size details:
    A4 = 1
  Sizes list: A4
 C:\Users\TT\Desktop\Temp\Kim_Culture_and_self_expression.pdf
  Size details:
    Letter = 35
  Sizes list: Letter
 Done

And "Page size" is also being displayed as a column in explorer but the page sizes are empty. and now the page sizes are displayed too.

I did not need to close the run box but perhaps I needed to install the "Filter Handler Metadata Properties Extender," which I did on this computer.

PS This is a great piece of software! I may even buy it! (I had thought that I would just be using it once but I am really liking it). When I rotate using PDF ShellTools it does not change the creator nor producer field of the document which is very good since my printer insists everything is made by Adobe or MS Word. Hopefully they will not notice.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on March 22, 2021, 04:43:49 PM
I did not need to close the run box but perhaps I needed to install the "Filter Handler Metadata Properties Extender," which I did on this computer.
The script saves the calculated sizes to the PDF itself, into the metadata custom field you configured with the manager. You can always use a PDF reader to check if the metadata got indeed saved to the file, e.g. File>Properties (CTRL+D) in Acrobat. The Windows File Explorer will use the PDF-ShellTools PDF Property Handler to access these properties, so these are available immediately after the metadata is saved to the PDF. That's why you didn't needed to close the script output window.

I don't think having the "Filter Handler Metadata Properties Extender" installed, or not, is related to the problem you experienced with the other script.
But, latest Windows 10 versions, e.g. 20H2, seems to have Windows Search issues, with the Search Indexer failing to index the metadata if, under the Windows Advanced Indexing Options, the PDF file type is set to index the properties and file contents, instead of just the properties. The indexer uses the registered PDF filter to gather the file contents and metadata properties (if also exported by the filter) and discard the metadata properties exported by the call to the properties handler, despite still calling it. This result in the Windows Search not finding by searching by any, supposedly, indexed metadata word(s). Having the "Filter Handler Metadata Properties Extender" registered fix this, as this filter also exports the PDFs metadata properties. When this issue is present, the PDF-ShellTools Reader Windows Search Explorer shows all the metadata columns empty.
Let's hope Microsoft fix this issue soon.

Quote
PS This is a great piece of software! I may even buy it! (I had thought that I would just be using it once but I am really liking it). When I rotate using PDF ShellTools it does not change the creator nor producer field of the document which is very good since my printer insists everything is made by Adobe or MS Word. Hopefully they will not notice.
Spread the word. :)
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: timtak on March 24, 2021, 10:14:04 PM
> The script saves the calculated sizes to the PDF itself.

Perhaps that was my problem. Perhaps I had the PDF files (that did not display page size) open, and that prevented ShellTools from saving the sizes to the PDFs.

Thank you very much indeed.

I will try to spread the word. It is the least I can do.

[Excuses I don't think I will be using this software again for another few years, until I send my textbook off to be printer again. I am using a really cheap printing company that helps very little and is quite strict, requiring each page be a separate PDF and that the page size, creating program, orientation be identical and that number of pages be one. Shell tools made checking these constraints very easy. But until I send my textbook off to a printing company again, in about 5 years time, I am not sure I  need the super functionality. I will have a think. If I need the functionality in my job then I can use my work budget. ]
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: Nick Riviera on April 29, 2022, 07:15:40 AM
Hello,
I work with pdfs that contains internal measurements (cropbox, trimbox..)
Can you make a script that show the  trim  and bleed box size in Windows Explorer ?
eg. 215.9 x 279.4mm+5mm
Thank you very much.

Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    var file = pdfe.SelectedFiles(i);
    var Page = file.Pages(0);
    if (Page) {
        var w = Math.min(Page.Width, Page.Height);
        var h = Math.max(Page.Width, Page.Height);
        var PSizeStr = w.toFixed() + 'x' + h.toFixed();
        var FileMetadata = file.Metadata;
        if (FileMetadata.PageSize !== PSizeStr) {
            FileMetadata.PageSize = PSizeStr;
            if (FileMetadata.CommitChanges()) {
                pdfe.echo(file.Filename + ' : (' + PSizeStr + ') [OK]');

            } else {
                pdfe.echo(file.Filename + ' [commit changes failed]', 0xFF0000);
            }
        } else {
            pdfe.echo(file.Filename + ' : (' + PSizeStr + ') [already set]');
        }
    }
}
pdfe.echo("Done");
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on April 29, 2022, 03:38:22 PM
Check reply 5, at this trim + bleed size (https://www.rttsoftware.com/forum.php?dsturl=https%3A%2F%2Fwww.rttsoftware.com%2Fforum%2Findex.php%3Ftopic%3D722.msg2303) topic started by you.
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: chrisrace on March 16, 2023, 09:51:10 AM
Hi - great scripts! We use a lot of PDF's (we're architects) would it be possible for this script to run automatically or create a ribbon button to run this automatically? Just wanting to make the process as simple as possible for the guys. Thanks Chris
Title: Re: Displaying PDF Page Size in Windows Explorer
Post by: RTT on March 17, 2023, 03:19:08 AM
You may use the RunScript command line function (https://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/MyScripts.htm#cmdline) to run the script from a shortcut, batch file, PowerShell script, etc.
But it's easy for the user to manually select the PDF files that have the specific column empty (sorting by that column), invoke the right click menu and call the script from the PDF-ShellTools sub-menu.