Wednesday, November 21, 2012

Creating a Compliant PDF for a Blurb Book with TeX

I'm an avid Blurb user since I receive my first photo book. They're just awesome. But I'm not going to talk about photos this time.

Today, I received my first text book, 440 pages, trade format (6x9 inches), printed in black and white and with hardcover and dust jacket. I opened it and it's just awesome. As awesome as a custom-made text book can be, at least for that price (approximately $33). The book is heavy, seems sturdy, doesn't look cheap, the text is finely printed and the paper is very good, with a nice creamy colour and nice to the touch. I just tried Blurb's text and photo books, and they really live up to the expectations. If you're wondering whether you should try them: you definitely should. Furthermore, Blurb has recently expanded their offerings including magazines, brochures, planners and other products. I haven't tried them yet (and don't know if I will), but should I need one of them, I wouldn't hesitate to purchase them from Blurb. The Downside of Using TeX with Blurb TeX (and TeX-derived processors) are wonderful, provided you know how to use them. And if you have some scientific academic background, chances are you do. I've been a faithful TeX user since the 90's, and I never switched to other editors, not even for pure text books. TeX's advantages are manifold, but suffice it to say that the quality of the documents you can produce is high, much higher (from a typesetting standpoint) than what you can achieve with a basic desktop publishing software (such as Microsoft Word). And TeX is it's really WYSIWYG and portable. Blurb provides many tools to easily create books and upload them to their site. Most of them take care of producing a Blurb-compliant book so that users have not to worry about that. Adobe Lightroom 4, for example, has a very flexible Book module that mimics built upon Blurb's BookSmart. Here you can find the update list of available tools for editors. What's the problem with TeX? The problem is that the output of a TeX engine depends on the engine itself. For "generic" books, Blurb has got a PDF To Book feature that allows users to upload a Blurb-compliant PDF for print. And what's "Blurb-compliancy"? Blurb obviously checks for a lot of things about the PDF in order to make sure the book is printed as the client wants it to be. Basically, the pages in the PDF files must conform to the sizes specified by Blurb's PDF To Book Specification. which, on the other hand, obviously depend on your book geometry. For example, the number of pages and the paper type determine the height of a book's spine, and you've got to take that into account when designing your book cover. This reasoning applies to all parameters of a book geometry (such as page size, cropped size, bleed, margins and safe boundaries). To complicate things even further, Blurb requires the PDF to be a compliant PDF/X-3 file. Needless to say, many PDF export tools (such as OS X save to PDF or pdfTeX) don't guarantee such compliance. When it comes to TeX, then, apart from setting up your page geometry according to Blurb specifications (which is a problem which affects every publishing tool you may use), you've required to produce a compliant PDF/X-3 file, otherwise the Blurb preflight checks will fail. The purpose of this blog post is describing how I solved this problem and help TeX/LaTeX users out there easily produce a Blurb-compliant PDF file. My workflow usually is: • Typeset the book in TeX with approximate book specifications: you don't really know them until the exact number of pages is known, so don't even bother nailing them at the beginning. • Once the number of pages is known, I fine tune the book specs. • Once the book is ready for print, I manage to produce a compliant PDF/X-3 file. Book Specifications This is the easy part, and that's one TeX is really great for. On the other hand, since TeX is so flexible, how you achieve it depends on parameters such as the TeX engine and the packages you're using. When editing text books, I usually rely on LaTeX and the memoir document class. Why? Because it encapsulate common functionality for book editing provided by lots of other packages (without dealing with each of them), it's extremely well documented and it's easy to use, especially when it comes to stock and page size tuning. If you use other engines or classes, however, don't worry: rely on their documentation to discover how to tune the page size according to Blurb specs. Furthermore, as we'll see later, pdfTeX (and company) doesn't produce PDF/X-3 file, and you've got to rely on some tricks to produce a proper file. Maybe you should check other TeX engines (such as the excellent ConTeXt) which now supports PDF/X out of the box. Getting a Blurb-compliant PDF with ConTeXt is a no-brainer. But you might lose the possibility of using other packages you're used to (such as the memoir class, which I really like). If you're beginning your book, I suggest you take a look at ConTeXt and see whether it fits your needs. Here's an example of a book setup in case you decide to use LaTeX and the memoir class. Let's suppose your book has got 390 pages, hardcover with dust jacket, black and white printing. According to Blurb, the book specifications are (in points): • Final PDF should measure: 441x666 • Page size / trim line: 432x648 • Bleed: 9 • Inset for margins (top, bottom, outer): 18 • Inset for margins (binding): 45 This is a screenshot of the Blurb calculator:  Blurb Calculator - Specifications for a book To tune your memoir document, you can use this code (I prefer to use inches in the book): \setstocksize{9.25in}{6.125in} \settrimmedsize{9in}{6in}{*} \settrims{0.125in}{0.0625in} \settypeblocksize{*}{\lxvchars}{1.618} \setlrmargins{*}{*}{0.618} \setulmargins{*}{*}{1} \setbinding{0.625in} \checkandfixthelayout Please note that the settypeblocksize is not required to get a compliant book, it's just a suggestion to get a beautifully proportioned typeblock size. Change the dimensions accordingly (remember that 1 inch corresponds to 72 point) to match your book dimensions using Blurb calculator. If you need more insights on the features provided by the memoir class, check its documentation. Producing a PDF/X-3 Compliant File This is the tricky part, and I was lucky enough to find a proven solution on the Internet (according to a discussion thread in TeX - StackExchange). In fact, I worried about this only when the book was typeset, and I started worrying whether I should switch to ConTeXt (and losing part of the typesetting work) or purchasing Adobe Distiller. Fortunately, there was a solution. To have pdfTeX produce a compliant file, you should add this fragment just before the \begin{document} statement and tune it to your needs: \pdfinfo{ /Title (Your Book Title) % set your title here /Author (The Author) % set author name /Subject (The Subject) % set subject /Keywords (The Keyword Set) % set keywords /Trapped (False) /GTS_PDFXVersion (PDF/X-3:2002) } % I think Blurb ignores both the MediaBox and the TrimBox, but I put it anyway \pdfpageattr{ /MediaBox [0 0 441.00000 666.00000] /TrimBox [0.00000 9.00000 432.00000 657.00000]} \pdfminorversion=3 \pdfcatalog{ /OutputIntents [ << /Info (none) /Type /OutputIntent /S /GTS_PDFX /OutputConditionIdentifier (Blurb.com) /RegistryName (http://www.color.org/) >> ] } The MediaBox and the TrimBox are the important parts, which establish the page geometry. As you can see, the MediaBox is set to the Blurb final PDF specification (beware that the box coordinates are swapped compared to the output of the Blurb calculator). The TrimBox is a little trickier to "casual users". Since the bleed is 9, I set the first of the trim box corners to (0pt, 9pt) (that's why you'd better get point measures from Blurb) and the second corner was set to (432pt, 657pt). Why? 432pt is the trimmed size width, and you can leave it as is. Since the bleed affects the bottom and the top of the page, you can subtract it from the media box: 666 - 9 = 657. Assuming your text won't run so close to the trim lines. Run your input file through pdfTeX and you should get a compliant PDF/X-3 file. The compliancy can be checked with the free Adobe Reader application. First of all, you should see the yellow trim box you specified on your PDF pages and, most importantly, you should get the following two entries into the document properties (both required by PDF/X-3): • PDF Version: 1.3 (Acrobat 4.x). • GTS_PDFXVersion: PDF/X-3:2002 The former is found in the main document properties tab (called Description), the latter into the Custom tab, as shown in the following picture:  Adobe Reader - Document Properties - Custom What About the Cover? The same reasoning applies. However, even if I consider myself an hardcore TeX user, I just rely on Adobe InDesign and Blurb's InDesign Plugin to get a good cover. You can certainly argue you can design it with TeX, and it's true, but when I'm dealing with images in a single page cover, I just prefer to use InDesign, especially since Adobe lets us rent it for approximately$30 bucks a month. I try to accumulate some jobs and process them on a single month.

Sometimes it's not possible and it certainly is a deal breaker for many, I do realise it. Anyway, as I already said, there are many other options, just check Blurb's website.

Conclusion

As you can see, producing a TeX book for printing with Blurb should be easy enough for any TeX user. The results are wonderful, both because TeX is a great engine and because Blurb is delivering awesome quality products at reasonable prices.

I hope this helps a lot of TeX users out there.