Wednesday, April 3, 2019

Lawyering in Linux - E-signing a PDF

I had the need the other day to e-sign a PDF that I hadn't myself generated. If I had generated the PDF, I could have easily stuck in the /s/ line myself on the signature line.

Luckily I had two great FLOSS tools to help: PDFtk and LibreOffice. The heavy lifting is done with pdftk and its multistamp operation. In my case, I had a 9-page PDF with signature lines on page 3 and page 9, so this is what I did:

  1. Determine the pages and locations on each page where you need to add text (in this case, a signature) (you can also add images). I went ahead and printed out the two pages I needed and used a ruler, but you can eyeball it to start, because you're likely to need to iterate anyway.
  2. Create a Writer document in Libreoffice. You can typically use libreoffice --writer to do this.
  3. Generate enough page breaks to match the number of pages in the PDF file. If you have a LOT of pages, you might consider using pdftk to break up your PDF into individual pages, and process each page separately. That exercise is left to the reader.
  4. On each page that needs, e.g., a signature line: create a table with two columns and two rows. Size the row height of the top (or bottom) row to get the other row in place. Then size the left (or right) column width to get the right cell into place. Make sure you uncheck "fit contents" so the row doesn't auto-resize.
    • If you need more elements on the page, add more tables. You can put tables inside tables if you need to. Or, you can use frames or other elements to put text on the page.
    • Don't forget to put your text and/or image into the correct cell!
  5. Save the Libreoffice document as a PDF.
  6. Use pdftk {PDF to sign} multistamp {PDF of signature(s)} output {Signed PDF} to sign the PDF. The output will have the name you gave to {Signed PDF}.
  7. Pretty likely, this won't work the first time. So go back to step #4 and adjust your row and column sizes, or frame positions, or whatever, and try again. I think it took me 3 iterations.
There you go - your text and/or other elements will now be stamped on the PDF you inherited.

You might also take a look at  stamptk in case that meets your needs! Keep in mind, though, that stamptk is a proprietary program, not FLOSS.


Post a Comment