Sat, Dec 14, 2002

I recently ran into a problem where I had about 50 individual HTML documents, with each document was about 2 pages long,  that I wanted to merge into one big HTML document. After merging all of these into one big document, I wanted them to print with their pages numbered 1-100. 

(FWIW, the individual documents were all Use Case documents, and I wanted to merge them all together and print them for a design review. With all of the pages labeled "1 of 2" and "2 of 2" they were useless, but put in the proper order and printed as "1 of 100", "2 of 100", etc., they would be perfect for the review process.)

The simple Unix shell script below did the trick for me. It simple does a listing of every file in the current directory, and concatenates all of those files into one big file named index.html, with each file separated by a CSS page break. Now, when I open index.html and print it, the desired effect is achieved. If you know a little bit about Unix/Linux, this script is straightforward.

Here's the code for the script:



file="index.html"
echo "<html><head>" > $file echo "<STYLE TYPE=\"text/css\">" >> $file echo " P.breakhere {page-break-before: always}" >> $file echo "</STYLE> " >> $file echo "</head>" >> $file for i in `ls *.html` do cat $i >> $file echo "<P CLASS=\"breakhere\">" >> $file done

Note: While the big HTML file created by this script technically generates incorrectly formatted HTML code, with multiple HTML and HEAD tags, it prints just fine. And that's all I'm really worried about here. Please feel free to modify the script for your own needs.


If that explanation doesn't make sense, here's a bit more of a manual example that also works:

1. Put this code in the <HEAD> section of the HTML doc:

<STYLE TYPE="text/css">
P.breakhere {page-break-before: always}
</STYLE>


2. Put this code wherever you want a page to break (a hard page break I suppose) i
n your HTML document:

<P CLASS="breakhere">

3. Open your HTML doc in IE, then print it. Actually, you can even preview it, and
it should break properly in the previewer.

If that doesn't work, let me know!