Using variables in a property - The TrimBox example
The file above has a MediaBox and a TrimBox and our goal is to find whether the TrimBox lies in the center of the MediaBox. Well, there is a Property (which could be used in a Check) in pdfToolbox named 'TrimBox is centered inside MediaBox'. This will check the location of the TrimBox inside the MediaBox, but without any tolerance. That means, if the TrimBox is located in the exact center, hence not off by even a point, the Check is a success. Also the distances between MediaBox and TrimBox in horizontal and vertical direction must be identical.
To understand the center, the distance between the TrimBox and the MediaBox on the left and right side of the page (similarly for the top and bottom) has to be equal. Fortunately, there is a condition in pdfToolbox to check the in-between distance on the left hand side named 'Horizontal offset of TrimBox from MediaBox'.
Condition == Distance on the left
And for our requirement, the 'Distance on the left' has to be equal to the 'Distance on the right.'
We start by making a new Check, 'TrimBox not centered inside MediaBox' with a custom check including 2 properties:
Very simple. The script here is calculating the distance between the MediaBox and the TrimBox on the right. (Another script for the vertical distance is not shown here in this example, but it has the same basis)
PLEASE NOTE: This Profile will work brilliantly on a one page file or a file which has the same distance between the two boxes on the right side of the first page and the left side of all the pages.
You can very well notice that the script is picking up the right hand side value only from the first page. Have a look at this:
In case the pages in your file have different MediaBox dimensions on different pages, the script has to be a bit more complicated.
The process plan with loops has 4 parts:
1. A variable to check that the page that we are looking at is page 1.
2. A check for horizontal offset (to calculate the distance between the boxes on the right side for each page individually) for the current page: screenshot below.
3. A check for vertical offset (to calculate the distance between the boxes on the top side for each page individually) for the current page.
4. A variable to increase the page number by 1, continuing with step 2 (if the page number is lower than or equal to the last page) or to end the loop when it is on the last page.
The process plan with loops includes 4 sequences:
- A Variable that checks that the page we are looking at is page 1.
- A Check on the current page for horizontal offset (to calculate the distance between the frames on the right for each page individually); see figure below.
- A Check on the current page for vertical offset (to calculate the distance between the frames above for each page individually).
- A Variable to increase the page number from step 2 by 1 (if the page number is lower than or equal to the last page) or to end the loop with the last page.
The screenshot above shows the Check for the point 2 of the above Process Plan (The Check for point 3 will be similar, hence not shown here).
The above Check contains 2 Scripts (mentioned by numbers and shown below)