PDF-ShellTools > General

Displaying PDF Page Size in Windows Explorer

(1/7) > >>

nightslayer23:
Hi guys,

Would you happen to know a way to get windows explorer to display the PDF page size in Windows Explorer Details view?

nightslayer23:
Getting the number of page for a multipage PDF would also be ideal..

RTT:
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, 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 script.

--- Code: ---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");

--- End code ---

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.

P. Allan:
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

RTT:

--- Quote from: P. Allan on September 10, 2015, 08:14:52 PM ---You describe, that it is easy to change units.

How is that done?

--- End quote ---

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, width and height properties).
From the above script, the relevant code lines are:

--- Code: ---var w = Math.min(Page.Width, Page.Height);
var h = Math.max(Page.Width, Page.Height);
var PSizeStr = w.toFixed() + 'x' + h.toFixed();

--- End code ---

So, let's say we want to have our "width x height" value in inches. The code becomes:

--- Code: ---//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);

--- End code ---

And the script will now fill our custom page size property with values in inches. ;)

Navigation

[0] Message Index

[#] Next page

Go to full version