Taxes on Linux
Taxes have always been an annoyance, at least here in America where the tax code is as long as your intestine (and just as convoluted!). But taxes are extra annoying on Linux due to the scarce availability of tax prep software on the platform. When I first started doing my taxes, I copped out and used a version of Turbo Tax on a Windows virtual machine I had (my parents had TurboTax already, so it was just a matter of installing it). But that year, I resolved to make taxes work on Linux.
Given that my taxes are generally fairly simple (I'm a graduate student...generally it's just a W-2 and 1099-INT), the biggest hurdle I faced was finding a way to (easily) fill in the PDF forms. Enter pdftk.
pdftk is a fantastic piece of software for many reasons. In this case, though, it's particularly useful because of two commands: dumpdatafields and fill_form. You might be able to see where this is going.
I wrote up the following (very simple) script to help make my life a bit easier:
#!/bin/bash
FILES=( find -iname '*.pdf' | grep -v -- '-filled' | tr ' ' '&' )
case “$1” in
prepare)
for i in ${FILES[@]}
do
FILE=${i//&/ }
FIELDS=${FILE%.pdf}.fields
FDF=${FILE%.pdf}.fdf
pdftk “$FILE” dumpdatafieldsutf8 output “$FIELDS”
if [ ! -e “$FDF” ]
then
echo -e '%FDF-1.2\n1 0 obj<> >>\nendobj\ntrailer\n<>\n%%EOF' > “$FDF”
fi
done
;;
fill)
for i in ${FILES[@]}
do
FILE=${i//&/ }
FDF=${FILE%.pdf}.fdf
FILLED=${FILE%.pdf}-filled.pdf
pdftk “$FILE” fillform “$FDF” output “$FILLED”
done
;;
final)
for i in ${FILES[@]}
do
FILE=${i//&/ }
FDF=${FILE%.pdf}.fdf
FILLED=${FILE%.pdf}-filled-final.pdf
pdftk “$FILE” fill_form “$FDF” output “$FILLED” flatten
done
;;
esac
The script takes one of three arguments (anything else will quietly exit).
preparegenerates afieldsandfdffile for each PDF file in that directory (that doesn't have-filledin the name). Of course, it takes care not to overwrite existing FDF files, so you can drop new PDF files in (as you realize your taxes are getting more complicated) and re-runpreparewithout any issues.fillfills in all PDFs with their corresponding FDF files and outputs to-filled.pdf.finalfills in all PDFs with their corresponding FDF files, flattens it (permanently merges PDF and FDF content together), and outputs to-filled-final.pdf.
My workflow at this point is something as follows:
- Download the basic forms from the IRS (1040 and any schedules I think I may need). It often helps for me to look at my previous year's returns to figure out which forms I used (this year, they somewhat rearranged some of the forms, but it was still helpful). I save these in a subdirectory called
Original Forms(I also save form instructions here). - Make another subdirectory called
Filled Formsand copy the fillable forms to that directory. The rest of my work is largely done in theFilled Formsfolder. - Run
build.sh prepare. - Use the
.fieldsfile to fill in the FDF file (syntax is just<>- start inserting those after/Fields[). This is the annoying part, since often the form fields are given nonsensical names - the IRS is actually decent here, since they (largely) sequentially number them, and some of the form fields have meaningful names. - Run
build.sh filland open the-filledPDF in a new window (it will auto-reload if your PDF viewer is any good, which makes everything easier). - Once I'm actually done, I run
build.sh final.
Of course, part of the problem is that to e-file, you will end up using some official software of some sort – I usually use one of the web-based efile providers (much as I loathe the idea of putting this sensitive stuff on their servers...) simply because other options don't really exist. I still use this method to double-check my federal returns (sometimes the website can be a bit limiting, and you don't know it until you already know which forms you'll need) and file my state returns (since for a while, my state situation was actually annoyingly complicated).
This method (of course) will work for any fillable forms – nothing here is actually limited in any way to tax forms. But this workflow tends to work particularly well for me with my taxes, since I can gradually build up my return, adding schedules and forms as I need to.