Automatic PDF calendar generation with pcal
During the Nepal earthquake response project I worked on, we were gradually getting access to historical mobile phone data for use in our analyses. I wanted to keep track of which days of data we had got access to, and which ones we were still waiting for.
I wrote a simple script to print out a list of days that we had data for – but that isn’t very easy to interpret. Far easier would be a calendar with days highlighted. I thought this would be very difficult to generate – but then I found the pcal utility, which makes it easy to produce something like this:I’m not going to go into huge detail here, as the pcal man page is very comprehensive – and pcal can do far more than I show here. However, to create an output like the one shown above you’ll need to put together a list of dates in a text file. Here’s what my dates.txt file looks like:
01/05/2018* 03/05/2018* 05/05/2018* 09/05/2018* ...
It is simply a list of dates (in dd/mm/yyyy format), each followed by an asterisk and a newline.
Then, to create the calendar, install pcal (on Linux it should be available via your package manager, on OS X it is available through brew) and run it like this:
pcal -E -s 1.0:0.0:0.0 -n /18 -b sat-sun -f dates.txt 5 2018 1 > calendar.ps
The arguments do the following:
- -E configures pcal to use European-style dates (dd/mm/yyyy)
- -s 1.0:0.0:0.0 sets up the highlighting colour in R:G:B format, in this case, pure red
- -n /18 sets the font (in this case the default, so blank) and the font size (the /18 bit)
- -b sat-sun stops Saturday and Sunday being highlighted, which is the default
- -f dates.txt takes a list of dates from dates.txt
- 5 2018 1 tells pcal to produce a calendar starting on the 5th month (May) of 2018, and running for one month. 5 2018 6 would do the same, but producing 6 separate pages with one month per page
This produces a postscript file, which can be opened directly on many systems (eg. on OS X it opens by default in Preview) or can be converted to pdf using the ps2pdf tool.
There are loads of other options for pcal – one handy one is -w which switches to a year-per-page layout, handy for getting an overview of data availability across a whole year:
If you found this post useful, please consider buying me a coffee.
This post originally appeared on Robin's Blog.
Categorised as: Computing, Linux, OSX, Programming, Windows
[…] Automatic PDF calendar generation with pcal […]