Author Topic: rename page size file  (Read 718 times)

0 Members and 1 Guest are viewing this topic.

Urraco

  • Guest
rename page size file
« on: May 22, 2019, 02:36:44 PM »
Hi
I have a hundreds of pdf files

I do not want to open every pdf file to see what format is...
It's possible to rename this files whit page size included?

Ex: Test.pdf   =  > Test_210x297 mm.pdf

Many thanks!!!

RTT

  • Administrator
  • *****
  • Posts: 839
Re: rename page size file
« Reply #1 on: May 23, 2019, 12:42:32 AM »
A better method would be to show the sizes in a Windows Explorer column, as discussed in this forum thread: Displaying PDF Page Size in Windows Explorer.

But, if you really want to go with the file rename method, you may use the rename tool, with the help of this script (also attached bellow).
Code: [Select]
function PageSize() {
    var Size = '';
    var Page = BatchFile.Pages(0);
    if (Page) Size = Page.Width.toFixed() + 'x' + Page.Height.toFixed() + ' mm';
    BatchFile.close();
    return Size;
}

Select all the files you want to rename and start the rename tool. Click the tool rename formula field right arrow and, from the menu that will show up, open the scripts editor, menu item "Scripts>Manage Scripts...". From this script editor main menu, import the bellow attached script (after unzipped) and close the editor (saving the changes).
You can now type [F]_[PageSize] in the tool rename formula field, to achieve the file name schema you are requesting.

Urraco

  • Guest
Re: rename page size file
« Reply #2 on: May 23, 2019, 10:32:41 AM »
Thank you for your prompt answer!
Apparently it works, but when I try to rename the file, I get this error: Unable to rename file - The process cannot access the file because it is being used by another process.
..and..can i get the "trim" page size format of pdf ?

Thanks and a good day!

RTT

  • Administrator
  • *****
  • Posts: 839
Re: rename page size file
« Reply #3 on: May 23, 2019, 03:14:47 PM »
Apparently it works, but when I try to rename the file, I get this error: Unable to rename file - The process cannot access the file because it is being used by another process.
My bad. I've update the above script to fix the issue.

..and..can i get the "trim" page size format of pdf ?
Do you mean the size of the PDF page trimbox, that reverts to the cropbox, or mediabox, if that box property is not defined?

Urraco

  • Guest
Re: rename page size file
« Reply #4 on: May 24, 2019, 07:38:41 AM »
Apparently it works, but when I try to rename the file, I get this error: Unable to rename file - The process cannot access the file because it is being used by another process.
My bad. I've update the above script to fix the issue.

..and..can i get the "trim" page size format of pdf ?
Do you mean the size of the PDF page trimbox, that reverts to the cropbox, or mediabox, if that box property is not defined?


I updated the script but still same error." Unable to rename..."
About format if you can, i want to get trimbox size of the pdf document and if does not contain trim size, return cropbox or mediabox size

Thanks



RTT

  • Administrator
  • *****
  • Posts: 839
Re: rename page size file
« Reply #5 on: May 25, 2019, 01:21:26 AM »
I updated the script but still same error." Unable to rename..."
It's working here, with the 3.3 version and Windows 10.
Did you deleted the the old one, from the list of scripts, before importing the updated script? If not, it's still using the old one, and the imported script ended named PageSize1.

Quote
About format if you can, i want to get trimbox size of the pdf document and if does not contain trim size, return cropbox or mediabox size

Check if this one works:
Code: [Select]
function PageTrimSize() {
    var Size = '';
    var Page = BatchFile.Pages(0);
    if (Page) {
        var box = Page.TrimBox ? Page.TrimBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        if (Page.Rotation == 90 || Page.Rotation == 270) {
            Size = GetDist_mm(box.top, box.bottom).toFixed() + 'x' + GetDist_mm(box.left, box.right).toFixed() + ' mm';
        } else {
            Size = GetDist_mm(box.left, box.right).toFixed() + 'x' + GetDist_mm(box.top, box.bottom).toFixed() + ' mm';
        }
    }
    BatchFile.close();
    return Size;
}

function GetDist_mm(x1, x2) {
    return Math.abs(x1 - x2) * 25.4 / 72
}

Type [F]_[PageTrimSize] in the tool rename formula field, to use this new script.


Urraco

  • Guest
Re: rename page size file
« Reply #6 on: May 28, 2019, 12:51:51 PM »
I updated the script but still same error." Unable to rename..."
It's working here, with the 3.3 version and Windows 10.
Did you deleted the the old one, from the list of scripts, before importing the updated script? If not, it's still using the old one, and the imported script ended named PageSize1.

Quote
About format if you can, i want to get trimbox size of the pdf document and if does not contain trim size, return cropbox or mediabox size

Check if this one works:
Code: [Select]
function PageTrimSize() {
    var Size = '';
    var Page = BatchFile.Pages(0);
    if (Page) {
        var box = Page.TrimBox ? Page.TrimBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        if (Page.Rotation == 90 || Page.Rotation == 270) {
            Size = GetDist_mm(box.top, box.bottom).toFixed() + 'x' + GetDist_mm(box.left, box.right).toFixed() + ' mm';
        } else {
            Size = GetDist_mm(box.left, box.right).toFixed() + 'x' + GetDist_mm(box.top, box.bottom).toFixed() + ' mm';
        }
    }
    BatchFile.close();
    return Size;
}

function GetDist_mm(x1, x2) {
    return Math.abs(x1 - x2) * 25.4 / 72
}

Type [F]_[PageTrimSize] in the tool rename formula field, to use this new script.



It works!
Thank for help, I appreciate it
Great software, I recommend.