Tech Write Tips

June 28, 2006

HTMLHelp Multiple Page Printing

Filed under: HTMLHelp,Technology — AndyR @ 6:55 am

HTMLPrint.gifIt wasn’t until I was reading of another authors struggle to get multiple topics printing correctly out of HTMLHelp that I realised that I had hit the problem myself. If you haven’t tried it you should try multiple page printing for your HTMLHelp and see if it still has your style applied.

The issue is that when you print multiple topics from a .chm it doesn’t just print each topic in turn. What happens is an intermediate html file is created from the selected topic. 

You can view this file as follows:

  1. Right clicking a book in the TOC of your .chm.
  2. Selecting print all topics. Leave the Print dialog open and browse to “C:\Documents and Settings\USERNAME\Local Settings\Temp”.
  3. Sort this folder by date, and you should see an .htm file thats name starts with “~hh…”.
  4. Open this file in a text editor to view how it has been compiled.
  5. Note the single <Head> section, and updated SRC sttributes for <IMG> tags.
  6. Also note the location of the .css which will reference your .chm absolutely but include the relative path from the topic and therefore not work.

Head Problem
This intermediate file only has one head section. This can cause a few headaches such as the IE header states the first topic on all printed pages. But worse than this is that if you have included any script calls or any automation in your header, or if you have a script that references header information will not work. In my case I was generating the topic title from the page title tag in the header. Therefore when I printed mulitple pages they all had the same header. Doh!

This is something that you may need to work around for your printed output. In my case I ended up including a hidden topic title that was then turned on just for printing via a “@media print {H1.print {display:block}}” in my style sheet.

CSS and JS Location Problem
This intermediate file is generated in a temp folder. To ensure that the images are displayed correctly the print routine automatically adjusts the src elements to reference from its new location. However, if you have referenced a .css or .js it doesn’t update the location.

To get around this you need to implement an absolute location to these files in your topics. You are essentially replacing the relative location (“../../Style.css”) with an absolute location (“ms-its:HELP.chm::Style.css”). These absolute references are dealt with properly in the intermediate file for printing.

Advertisements

5 Comments »

  1. Interesting, I wonder how many of my helps have this problem. *Runs off to check*

    Comment by marks — April 11, 2006 @ 4:53 pm | Reply

  2. Additional: I have also come across the suggestion that you could, if you are able to live without the script or .css on the printed topic, detect the filename in the script and if it begins “~hh…” then don’t run the script.

    According to Microsoft MVP Rob Cavicchio (who identified 3 and 4 above):
    In cases 3 and 4, it is possible to conditionally use these items when the topics are viewed online, but prevent them from being included in the printout. This requires a bit of scripting. You basically have to check to see if the file name of the document.URL begins with “~hh”, which tells you it’s a book printout.

    Comment by techwritetips — July 3, 2006 @ 6:39 am | Reply

  3. Snippet 46 on my site may also help.

    http://www.grainge.org/pages/snippets/snippets.htm

    Comment by Peter Grainge — July 3, 2006 @ 11:19 am | Reply

  4. Thanks for the comment. I hadn’t thought of this approach. Although for me, duplicating my .css would be quite problematic as this would compromise the ease of changing the style of the help that made me switch to .css.

    I like your site by the way, very helpful.

    Comment by techwritetips — July 3, 2006 @ 11:52 am | Reply

  5. Hi .. awesome find…This is a must read for me,
    Thanks for sharing the great info with us all.

    Comment by Fun Envelopes — October 4, 2006 @ 9:39 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: