How do I automatically print only part of a PDF page in OS X?

4

I frequently have to crop out the top half of a PDF (it's a shipping label) and only print that on A4 paper, instead of the whole label.

I can do this very easily with Adobe Acrobat Pro, by opening the file, then going to Edit Text & Images, then manually removing all I don't need, and finally printing through OS X' system dialog. However, that's a little cumbersome when I have multiple files.

Can I somehow automate this on OS X, by using Automator or any command-line script?

slhck

Posted 2015-01-02T15:09:10.763

Reputation: 182 472

Answers

7

If it is only for the occasional "print only top half" on OS X, you actually do not need to install anything.

  1. Open the PDF in Preview.app (which likely is the default PDF viewer on your system anyway).

  2. From the application's menu, make sure that 'Tools -> Rectangular Selection' is active.

  3. Use mouse pointer to select that half (or other part of page) you want to print (or export to PDF).

    Screenshot shows the original file with the selection

  4. From application menu, select 'File -> New from Clipboard' (or use appropriate keyboard shortcut).

  5. A new window titled "Unknown" opens. It contains your rectangular selection. Print it or export to PDF.

  6. When printing, you can 'Scale', 'Scale to Fit' and/or 'Autorotate' as you please.

    Print dialog showing preview of selected part only

  7. There is no need to save the "Unknown" file, if you do not want.


As you may have noticed, I demoed my method not with a PDF. Because this method works for any file which Preview.app can open and display. It also works for PDFs, of course. I know you have asked for some automated way to do this, and this isn't it. But it avoids the heavy guns of Adobe Acrobat Pro, which is not required when doing it manually on occasions only.

Kurt Pfeifle

Posted 2015-01-02T15:09:10.763

Reputation: 10 024

But the problem is really that I need the top half only, printed on the top half of the paper. Cutting only will not achieve that. – slhck – 2015-01-05T22:29:21.500

6

Here are the steps:

  • Install Homebrew. Make sure to follow all instructions on the command line.

  • Install ImageMagick with brew install imagemagick.

  • Open Automator.app, then create a new Print Plugin.

  • Drag Run Shell Script from the left pane to the right.

  • Select Pass Input: as arguments and paste the following code:

    # Crop off the top half of a PDF and print it
    CROP_PERCENT=50                 # top percent to keep
    DENSITY=600                     # DPI density for PDF reading
    OUTPUT_SIZE="28x21cm"           # Output page size, e.g. 28x21cm is A4
    TMP_OUTPUT="/tmp/cropped.png"   # Output tmp file
    
    convert -density "$DENSITY" "$1" -crop 100x${CROP_PERCENT}%+0+0 -gravity North -extent "$OUTPUT_SIZE" "$TMP_OUTPUT"
    
    echo "$TMP_OUTPUT"
    
  • Drag Print Finder Items from the left pane to the right.

It should look like this:

Save it under any name you want, e.g. Print Top Half, and now you can access it from any print dialog:

slhck

Posted 2015-01-02T15:09:10.763

Reputation: 182 472

1

You actually don't have to bother with contents. All you need to do is cropping the page.

Another possibility would be creating a custom paper format corresponding to A5 landscape (probably what the packaging label is about).

You do that in the printer driver dialog, just ignoring the Acrobat complaint that you will leave now the Acrobat print dialog and end up at the printer's dialog. There you create the new format, and save it; or if you already have it, select it. Confirm, and you get back to the Acrobat Print dialog. There deactivate automatic rotating and centering, and this new page size will be active. Verify that it is correct in the little preview thumbnail. If OK, you can print.

The settings in the Acrobat print dialog are persistent, which mean that they will be remembered the next time you use the dialog.

You can now, of course assemble an Action using the Action wizard.

You might also look at the printParams (Acrobat) JavaScript object, whether it is sufficient for your needs; if so, you could create an app-level JavaScript with a menu item, and run it whenever it is needed.

Finally, you could also use AppleScript with System Events to fully control the Acrobat Print dialog AND the printer's print dialog. This Applescript can then be made into a Droplet.

So, there are many options, all available with on-board means.

Max Wyss

Posted 2015-01-02T15:09:10.763

Reputation: 1 481

Great ideas, thanks. I chose the somewhat hacky method. Choosing A5 and setting landscape as paper format works quite well, but it still requires me to open the program and do a few clicks in the dialogs. Especially when changing between printing formats, this is a little annoying. What specifically do you mean by assembling an Action? Can I do more there than just printing the document? I don't see a way to specify print options. (When I click "Specify Settings", I get "The Print tool uses the settings in Acrobat's Print dialog.") – slhck – 2015-01-02T15:42:58.837

@slhck: With "assembling an action", I mean using the Action Wizard (which may be not visible in the Tools panel; if it is not click on the very discreet icon in the upper right corner of the Tools panel, and activate the Action pane. However, by thinking over it again, it may not work because the Actions are within Acrobat and don't reach out to the printer's print dialog. It might be necessary to create a copy of the printer, and remove all the paper sizes except the horizontal A5. …or move on with the Applescript approach. – Max Wyss – 2015-01-02T16:41:02.087

Yeah, I think that's the issue with Action Wizard. But I was now able to make it a simple Print Plugin for Automator. I'll remember the trick with A5 Landscape. – slhck – 2015-01-02T18:30:40.133

Automator is an approach too. And if it does what you want it to do, then why worry… – Max Wyss – 2015-01-02T18:39:50.860