Stupid COM...

ziggy on 2002-02-19T21:31:46

Here's an uncommon request. Format an SGML source file into RTF, and use inside/outside/gutter margins to prepare the document for binding.

Turns out that DSSSL understands top/bottom/left/right page margins, but not top/bottom/inside/outside/gutter margins. It should, and it could (with the proper set of extensions), but it doesn't. Bummer.

But, any SGML/DSSSL/RTF hacker is going to have a copy of Word nearby, and theoretically, you should be able to write a small Perl program to drive Word to update the formatting properly. (This is how external graphics are typically embedded into a Word file; RTF does support embedded graphics, but Jade doesn't allow you to generate them using DSSSL.)

So, after a couple of wasted hours trying to find the appropriate docs on MSDN, and trying to get a Perl script to cozy up to Word in just the right manner, I thought I was done. Except that the little Perl script to reset the page margins was opening and saving my RTF documents, but not actually setting the page margins. Not worth debugging.

Eventually, I did what I should have done in the first place: update the RTF file manually using Word and doing a before/after diff of the outputs.

Sure enough, the answer was a 20 line Perl script to open, modify and save the RTF file. (RTF is a simple text format after all). Why 20 lines? Just lots of whitespace, comments and clear statements around a simple regex to tweak the margins.