Spike

drfloob.com

About

My name is AJ, and I'm a web developer and software engineer out of Southern California.

If you're interested in hiring me, take a look at my portfolio and send me an email

Quick Scripts: How To Fill out PDF Forms on Linux

I'm applying to go back to school to get another degree, and I found myself needing to fill out a lot of PDF Forms. That's evidently a difficult task on Linux. I couldn't find any simple ways to do it, anyhow. So my options were either A) print out the forms and submit my chicken scratch handwriting, or B) hack together a solution for myself. Enter GhostScript and Inkscape.

I'm a huge fan of Inkscape. It is a versatile SVG authoring tool with the most natural keyboard shortcuts I've ever learned, and it's a ball of fun to play with. I design my site layouts with it, create graphics and logos, iron out simple flowcharts and mindmaps ... I could go on. It's a cool tool, check it out!

I've also got a growing sense of appreciation for the GhostScript project. It's got a very steep learning curve, but it has saved my butt a few times over the years. With PDF documents becoming more prevalent these days, being able to manipulate them is an invaluable skill.

So, yesterday, I needed to fill in a PDF Form. If you haven't had to fill one in yourself yet, you'll be surprised how few options you have for Linux. Forums, Mailing Lists, Google searches ... all turned up pretty empty. The closest thing I found was a tool called Scribus, which allows you to create fillable forms, but never had any mention of actually filling them in. I need a way to fill in preexisting PDF forms.

Thankfully, I've been reading the Inkscape documentation, and found that Inkscape can import PDF's one page at a time. Even better than that, I learned a lot about GhostScript recently trying to reformat a huge set of Python PDFs for print. In short, I can split a PDF into individual pages, add text with Inkscape, and smash the resulting SVG's together into a single, filled-out PDF.

Pretty cool, huh? Enjoy

Downloads

Here are the quick scripts I wrote to make this job a cakewalk:

drf_ink2pdf
  • Turns a series of Inkscape SVGs into PDFs
  • Requires: Inkscape
  • Usage:
    drf_ink2pdf [-C output_folder] file.svg [file2.svg file3.svg ...]
drf_mergepdf
  • Merges a series of PDFs into a single, multi-page PDF
  • Requires: GhostScript. Optional: a PDF Viewer, like evince or xpdf.
  • Usage:
    drf_ink2pdf [-C output_folder] file.svg [file2.svg file3.svg ...]

Questions

Why did you write your own merge PDF tool? Aren't there tons of those for linux?
Yes, there are tons. I wanted to learn something while writing a quick, single-purpose script.
How do you split a PDF up into single-page PDF's?
The command was pretty short, so I didn't write a script. For anyone interested in splitting up a multi-page PDF in batch, you can use something like:
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=singlePage-%02d.pdf multiPage.pdf

This spits out a series of pdfs named singlePage-01.pdf, singlePage-02.pdf, etc. Check out GhostScript's man page for formatting options.
You did blah blah blah wrong!
Cool. Let me know. I've got to learn somehow, right?
Adding text in Inkscape is hard! One letter per box? How did you do it?
Tip 1: Manual Letter Spacing is handy. When editing a text object, use Alt+> and Alt+< to increase and decrease letter spacing, respectively.
Tip 2: Use a monospace font.
Tip 3: Once you find the sweetspot for a specific font, font-size, and letter-spacing, REUSE THAT TEXT OBJECT. Copy and paste it, so you don't have to redo your kerning every time.