RTTSoftware Support Forum

PDF-ShellTools => General => Topic started by: Nick Riviera on April 29, 2021, 09:35:16 AM

Title: trim + bleed size
Post by: Nick Riviera on April 29, 2021, 09:35:16 AM
Hi,

I have this script (from RTT) which adds in the file name the  trim box size  ex "test_210x297 mm.pdf"

In this script can be added also the bleed size? ex "test_210x297 mm + 10 mm bleed.pdf".
If there is no bleed in the document then  "test_210x297 mm + 0 mm bleed.pdf"

Thanks a lot

Code: [Select]
function TS() {
   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
}
Title: Re: trim + bleed size
Post by: RTT on April 30, 2021, 04:22:14 AM
The bleed box, as all the other page boundary boxes in PDF (crop, trim, etc) is a rectangle defined by 4 corners coordinates. I suppose the bleed size you want to know is the difference between the trim and bleed boxes? Because these are rectangles, it may result in 4 different values, i.e. left, top, right and bottom bleed sizes. Do you want all the 4, just the maximum, or this is just a scenario not happening with your PDFs?
Title: Re: trim + bleed size
Post by: Nick Riviera on May 04, 2021, 07:27:10 AM
I suppose the bleed size you want to know is the difference between the trim and bleed boxes?

that's exactly  I want
I work only on pdf documents whit bleed equal for all sides,
so I  need the bleed size  for only one side

I think.. something like that (bleedbox - trimbox) / 2"


Thanks for help!
Title: Re: trim + bleed size
Post by: RTT on May 05, 2021, 01:50:06 AM
From the renamer tool (https://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/Renamer.htm) scripts editor, import the attached script or manually create a new script, name it BleedSize and paste the next code into the script content.
Code: [Select]
function BleedSize() {
    var Size = '';
    var Page = BatchFile.Pages(0);
    if (Page) {
        var TrimBox = Page.TrimBox ? Page.TrimBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        var BleedBox = Page.BleedBox ? Page.BleedBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        Size = GetDist_mm(BleedBox.top, TrimBox.top).toFixed() + ' mm';
    }
    BatchFile.close();
    return Size;
}

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

Rename expression:
[F]_[TS] + [BleedSize] bleed

 
Title: Re: trim + bleed size
Post by: nightslayer23 on July 05, 2021, 01:50:22 AM
This is a handy Script! Could it be tweaked to instead of adding the bleed or trim box size to the filename, but add it to a custom handle in explorer?

TRIM BOX
BLEED BOX
ART BOX

All go to their own respective Property Handler ? (no filename change)
Title: Re: trim + bleed size
Post by: RTT on July 13, 2021, 05:46:27 AM
As with the Displaying PDF Page Size in Windows Explorer example (https://www.rttsoftware.com/forum/index.php/topic,507.msg1393.html#msg1393), use the manager to create the 3 custom properties, named ArtSize, TrimSize and BleedSize.
Import and run the attached script to calculate and fill these properties, before they can show in the respective Windows File Explorer columns.
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);
    var TrimSize = '';
    var BleedSize = '';
    var ArtSize = '';
    if (Page) {
        var TrimBox = Page.TrimBox ? Page.TrimBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        var BleedBox = Page.BleedBox ? Page.BleedBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        var ArtBox = Page.ArtBox ? Page.ArtBox : Page.CropBox ? Page.CropBox : Page.MediaBox;

        if (Page.Rotation == 90 || Page.Rotation == 270) {
            TrimSize = GetDist_mm(TrimBox.top, TrimBox.bottom).toFixed() + 'x' + GetDist_mm(TrimBox.left, TrimBox.right).toFixed() + ' mm';
            ArtSize = GetDist_mm(ArtBox.top, ArtBox.bottom).toFixed() + 'x' + GetDist_mm(ArtBox.left, ArtBox.right).toFixed() + ' mm';
        } else {
            TrimSize = GetDist_mm(TrimBox.left, TrimBox.right).toFixed() + 'x' + GetDist_mm(TrimBox.top, TrimBox.bottom).toFixed() + ' mm';
            ArtSize = GetDist_mm(ArtBox.left, ArtBox.right).toFixed() + 'x' + GetDist_mm(ArtBox.top, ArtBox.bottom).toFixed() + ' mm';
        }

        var BleedSize = GetDist_mm(BleedBox.top, TrimBox.top).toFixed() + ' mm';

        var FileMetadata = file.Metadata;
        var Changed = false;
        if (FileMetadata.TrimSize !== TrimSize) {
            FileMetadata.TrimSize = TrimSize;
            Changed = true;
        }

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

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

        if (Changed) {
            if (FileMetadata.CommitChanges()) {
                pdfe.echo(file.Filename + ' : (ArtSize=' + ArtSize + ', TrimSize=' + TrimSize + ', BleedSize=' + BleedSize + ') [OK]');

            } else {
                pdfe.echo(file.Filename + ' [commit failed]', 0xFF0000);
            }
        } else {
            pdfe.echo(file.Filename + ' : (ArtSize=' + ArtSize + ', TrimSize=' + TrimSize + ', BleedSize=' + BleedSize + ') [properties already set]');
        }
    }
}
pdfe.echo("Done");

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