Monday, December 26, 2011

Tech PDFs should be 7.5" x 9"

‹prev | My Chain | next›

I have made a right old mess out of my fork of the git-scribe tool chain for producing ebooks. A mess it may be, but the resultant mobi is a bit better in that code blocks no longer split across pages and some Kindles better recognize the result as an ebook.

But really, I should do what I can to get back to upstream. Most of the work that I have in my fork is better epub/mobi out, but there is at least one PDF fix that I consider a show-stopper. Technical PDFs should be 7.5" x 9". Go on, check your PDFs from "real" publishers. That's how big they are. 8.5" x 11" is fine for printing on US-letter, but it is just too darn tall for computer reading.

Anyhow, I had got 7.5"x9" working back on my original fork fairly easily. Let's see how well that applies to recent upstream changes.
➜  git-scribe git:(master) git fetch upstream
➜  git-scribe git:(master) git co -b upstream -t upstream/master
Branch upstream set up to track remote branch master from upstream.
Switched to a new branch 'upstream'
The most obvious thing to try is cherry picking my old commit into this upstream branch:
➜  git-scribe git:(upstream) git cherry-pick b94110f
error: could not apply b94110f... Certain publishers prefer 7.5x9 inch paper size
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'
The conflict is in the lib/generate.rb file responsible for, well, just about everything in an ebook generating library:
➜  git-scribe git:(upstream) ✗ gst
# On branch upstream
# Changes to be committed:
#
#       modified:   docbook-xsl/fo.xsl
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      lib/git-scribe/generate.rb
#
More specifically, it looks as though the xsltproc command-line is missing the page-size options:
      java_options = {
        'callout.graphics' => 0,
        'navig.graphics'   => 0,
        'admon.textlabel'  => 1,
        'admon.graphics'   => 0,
      }
      run_xslt "-o #{local('book.fo')} #{local('book.xml')} #{base('docbook-xsl/fo.xsl')}", java_options
Back in my version, I had added the page-size:
strparams = {'callout.graphics' => 0,
                   'navig.graphics' => 0,
                   'admon.textlabel' => 1,
                   'admon.graphics' => 0,
                   'page.width' => '7.5in',
                   'page.height' => '9in'
      }
      param = strparams.map { |k, v| "--stringparam #{k} #{v}" }.join(' ')
      cmd = "xsltproc  --nonet #{param} --output #{local('book.fo')} #{base('docbook-xsl/fo.xsl')} #{local('book.xml')}"
      ex(cmd)
The easiest thing to try is to simply add those options to the new version:
java_options = {
        'callout.graphics' => 0,
        'navig.graphics'   => 0,
        'admon.textlabel'  => 1,
        'admon.graphics'   => 0,
        'page.width' => '7.5in',
        'page.height' => '9in'
      }
      run_xslt "-o #{local('book.fo')} #{local('book.xml')} #{base('docbook-xsl/fo.xsl')}", java_options
      ex "fop -fo #{local('book.fo')} -pdf #{local('book.pdf')}"
After re-building and re-installing the gem, I give it another try:
➜  backbone-recipes git:(master) ✗ git-scribe gen pdf
GENERATING PDF
GENERATING DOCBOOK
asciidoc: reading: /etc/asciidoc/asciidoc.conf
asciidoc: reading: /home/cstrom/.asciidoc/asciidoc.conf
asciidoc: reading: /etc/asciidoc/asciidoc.conf
asciidoc: reading: /home/cstrom/.asciidoc/asciidoc.conf
asciidoc: reading: /home/cstrom/repos/backbone-recipes/output/book.asc
asciidoc: reading: /etc/asciidoc/docbook45.conf
asciidoc: reading: /etc/asciidoc/filters/graphviz/graphviz-filter.conf
asciidoc: reading: /etc/asciidoc/filters/music/music-filter.conf
asciidoc: reading: /etc/asciidoc/filters/code/code-filter.conf
asciidoc: reading: /etc/asciidoc/filters/source/source-highlight-filter.conf
asciidoc: reading: /etc/asciidoc/filters/latex/latex-filter.conf
asciidoc: reading: /etc/asciidoc/lang-en.conf
asciidoc: writing: /home/cstrom/repos/backbone-recipes/output/book.xml
asciidoc: book.asc: line 7: reading: /home/cstrom/repos/backbone-recipes/output/history.asc
asciidoc: book.asc: line 16: reading: /home/cstrom/repos/backbone-recipes/output/introduction/namespacing.asc
Making portrait pages on USletter paper (7.5inx9in)
...
And it works! I could have sworn that I tried that a couple months back without success.

Just to be sure, I check the properties of the resultant PDF and, sure enough, it is 7.5" x 9":


I call it a night here. Up tomorrow, I need to see if I can get syntax highlighting working again with upstream. I had it working a few months ago, but am unable to find the magical combination of configuration options and installed packages to get it working tonight.

Update: Ugh. It turns out that I was re-installing my old version (0.0.9) of the gem rather than the new version (0.1.1). And so, page width and height are not, in fact, being honored.

Day #246

No comments:

Post a Comment