Open PDF to bounding box.

I have a series of pdf’s that have been generated that is essentially a 4x6 image on an 8.5x11 piece of paper. Because of limitations in the software, I cannot print directly to a 4x6" pdf. For my purposes, I need to utilize that 4x6 area exclusively (cropping out the remainder of the 8.5x11.

Unfortunately, the image is not centered on the page, otherwise, I would just have Image Events open the image and cropt to the dimensions, I need.

If you open the image in Image Events, Preview, or Adobe Reader, the image is always on an 8.5x11 image. HOWEVER, if you open the pdf file in Photoshop, you can open the image to the “Bounding Box” of the image. This renders the image out to the 4x6" image I require!

For a multitude of reasons, I would prefer not to have every one of these images rendered through Photoshop. Does anyone know of any AppleScript-able programs that will open a PDF with a “cropping to bounding box” option enabled?

Something like this might work. If you determine what box type is defining the edge of the content, you can set the crop box to that. This will give you all the values in one list.

tell application "Adobe Acrobat Professional"
	tell front document
		tell page 1
			set theCropBoxList to crop box
			set theBleedBoxList to bleed box
			set theArtBoxList to art box
			set theMediaBoxList to media box
			set theTrimBoxList to trim box
		end tell
	end tell
end tell

{theCropBoxList, theBleedBoxList, theArtBoxList, theMediaBoxList, theTrimBoxList}

This worked for a document I had but see what values you get in your document for the other box types:

tell application "Adobe Acrobat Professional"
	tell front document
		tell page 1
			set crop box to trim box
		end tell
	end tell
end tell

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Hmm… Thanks for the hint. It is strange.

It seems that Acrobat and Photoshop see the file differently.
The script returned the same results for all of the boxes… including the one that is in the dictionary marked obsolete called “bounds” - which are: {0.0, 792.0, 612.0, 0.0}

Yet, in Photoshop, if you select any of the media, trim, crop, art, or bleed boxes, you see this at the import screen.

However, if you select the bounding box option, you see this.

Edit: for those that are not sure - the thumbnails on those screen grabs illustrate a 4x6 image on an 8.5x11 and then with the bounding box option, it is simply showing that it would open the image right to the 4x6 portion of the image.

PS - Why are the image tags disabled???

What application were they generated with and what application do you need them in at the trimmed image in?

Generated out of Endicia for Mac… they will be going into a workflow that will put them 4 up on a 8.5x11 sheet of labels. They won’t necessarily be going into any other program - they will fit into our printing workflow accordingly if I simply have the cropped image.

Hmmm. It really looks like a PhotoShop solution would be the best and most easily scriptable.

But, you said you don’t want to do that so, does this crop your file to the right size in Acrobat:

tell application "Adobe Acrobat Professional"
	activate
	delay 2
	tell application "System Events"
		tell process "Acrobat"
			keystroke "t" using {command down, shift down}
			delay 2
			
			click checkbox "Remove White Margins" of group 1 of group 1 of window "Crop Pages"
			
			delay 1
			
			key code 36
			
		end tell
	end tell
end tell

Yes, that does work.

I was trying to avoid Photoshop primarily so that this process would not be required to run on a “production” machine. It is an office function and should be handled on a machine set-up for that environment. Ideally, I was trying to utilize something like “Image Events” and process them all in the background.

Scott:
What are you imposing these with? (And please don’t tell me the imposition is “an office function”!) :expressionless:

If you’re only using them for imposition you should be able to impose them by offsets easily and repeatably. What app are you importing them into?

Jim Neumann
BLUEFROG

I wasn’t planning on going into another app. I was going into a Hotfolder on the RIP… and unfortunately, I don’t believe the offsets are that friendly. I had checked before I started getting into this, but I will definately double check. Otherwise, if I was going to go to an InDesign or something, I could see using that. Again, it just seems like heavier lifting than necessary.

Oh… and it’s an office function. :wink:

InDesign does let you set which “box” to use on import. It sets the global setting, and through the GUI it’s kind of a hidden setting. I first learned this from http://macscripter.net/viewtopic.php?id=27093


tell application "Adobe InDesign CS3"
	set PDF crop of PDF place preferences to crop media -- content, art, PDF, trim, bleed, media are the options
end tell

I think “content” is the same as “bounding box” in the rasterize dialog box of photoshop, but not positive. Media box is the total size of the actual artwork. You could place it that way and then center or resize the boxes as necessary in InDesign.

This will set your global InDesign import preferences, however. Actually, any time you change it in the GUI, it retains it (really bad way of handling this btw) until you change it in the semi-hidden dialog. You could get the original setting, change it for your purposes, and then change it back using the code below, or just do what we do and make the default be what we use the most.


tell application "Adobe InDesign CS3"
	set userCrop to PDF crop of PDF place preferences -- get the user's current settings for safekeeping
	set PDF crop of PDF place preferences to crop media  -- content, art, PDF, trim, bleed, media

	-- Do the actual placing

	set PDF crop of PDF place preferences to userCrop -- set the user's orignal setting back
end tell

This all assumes you count InDesign an office function, that is…

(Don’t get me started on Abobe’s proliferation of boxes in PDFs…)

Why don’t you set up a custom page size to choose when exporting the PDF from the mail app? This looks like an ongoing problem, so it would be best to set up a more streamlined workflow and eliminate the problem a the same time.

Thanks guys.

First off, the “office functionality” is starting to get blown out of proportion. But from my company’s perspective, order entry, accounting, shipping, and customer service functions, require a certain employee skill-set as well as a certain software arsenal. It seems kind of silly to me that those people would need anything as robust as the Adobe Creative Suite on their machines.

Secondly, I would love to simply set the page size to 4x6 and print the pdf - and I would have done that had it been available. (I can be pretty aloof sometimes, but I usually exhaust such options before attempting to find an AS solution). The “Endicia for Mac” application has certain restrictions in the software, and unfortunately, that is one of them. In order to print to PDF rather than straight to a label printer, the only page layout available is a 4x6 on an 8.5x11 layout.

For the short term, I will consider the inDesign route. Hopefully, down the road, I can convince Endicia to allow the laser writer to print straight to a 4x6.

I have the pdf dropping in the way I want in inDesign - but now I need to center the pdf and fit proportionally to the rectangle. My properties line does not seem to do anything. Can someone correct my syntax, please.

set theFile to "path:to:pdf.pdf"

tell application "Adobe InDesign CS3"
	tell document 1
		place theFile as alias on rectangle "Box3" of page 1 with properties {fitting on empty frame:proportionally, fitting alignment:"center anchor"}
	end tell
end tell

hmmm… not sure why the properties tag wouldn’t work - but, this is how I got around that.

set theFile to "path:to:pdf.pdf"

tell application "Adobe InDesign CS3"
	tell document 1
		place theFile as alias on rectangle "Box4" of page 1
		
		tell every rectangle
			fit given proportionally
			fit given center content
		end tell
	end tell
end tell

I did a quick search, and another option might be found at http://macscripter.net/viewtopic.php?id=24706. There’s evidently a free program called iMagine Photo - that apparently works like Image Events, but allows you to crop off-center. I don’t know anything about it though. If it works, it might save you from needing to use InDesign, and could be more of an “in the background” process. It’s kinda crazy if you ask me that Image Events is limited to only center cropping.

Edit: actually, here’s a better link - the cropping is part of iMagine Photo’s import funtion: http://www.yvs.eu.com/documentation/importinggraphic.html

I considered imaginePhoto. But the author is a member here and considering that his signature line is “iMagine Photo is deprecated. I would not use it for any new projects.” - it makes me a tad leery to being using it. However, he has also stated

In the meantime, this is what I have come up with to drop the label files into a 4-up layout in inDesign. The master pages have the rectangles defined and have script labels attribtued to them.

--define the files we need to print
set theFolder to choose folder
set folderList to list folder theFolder without invisibles
set folderListCount to the count of items in folderList

--define page information for InDesign - starting page and number of pages for the document.
set myPage to 1
set numPages to (folderListCount / 4) round rounding up

--create the labels
repeat with x from 1 to folderListCount by 4
	--get the 4 files for this page.
	set theFile1 to (theFolder & (item x of folderList)) as string
	try
		set theFile2 to (theFolder & (item (x + 1)) of folderList) as string
	on error
		set theFile2 to ""
	end try
	try
		set theFile3 to (theFolder & (item (x + 2)) of folderList) as string
	on error
		set theFile3 to ""
	end try
	try
		set theFile4 to (theFolder & (item (x + 3)) of folderList) as string
	on error
		set theFile4 to ""
	end try
	
	--Place the Labels
	tell application "Adobe InDesign CS3"
		tell document 1
			override master page items of page myPage destination page page myPage
			
			place theFile1 as alias on rectangle "Box1" of page myPage
			if theFile2 ≠ "" then place theFile2 as alias on rectangle "Box2" of page myPage
			if theFile3 ≠ "" then place theFile3 as alias on rectangle "Box3" of page myPage
			if theFile4 ≠ "" then place theFile4 as alias on rectangle "Box4" of page myPage
			
			--make new page if necessary
			if (myPage + 1) is not greater than numPages then
				make new page
				set myPage to (myPage + 1)
			end if
		end tell
	end tell
end repeat

--center fit all of the labels
tell application "Adobe InDesign CS3"
	tell document 1
		tell every rectangle
			fit given proportionally
			fit given center content
		end tell
	end tell
end tell

I’m reprising an old topic.

Quick review so that you don’t have to read the entire thread. I am currently restricted in Endicia for Mac to either print directly to a thermal printer, or to a regular print driver on an 8.5x11 sheet exclusively. In an effort to improve workflow, I can print the 8.x5x11 directly to a PDF. The 4x6 image is positioned on the page like this.

Originally, my intention was to get the images 4 up on an 8.5x11 sheet. My InDesign solution worked fine for that. Now, however, I need to get the 4x6 image into a FileMaker container field, so I am back to figuring out how to crop the image to 4x6.

Has anyone used Image Magick to crop files? I have no experience with the application.

Hi Scott,

Back then when I needed a solution to silently crop images in the background for a window screenshot utility, I wrote myself a small command line utility, which might be of some help for you.

I called it croppic and you can download it here (this is the source code).

From AppleScript, you can call it like follows to crop an image:


-- path to the croppic tool
set toolpath to "Macintosh HD:Users:martin:Desktop:croppic"
set qtdtoolpath to quoted form of POSIX path of toolpath

-- input image path
set origimgfilepath to "Macintosh HD:Users:martin:Desktop:original.jpg"
set qtdorigimgfilepath to quoted form of POSIX path of origimgfilepath

-- output image path
set cropimgfilepath to "Macintosh HD:Users:martin:Desktop:cropped.jpg"
set qtdcropimgfilepath to quoted form of POSIX path of cropimgfilepath

-- this command will stamp out a rectangular with a width and height of
-- 350 pixels from the original image, starting at the x/y coordinates 50/50
-- the save format will be jpg (other possible values: png/tiff)
set command to qtdtoolpath & " -h 350 -w 350 -x 50 -y 50 -f jpg -i " & qtdorigimgfilepath & " -o " & qtdcropimgfilepath
do shell script command

Maybe you can also make good use of it.

Best regards,

Martin

Oh my, that looks pretty!

I’ll download and check it out now.