Skip to main content
GordonPrince
Participating Frequently
April 16, 2019
Answered

check pdf document size

  • April 16, 2019
  • 5 replies
  • 5261 views

I'm working with VBA and Acrobat. I want to examine a .pdf file to see if it's 8.5x11" in size. If it's not that size, I'd like to change it to be that size (or create a copy of the document that is 8.5x11" in size). Most of the documents are only one page long.

Any suggestions on the best way to do this without requiring any interaction from the user?

Thanks.

This topic has been closed for replies.
Correct answer try67

I'm pretty sure of that. And I'm willing to test that first. I.e.,

1. check to see if the document is only one page long (I know how to do that from VBA using the IAC (interapplication communication). If it's not, pop up a message to the user that they have to do something manually.

2. check to see if the one page document is 8.5x11". If not, pop up a message to the user.

If everything is one page, 8.5x11", I'm good.

If there are a lot of exceptions, I'll come up with something that deals with that.


You can use this code to achieve it:

if (this.numPages>1) app.alert("This file has more than one page!");

else {

    var cropBox = this.getPageBox("Crop", 0);

    var pageWidth = cropBox[2]-cropBox[0];

    var pageHeight = cropBox[1]-cropBox[3];

    if (pageWidth!=612 && pageHeight!=792) app.alert("The dimensions of this page are not 8.5\" x 11\".");  

}

I used the Crop box, as it's the default one, but you can change it to something else, or test multiple boxes, if you wish.

5 replies

Legend
April 17, 2019

JavaScript can inspect the page size of each page. Consider carefully what you mean by page size - crop box or media box? Follow page rotation or no?

GordonPrince
Participating Frequently
April 17, 2019

When I say page size, I mean what displays when in the bottom left corner of an Acrobat document (sometimes requires a hover, sometimes it displays on the status line of the document). But I'm willing to use the correct term, if there's a better term for this.

GordonPrince
Participating Frequently
April 17, 2019

So back to the first part of my original question:  before I try to "resize" the document in question, is there a way to tell whether it's already at an 8.5x11" size? It's possible virtually all of my documents are already the right size, and I'll only need to pop up a message to the user that they need to fix the occasional document.

try67
Community Expert
Community Expert
April 17, 2019

Are your documents all just one page?

GordonPrince
Participating Frequently
April 17, 2019

I'm pretty sure of that. And I'm willing to test that first. I.e.,

1. check to see if the document is only one page long (I know how to do that from VBA using the IAC (interapplication communication). If it's not, pop up a message to the user that they have to do something manually.

2. check to see if the one page document is 8.5x11". If not, pop up a message to the user.

If everything is one page, 8.5x11", I'm good.

If there are a lot of exceptions, I'll come up with something that deals with that.

Legend
April 16, 2019

Oh, yes. Can it be automated?

try67
Community Expert
Community Expert
April 16, 2019

You can use JS to run a Preflight Profile, but I'm not sure whether it will prompt you for the page size to use in each run, or if it can be defined in the profile's properties.

Legend
April 16, 2019

Distiller has a watched folder feature. The only acceptable input is PostScript. However... Using print-to-PDF to resize is considered a desperate last resort as it often loses features, quality, and information. However... Acrobat doesn't offer any neat "scale to resize" feature otherwise.

try67
Community Expert
Community Expert
April 16, 2019

Why not? The Preflight tool of Acrobat DC/2019 has a Scale Pages command, I believe.

GordonPrince
Participating Frequently
April 16, 2019

For another project I created a JavaScript function that does this. But it requires installing the .js file on the user's computer, which I was hoping to avoid. Maybe that's the only way to do this, still. I only have 10 users using this, so it's not too burdensome.

Legend
April 16, 2019

How do you plan to change the size? Please be specific about what you would do in the user interface to change the size.

GordonPrince
Participating Frequently
April 16, 2019

Currently we copy the file to a Distiller folder. It gets picked up from the "input" folder, converted to a new file and put into the "output" folder. But this requires the user to configure their Distiller correctly, and I'm trying to get away from that. If there was a way to force Distiller to listen to a specific folder, without the user turning that on, I could do that. However, this might result in unnecessary processing if the original file was already 8.5x11" in size.

Or people sometimes print to their Acrobat PDF printer using 8.5x11" output settings.