A Helper Class to Print Text Box Content in a Windows Store App
Join the DZone community and get the full member experience.Join For Free
microsoft's documentation & sample for printing is too complex. the sample app for printing shows only how to print richtextblock . there's no tutorial to print the textbox content in a windows store app. moreover, to print a single line string, one has to write too much code rather than a maximum of 10 lines in winform. so, this helper class provides the simplest method to print the text box content. it has only one static method. it prints the text box content with its formatting. it's majorly based on msdn print sample.
i got the idea to write a library from the following stack overflow questions:
how to use it ?
you have to call just one static method
, it will do print job on your behalf.
await printer.showprintuiasync(printpreview, mytextbox, guid.newguid().tostring());
printpreview is a canvas, which is mandatory to show print preview in device charm. you have to declare in your xaml.
mytextbox is a text box object, whose text content is going to be printed.
- guid.newguid().tostring() is a file name for printing the document. (it will be applied if you are creating pdf or xps file via printing.)
i would be glad to have issues or suggestions from you, so i can improve this. if you want to fork the repository or post issues, find this helper class on
Published at DZone with permission of Farhan Ghumra. See the original article here.
Opinions expressed by DZone contributors are their own.