small medium large xlarge

How Do We...?

How Gerbils Make Sausage

Generic image illustrating the article
  People often write in and ask us how we do things: how are the PDFs stamped? how do we ship books? what technology do we use to author books? Each month we’ll answer one of these questions.  
This month's question: How do you add my name to the bottom of the PDFs I buy?

We refuse to hobble our electronic books with Digital Rights Management (DRM) restrictions. We feel that, just as when you buy a paper book, you should be able to use your electronic books as you see fit. You should be able to copy them to your laptop, make backups, read them on your phone or eBook reader—whatever you need. We just ask that you respect our copyright, pay for the books you use, and don’t give those books to others.

To help remind readers that we’re giving them responsibility for their books, we add their name to the bottom of each page of their PDFs. (We once toyed with the idea of putting their credit card number there, but prudence won out.) So how do we do that?

During the regular build process (driven by rake, of course), we produce master PDF, mobi, and epub versions of a book. These versions are checked into a subversion repository.

Over in the EC2 cloud, we have a variable number of stamping machines running. Each of these machines has a checked-out copy of the book masters.

The stamping machines use a REST interface into our order system to look for new purchases and requests for book regenerations. When a request comes along, they take the master PDF and run it through a program that adds the annotations you see (along with a few other annotations you don’t see) to produce a personalized PDF. This PDF is then stored in S3. This is the PDF that you download.

We used to use some commercial software to do the stamping, but the licencing terms became ridiculous, so we’ve switched to using the wonderful open source iText library. It’s a Java program, so we drive it from our Ruby code using a simple popen call, passing stamping parameters to the stamper’s standard input.

Once stamping is complete, the EC2 machine uses another REST request to tell the online store, and your download becomes available.

And how do we tell the stamping machines to update their master copies of the books when we make changes? Our book build process tells the online system, and the system tells the stampers when they next request work. They then simply issue an svn up and continue.