Workflow

Print one long document from many small text files

many small text files printing as one large documentI’ve been writing a large-ish thing, storing each chapter in an individual text file. I love this method – it’s fast, easy to edit, extensible (since I’m writing in markdown), etc.

However, what should I do when I need to print out one large document containing all the text files?

I could open each file, preview in a browser, then print, but that’s too much work when you’ve got 20+ text files. Or maybe I could bring each file into Scrivener and compile a larger document from that, but then I’m going back and forth between Scrivener and text files and back again…

Here’s what I did:

Printing one document from many small text files:

First: I grabbed the first txt file, converted it from MultiMarkdown to an HTML file. This is our master “shell” into which we’ll put all the other documents.

Second: Export each of the files to HTML, copy and paste into the “shell” HTML file. (it’s not pretty, I know, but it only took 5 minutes to go through 25 files).

Third: Insert a little style snippet into the <head> to give us some styles we like. You’ll find the snippet below.

Fourth: Save your HTML file, open in a browser and print.

Badda bing: you’ve got one long document, styled nicely, that will print each chapter (whatever’s started with an h1 heading) on a new page.

Simple Print Style Snippet

This style snippet does a few things: sets our fonts, sets the size of our headings, creates a new page at every h1 headline, and keeps some elements from being split by a page break. Extra points if you make this a TextExpander snippet.

<style>
    * {font-family:'Helvetica Neue', helvetica, sans-serif;
        line-height:1.5;
        font-size:14px;}
    body {padding:80px;overflow: visible}
    h1 {font-size:2.5em;page-break-before: always;}
    h2 {font-size:1.5em;}
    h3 {font-size:1.2em;}
    h4 {text-transform:uppercase;}
    h1, h2, h3, h4, h5, h6 { page-break-after:avoid;
        page-break-inside:avoid }
    img { page-break-inside:avoid; page-break-after:avoid; }
    blockquote, table, pre { page-break-inside:avoid }
    ul, ol, dl  { page-break-before:avoid }
</style>

Leave a Comment

Previous post:

Next post: