Copy link to clipboard
Copied
Hello,
I have been working on a script that would change the ArtBox of the page but it does not seems to be working. Here is a sample script:
for (var o = 0; o<this.numPages; o++) {
var crBox = this.getPageBox('Bleed',o);
var trBox = this.getPageBox('Trim',o);
var rightBleed = [trBox[0], crBox[1], crBox[2], crBox[3]];
var leftBleed = [crBox[0], crBox[1], trBox[2], crBox[3]];
if ( o % 2 == 0 ) {
this.setPageBoxes({
cBox: 'Art',
nStart: o,
rBox: rightBleed
});
}
else {
this.setPageBoxes({
cBox: 'Art',
nStart: o,
rBox: leftBleed
});
}
}
The idea goes like this; for every odd page, set the ArtBox to BleedBox except the left side (use TrimBox instead). For even pages flip the sides. But it does nothing in return.
Strangely, if I replace the ArtBox with MediaBox like this:
for (var o = 0; o<this.numPages; o++) {
var crBox = this.getPageBox('Bleed',o);
var trBox = this.getPageBox('Trim',o);
var rightBleed = [trBox[0], crBox[1], crBox[2], crBox[3]];
var leftBleed = [crBox[0], crBox[1], trBox[2], crBox[3]];
if ( o % 2 == 0 ) {
this.setPageBoxes({
cBox: 'Media',
nStart: o,
rBox: rightBleed
});
}
else {
this.setPageBoxes({
cBox: 'Media',
nStart: o,
rBox: leftBleed
});
}
}
it suddenly works just fine. Any other change Crop, Bleed or Trim does not work either.
Can anyone provide an insight into this?
Why ArtBox? Well I have discovered that watermarks are dependant on it and ignore any other page box. At least that is the result of my testing.
I have created a test file for testing as well as a simple script that adds the same function with a menu item (under Edit) to run it (can't upload .js so I just change the extension to .txt).
Please, let me know if you know how to make it working. I am a beginner in javascript, so any advice or insight is appreciated.
Best Regards,
David
Copy link to clipboard
Copied
You have to do some math with difference between the boxes. Read these:
https://pdfautomationstation.substack.com/p/cropping-and-reverse-cropping-pdf
https://pdfautomationstation.substack.com/p/pdf-page-coordinates
Are you using a PDF page to add the watermark? You have might have to match the crop box to the BBox on the page you are using for the watermark.
Copy link to clipboard
Copied
Hello,
I have checked the links you provided and they are on point, thanks for posting them.
I revised the code a bit but to no avail. And then I checked the javascript console. I have a strange, unaccountable feeling that Acrobat is lying to me, right before my eyes. Let me explain.
I have opened the document I included in the original post. Checked the console with these commands and results:
this.getPageBox('Art',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Bleed',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Trim',0);
8.503936767578125,291.968994140625,221.1020050048828,8.503936767578125
this.getPageBox('Crop',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Media',0);
0,300.47198486328125,229.6060028076172,0
Here is a screenshot:
After that, I executed the script from the Menu Item and got these results:
this.getPageBox('Art',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Bleed',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Trim',0);
8.503936767578125,291.968994140625,221.1020050048828,8.503936767578125
this.getPageBox('Crop',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Media',0);
0,300.47198486328125,229.6060028076172,0
//After the script
this.getPageBox('Art',0);
8.503936767578125,300.47198486328125,229.6060028076172,0
this.getPageBox('Bleed',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Trim',0);
8.503936767578125,291.968994140625,221.1020050048828,8.503936767578125
this.getPageBox('Crop',0);
0,300.47198486328125,229.6060028076172,0
this.getPageBox('Media',0);
0,300.47198486328125,229.6060028076172,0
A proof of that:
Not only are the visual guides off (the red rectangle for the ArtBox should be on the green TrimBox on the left - according to the javascript console) but the Set Page Boxes tool in acrobat does not register this change either:
Do you know what is happening?
The script is obviously working; if I replace the ArtBox with CropBox inside the script, the change is apparent:
Therefore the problem must lie inside the Acrobat by itself.
Please, let me know if something relevant comes to your mind,
David
Copy link to clipboard
Copied
Your script is working. Here's how I tested the results:
1) Add a text field with some yellow fill color to every page and named the fields "Art0" through "Art11". (see Before Script attachment).
2) Ran your first script in the console (see After Script attachment).
3) Ran the following script in the console that adjusts all the fields on each page to the Art box coordinates on each page (see Fields Adjusted attachment):
for(var i=0;i<this.numPages;i++)
{
this.getField("Art"+i).rect=this.getPageBox("Art",i);
}
Copy link to clipboard
Copied
It is clearly changing some values, no doubt about that, but unfortunately the watermarks does not seem to respect the ArtBox edited via JavaScript.
I will post the whole code here in the attached file.
The script takes a document and impose it for sewn binding. I got it working using the CropBox. But this solution is not ideal. I do not want to change the appearance of the original document and the ArtBox is great for that (it is the only PageBox that do not influence the printing process and can be safely ignored if left as is after the script).
If I use the CropBox, everything works. The Artbox breaks things (you can test if by replacing the variable in the main function).
I have found a solution for the crop box in that the script extract the pages first and then replace the original pages (with edited CropBox) after the script is done. Also sets the dirty flag to false so the document appears as the original and do not require saving afterwards.
I may have found a solution in this simple case, but I plan on implementing more functions with a custom dialog window that would enable the user to impose the pages in more ways (Step & Repeat, N-Up pages, etc.) and I'm afraid that this solution might not work in other cases.
Thanks for your time and please let me know if something comes to your mind why the ArtBox does not work or if you have an alternative solution to the clean-up process after the script is done.
David