Stupid Sudoku Book Generator

12:06 am FPDF, My Stores, PHP, Puzzles, Sudoku

I’m looking for beta participants for my PC client! See http://blog.sc.tri-bit.com/archives/151.

The problem? PDF. The solution? FPDF, PHP, and the force of anger incarnate.


So, I’ve got the puzzle drafting application up and running in a non-painful way, which took no small (read: Herculean) effort and a pinch or two of CSS Ninja Magic. This means I have a relatively pleasant interface in which to hand-create my sudoku puzzles, instead of this pencil and paper bullcrap slowing me down.

Of course, I like my puzzles (being an egotist that’s a given, but let’s ignore that for now.) As a result, I want to share them with others, preferably for money. The logical choice is a place like Cafe Press or Lulu, but they both want books kind of already laid out, so they can just print them and be done with them.

This all sounds perfectly reasonable, until that horrible death knell comes gonging around the dark recesses of your animal hindbrain, into places your soul is afraid to go, where ancestral memory remembers stuff like dinosaurs and being hunted by eagles and effective presidents and other scary relics of an antiquarian past.

The name of that knell? PDF.

So, in order to provide content for these places, one has to give up a standardized-ish format which is designed for print. Luckily, postscript doesn’t really much exist in modern tools, so god forbid I be able to go in with a programming language for my layout application, guns a-blazing. (Interject here with fond memories of my father showing me Display PostScript on his NeXTslab as a programming language in which to write actual applications.) At first my plan was to get one of those PDF printer targets like Primo going, then to use Word automation from Delphi to do the actual printing. That worked well enough for my blank boards, but it got hella cumbersome when I wanted to do non-trivial boards, so I started to look for alternatives.

Then I found FPDF, which in many ways rocks. It’s a PHP class from which you derive classes which implement printing behaviors. You override methods to handle when page breaks might occur (for example, to set up column driven layout, keep some variable off in a corner somewhere, and when FPDF says “time to page break,” you override by saying “No, just move ten inches to the left and back up to the top.”) The methods to get things done are relatively straightforward, measured in user-chosen units relative to the edges of the current page, and so on. It’s relatively pleasant, despite a few seriously annoying bugs.

Granted, it seems either that FPDF only implements a subset of PDF, or that PDF is entirely simpler than I had previously believed. Really, you just have a few graphics primitives with simple color and thickness controls for line and fill, the ability to place form elements and the ability to place images. That’s pretty much it, and that surprised me.

But, you know what? That’s all I need for Sudoku. My generation tool now knows how to crap out a homebrew sudoku format (including for all those purty variants I’ve learned about,) and I have a PHP script that turns many instances of that format straight into CafePress ready books. (Actually, with some tweaking, I intend to extend this script to handle other puzzle types, too. I’ve got a genuinely funktronic layout model going on, which I’m getting fairly into.)

So, some standard Sudoku books are on the Very Near Horizon™, as soon as I teach my generator how to put together title pages and instructions pages (there’s a lot of automatic scaling and placement going on, so that’s not as trivial as it sounds) and to place some niceties in the books. You’ll need to buy one to find out what those nicities are, natch.

Right now, my book generator only knows how to draw standard and off-rectangle sudoku (3×3, 4×4, 2×5, et cetera.) Soon, irregular backgrounds. Afterwards, disjoint backgrounds. Promptly following? ”The World”.

I have some very neat things I intend to reveal on that store in the near future. Be sure to go buy things. Right now.

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.