Quick Tip: How to convert a pdf into an image file using ImageMagick

The other day I needed to convert a pdf document into an image file using ImageMagick and here are a few things I learned. Note: The following conversion examples were performed in the Linux terminal but ImageMagick is not limited to a Linux OS.

How to convert a single-page pdf into an image file:

convert file.pdf file.png

How to convert a multi-page pdf into multiple image files:
Note: The following command will output image files where the file names will following the pattern file_pg_#.png. e.g. file_pg_0.png, file_pg_1.png, etc.

convert file.pdf file_pg_%d.png

Additional options:

  • You can replace an alpha background with a white background using the parameters -background white and -alpha remove. See example below.
    convert -background white -alpha remove file.pdf file.png
  • You can change the density of an image (i.e. specify the dots per inch value) using the -density parameter. See example below.
    convert -density 300 file.pdf file.png

Want to learn more about ImageMagick? Check out their site here.


How to create symbolic links

Occasionally you will need to make a link to a file or directory in Linux. To create a symbolic link you will need to use the ln command, which will follow the form of;

ln -s <target> <link name>

Example: Assume you frequently use gnome-calculator and decide you want a link on your desktop so you can quickly start that application in the future. To accomplish this with a symbolic link you could do the following;

ln -s /usr/bin/gnome-calculator ~/Desktop/calculator

You can also update an old symbolic link by overwriting the link using the following command.

ln -sf /usr/bin/gnome-calculator ~/Desktop/calculator

or when linking to directories you will need to include an n option

ln -sfn /mydir/ linkname

Quick-Tip: Escaping special characters in MS-DOS

The other day I needed to make a batch file, and encountered the problem of having characters (specifically spaces and parentheses), which needed to be escaped in order for the batch file to run correctly in MS-DOS.

An example of this problem would be having the following line in a batch file:

Incorrect example: C:\Program Files (x86)\Program\executableFile.exe

This example would result in an error stating:

’C:\Program’ is not recognized as an internal or external command, operable program or batch file.

This error is caused by multiple special characters which were not escaped. To solve this problem a ‘^’ should be placed before all characters which need to be escaped (eg. spaces, parentheses, etc). See the correct example below:

Correct example: C:\Program^ Files^ ^(x86^)\Program\executableFile.exe

Quick Tip: Local Port Forwarding

Recently I needed to learn how to access a http resource from work from my home computer. Being relatively new to ssh, I was completely unaware I could forward a port and access the required resource form my home computer.

If you can ssh into your work server, you can perform local port forwarding using the following ssh command.


ssh <username>@<hostname> -L <localport>:<host>:<hostport>


ssh myusername@mypretendworkserver.com -L 8080:localhost:8057

The above example, forwards localhost:8057 from my work server’s to my home computer’s localhost:8080, giving me local access to a resource previously not accessible.

To learn more about local and remote port forwarding check out this website.

Tinting Your Hillshade in ArcMap

My posts have been noticeably absent of geomatics content, so today I’ll share a tutorial that I read on tinting a hillshade in ArcMap. The tutorial is available at the following ESRI Blog post. I’ve used this technique in the past, and it’s a great way to keep your base map crisp and colourful (crisp example), instead of the typical dull appearance produced when a semi-transparent DEM layer is placed over a hillshade (dull example).

The tutorial uses pansharpening to fuse a hillshade raster with a DEM that has had a colour ramp applied to it and broken in to RGB layers. It may take a few attempts to get the final result you want, but the result is an excellent way to make your base layer really stand out. Give it a try, you may be surprised how much your hillshade’s appearance is improved.

Quick-Tip – Netstat: Processes and Port Numbers

Earlier today I needed to kill a process that was occupying a specific port of a network. After a quick search online I learned from a website that Netstat can list listening sockets and provide the program PID’s which are using a specific port. The command to do this is as follows;

netstat -lp

This approach can be further refined if you know which port to look for, by piping a grep command afterwards with a specified port number;

netstat -lp | grep <port #>