Share via


Printing (HTML)

These topics describe how to print content from a  Windows Store app that is built with JavaScript and HTML.

These topics assume that you already understand how to write programs with JavaScript and HTML, and so they focus on the techniques that are specific to printing from Windows Store apps that are built with JavaScript and HTML.

Overview

To print from an app in Windows 8, the app must access Windows printing and provide the formatted content to be printed.

Accessing Windows printing

Your app accesses Windows printing by registering for the Print contract in each view of the app from which you want users to be able to print. Registering for the Print contract means obtaining a PrintManager object, creating a PrintTask object, and handling the printing events. Quickstart: Print from your app and How to print using an in-app print button show how to do this.

After registering for the Print contract, your app can customize the print experience, if necessary. How to change default settings in the print window shows one way to customize the default print experience.

Windows printing provides a preview feature to all apps that have registered for the Print contract. For the most consistent user experience, Windows Store apps should use the print preview functions provided by Windows printing instead of creating a print preview feature specific to the app.

Note about window.print()

The JavaScript function window.print() can be used to print your app’s content, but it is intended for printing the content that is displayed on the screen by using the default print experience. Unfortunately, what makes a Windows Store app display well on the screen doesn’t always produce good printed output. Because calling window.print() to print from your Windows Store app might not provide the best customer experience, we recommend that your app use the Windows Runtime functions to register for the Print contract.

Providing formatted content to print

Because the screen display of your Windows Store app is likely to be formatted differently from what would look good on paper, the app must create a copy of the content that is specifically formatted for printing.

Note  Customized printing features like printing specific pages or custom print settings can only be added to Windows Store apps using C++, C#, or Visual Basic and XAML. For more info about adding custom printing features to your app, see Printing (XAML).

 

Best practices

Best Practices for developing print-capable Windows Store apps contains other valuable tips for printing content from your app.