remove white margin with javascript

I want to delete all white margin from a document.
With GUI (Acrobat XI) I do:
-> Tools -> Print production -> Set Page Boxes -> (Margin Controls) Apply to: CropBox and check "Remove White Margins"

How I can do this with JavaScript?
I´ve tried to read the values with:
Media = this.getPageBox("Media");
and to set with:
this.setPageBoxes("Media", 0, 0, Media);

BUT I do not get the "right Boundingbox"-values with "getPageBox"?
Do someone have an idea?

Thanks
Eugen


Eugen Daubert


10 Answers

Voted Best Answer

This function is not available in JavaScript.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


By Gilad D (try67)   

Is there a another way?
How do acrobat "read out" the value of the "end of text" from each site?


Eugen Daubert   

Acrobat has access to the underlying structure of the PDF and knows where all the objects are located, so it can calculate in which areas there are no objects. JS has no such access.

The closest you can get with JS is to calculate the area where there is no more text, but you can't know if there are other objects (images, graphic elements) in that area.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

Thank you for you help!

ah. ok. - so I have to find another way to crop the PDF... ;-(

for history:
I am looking for a way to crop the white margin from this pdf

to get this:



Eugen Daubert   

Why do you need to do it with JS, though?

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

I have a lot of diagramms like this (and get them from our productmanagment) - so I´ve created an automatically process ( with VB -> JS)

This diagrams came from excel.
Then I print them (over VB) from excel to PDF.
And now I want to "crop" them.

I´ve also try to crop them with ghostscript (and then convert back to PDF) but sometimes ghostscript does not create the boundingbox correcty (= keept the border there - so there are still there in PDF)
So my idea was to crop the PDF at the biginning.... - in acrobat


Eugen Daubert   

If you have Acrobat Pro then you can do it in an Action and process all of your files at once.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

I have the Pro-version.
Can I then execute this action from JS?
Or create a menuitem (which exec the action) and then exec the menuitem from JS?


Eugen Daubert   

The "getPageBox()" method can get one box that you cannot set: The Bbox - that's the bounding box, and it may be all you need. Try getting the BBox, and then setting the CropBox to the size returned by BBox. If that works depends on the PDF file and how it was generated. You may also want to take a look at the ArtBox. Some PDF generators set the ArtBox to just the contents of the page (and therefore do not include the white margins).

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer   

That it the solutioin:

1 : create a VB-Script (.vbs) (see also doku):
Set gPDDoc = CreateObject("AcroExch.PDDoc")
gPDDoc.Open(FileName)
Set jso = gPDDoc.GetJSObject
jso.CropPage FileName
jso.saveAsEPS FileName

2: Create an new JS-file in folder "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Javascripts" - all JS-files will be read when Acrobat is starting:
3: write this in the JS-file

function CropPage(FileName)
{
console.clear();
console.show();

Media = this.getPageBox("Media");
this.setPageBoxes("Media", 0, 0, Media);

Crop = this.getPageBox("Crop");
this.setPageBoxes("Crop", 0, 0, Crop);

Trim = this.getPageBox("Trim");
this.setPageBoxes("Trim", 0, 0, Trim);

BBox = this.getPageBox("BBox");
this.setPageBoxes("Crop", 0, 0, BBox);

Bleed = this.getPageBox("Bleed");
this.setPageBoxes("Bleed", 0, 0, Bleed);
}

function saveAsEPS (FileName)
{
console.clear();
console.show();

this.saveAs(FileName + ".eps", "com.adobe.acrobat.eps");
this.closeDoc(true);
}


THANK YOU SO MUCH!

Eugen


Eugen Daubert   


Please specify a reason: