How to print all items in a listview RRS feed

  • Question

  • Hi,

    I have added a print contract to my app. I want my app to print all items in a listview. When there are too many items only the items loaded in memory are generated for print. How can I generate print content for all items in the listview datasource.

    Wednesday, December 26, 2012 7:01 PM


  • Hi ner9G,

    As the sdk "Print Sample" example demonstrated:

    #Print sample

    when we want to add printing functions for our windows store javascript app, we need to register the "onprinttaskrequested" event against the "PrintManager" object. And in the "onprinttaskrequested" event handler, we invoke "MSApp.getHtmlPrintDocumentSource" method to retrieve the html content which is used as html source to print (send to printing devices).

    Then, how the print output looks like depend on the source you supply through "MSApp.getHtmlPrintDocumentSource" method call. This method accept a html document object, you can supply the current page's document object or the document object of an iframe.

    #getHtmlPrintDocumentSource method (Windows)

    In any case, you need to make sure the html content retrieved from the specfiic document object has the expected html layout you want to print. For your case, you have large number of items (displayed via ListView) to print. Then, you cannot directly use the page layout which displays ListView for printing. Because ListView control will only show limited number of items and hide the remain ones (unless we scroll to them). If you want to print all items, you need to provide a printing specific UI layout which can be done through the following means:

    • You can just use CSS style to define a printing layout for your ListView page (for example, the style use @media query to specify that the ListView is hidden for printing view and you display a normal bullet list <ul><li>....</li></ul> to show all items)
    • Or you can just provide a separate html page to show all items (does not use ListView Control) and reference that page via iframe. Thus, you can supply the document object from the iframe when you call the getHtmlPrintDocumentSource method.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by ner9G Monday, December 31, 2012 10:19 PM
    Monday, December 31, 2012 8:15 AM