How to remove the first or last page of a .pdf using a Mac

I needed to remove the first and last pages of a hold lot of .pdf files on a Mac. It wasn’t that easy to find solutions and so I thought I would document the process:

1 – Install pdftk server which rather helpfully has a Mac installer:

https://www.pdflabs.com/tools/pdftk-server/

Run the commands
To remove the first page of all the .pdf files in a directory use this command:

for i in *pdf ; do pdftk $i cat 2-end output output/$i ; done

To remove the last page of all the .pdf files in a folder use this command:

for i in *pdf ; do pdftk $i cat 1-r2 output trimmed/$i ; done

Hope this helps someone.

How to split a .pdf every 2 pages using Python

I’ve just scanned in some old copies of Trail walking magazine. I had around 150 .pdf files in a directors and needed to break the split them every two pages. I thought my python script might be useful to someone. It used pypdf which you easierly install using:

pip install pypdf

The script is as follows:


#!/usr/bin/env python

from pyPdf import PdfFileWriter, PdfFileReader
import glob
import sys

pdfs = glob.glob("*.pdf")

for pdf in pdfs:

    inputpdf = PdfFileReader(file(pdf, "rb"))

    for i in range(inputpdf.numPages // 2):
        
        output = PdfFileWriter()
        output.addPage(inputpdf.getPage(i * 2))

        if i * 2 + 1 <  inputpdf.numPages:
            output.addPage(inputpdf.getPage(i * 2 + 1))

        newname = pdf[:7] + "-" + str(i) + ".pdf"

        outputStream = file(newname, "wb")
        output.write(outputStream)
        outputStream.close()

I hope this helps someone.

How Install HP Support Package On Ubuntu 14.04

I need to install HP support package on Ubuntu Trust / 14.04.

Add the following line to:

sudo nano /etc/apt/sources.list.d/hp-proliant-support-pack.list

Add the following line:

deb http://downloads.linux.hp.com/SDR/downloads/MCP/ubuntu trusty current/non-free

Update the apt-get cache:

sudo apt-get update

You can see the list of packaging in this repository by using this command:

grep ^Package: /var/lib/apt/lists/downloads.linux.hp.com*

Hope this helps someone.

How To Connect To A MacBook With A Broken Screen

My wife accidentally dropped her Macbook Pro off the sofa and broke the screen. Amazingly the computer was still running but she could no longer interact with it because the screen was completely blank. She was just finishing some work and didn’t have a backup. I think that the best thing to do in this scenario is remotely connect to the computer and rescue it. I don’t recommend restarting the computer because there is always a chance that it won’t come back up. You will need another working computers (preferably a Mac) to follow these instructions.

Here is how I did this:

1 – Open The Terminal On Broken Computer
Although, you can’t see the screen, you will need to open the terminal. You can open the terminal using the shortcut: command-space and typing terminal and pressing enter.

2 – Allow ssh connections
On the broken computer, you will need enable SSH. This requires some accurate typing because again you can’t see what you are typing. You need to enter this command (from within the terminal that you have just launched).

sudo systemsetup -setremotelogin on

3 – Find the computer’s IP Address
Using another computer, you will need to find the IP Address of your broken computer. The best way is to connect to your router and view the DHCP leases table. I can’t provide instructions for this stage because it varies so much between different routers. Here is how my Virgin router’s DHCP lease / reservation tables looked. I’ve covered over the mac addresses for privacy.

DHCP Lease Reservations

You can see the entry at the bottom shows a computer with an IP Address of 192.168.0.8. This was my wifes Macbook.

4 – SSH into the Macbook
From your working computer – you should then be able to SSH into the broken computer by opening the terminal.

ssh username@ipaddress

5 – Enable remote desktop
You should now be connected over SSH to the broken computer and should be able to enable remote desktop. This varies depending on the version of OSX that you are using. You can see full instructions on the Apple website. This is the command that I used:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -al

6 – Connect Via Remote Desktop
You should now be able to connect the broken computer via remote desktop. The best tool that I’ve found for this job is Easy Remote Desktop. You open it and enter the IP address of the broken computer:

easy-remote-desktop

And voila…. you are connected to the computer…

I hope that this helps someone.