Back
Nametags 2019-10-20

As part of my work, I organized a conference where multiple people got together to talk about the current state of the project we were working on. Some of the people invited did know everyone else, so I thought it would be a good idea to make some nametags for everybody. Because I know Fitz, who cares a lot about badges, I wanted to do something nice that fit most of the requirements, and would be easy for me to make.

Unfortunately, I couldn't find a simple tool that was easy to perform a kind of mail-merge; Inkscape was totally unhelpful, and I didn't really want to use AppleScript to do this. I realized what I really wanted was essentially HTML, so I made a template there. I left in certain markers (e.g. First Name, Last Name) so that I could replace those substrings with the real data.

So, I drafted a template. It looked like this:

First Name

Last Name

Pronoun

Username@

Office

My Awesome Conference

I'm no design expert, but I'm pretty proud of that. The final result even uses a neat little script to compare the scrollWidth to the offsetWidth of a line of text; if the former is larger than the latter, the script shrinks the font in that line, and keeps doing so until the text fits.

Next, I had to take the spreadsheet of attendance (generated from a Google Form) and apply each row to the template to generate a separate .html in order to manually tweak anything before printing. Rather than learn the Google Sheets API, I chose to export the sheet as a tab-delimited file and parse it in a short Python script. Why Python? I don't really remember. Maybe it just seemed easy? Anyway, the script just removes the templated bits and replaces them with the contents of a file, one line at a time, and creates the individual html files, named after the username.

Finally, I needed to print each of the files. Here, Mac OS X / Chrome was a big disappointment, because I couldn't just say: print these, please. Instead, I ended up writing a short js program using the chrome-remote-interface npm module to control Chrome and print each html file to PDF. This worked really well!

Lastly, I needed to take my 1-up pdfs and convert them to 2-up to save some paper, and that wasn't too hard, but took a bit of trying. I ended up using the pdfcrop and pdfnup tools (part of the pdfjam suite of tools) to create the final, collated PDF:

$ ls *.pdf | xargs -n 1 pdfcrop
$ pdfnup --nup 2x1 --paper letter --no-landscape --frame true --no-tidy --scale 1 *-crop.pdf -o all.pdf

Then, I could just preview what the nametags would look like, and print them out. Overall, it went well, and I was able to produce the nametags before the conference deadline.

The resulting code lives on github here.