HTML and CSS Reference
A print task has a name that will reference the job in the printer and is associated with some work
aimed at grabbing and formatting the content to print. In Windows 8, you always use a single line of
code to reference the code to print. More specifically, from within a WinJS application, you always
print the current HTML document displayed to the user. That's just what the line below achieves.
The next point to tackle is how you can ensure that the getHtmlPrintDocumentSource always gets
the right content from the document's object model.
The printing user interface
Let's put the whole topic of printing the content aside for a moment. The only way to print in
Windows 8 is through the print dialog shown in Figure 12-10.
FIGURE 12-10 The print charms.
You select the printer of choice and then see another panel containing a preview of the page that
responsible for providing the content to preview and print. The preview window (see Figure 12-11) is
generated by the system and requires no extra code beyond the code you saw earlier.
As you can discern from Figure 12-11, if your intended purpose is to print the current content
of the screen you don't need to do anything—just bring up the charms print dialog and go. More
reasonably, though, you probably want to print only a subset of the content currently displayed on
the screen. Doing that requires a few tricks.
In essence, in Windows 8, and from a WinJS-based application, you want to print only some of
the HTML content from the currently displayed document. Printing plays by common browser rules,
which means that hidden content is not printed, and any visible content can be optionally styled for
To print exactly the content you want at a given point, you need to arm yourself with print-only
style sheets and some extra code that hides the content you don't want to print, leaving just the
content that needs to go to the printer visible.