c# - How to print Webview on a windows store app -
hey guys have been trying print webview using tutorial jerry nixon gave on how print webview content in windows store app? , tutorial "windows 8 apps xaml , c#" adam nathan, have attached code below example:
using system; using windows.graphics.printing; using windows.graphics.printing.optiondetails; using windows.ui; using windows.ui.core; using windows.ui.xaml.controls; using windows.ui.xaml.media; using windows.ui.xaml.printing; namespace chapter19 { public sealed partial class mainpage : page { // supports printing pages, each page uielement printdocument doc = new printdocument(); public mainpage() { initializecomponent(); // attach handlers relevant events doc.getpreviewpage += ongetpreviewpage; doc.addpages += onaddpages; printmanager printmanager = printmanager.getforcurrentview(); printmanager.printtaskrequested += onprinttaskrequested; } // prepare print preview pages void ongetpreviewpage(object sender, getpreviewpageeventargs e) { this.doc.setpreviewpagecount(2, previewpagecounttype.final); if (e.pagenumber == 1) { this.doc.setpreviewpage(1, new viewbox { child = new button { content = "page 1!", background = new solidcolorbrush(colors.red) } }); } else { this.doc.setpreviewpage(2, new viewbox { child = new button { content = "page 2!", background = new solidcolorbrush(colors.red) } }); } } // prepare real pages void onaddpages(object sender, addpageseventargs e) { this.doc.addpage(new viewbox { child = new button { content = "page 1!", background = new solidcolorbrush(colors.red) } }); this.doc.addpage(new viewbox { child = new button { content = "page 2!", background = new solidcolorbrush(colors.red) } }); this.doc.addpagescomplete(); } // prepare , perform printing void onprinttaskrequested(printmanager sender, printtaskrequestedeventargs args) { // gets invoked devices pane shown printtask task = args.request.createprinttask("document title", async (taskargs) => { // invoked on background thread when print // button clicked var deferral = taskargs.getdeferral(); await this.dispatcher.runasync(coredispatcherpriority.normal, () => { // must run on main thread taskargs.setsource(doc.documentsource); deferral.complete(); }); }); // show custom options printtaskoptiondetails details = printtaskoptiondetails.getfromprinttaskoptions(task.options); details.displayedoptions.clear(); details.displayedoptions.add(standardprinttaskoptions.mediasize); // custom text option printcustomtextoptiondetails option1 = details.createtextoption( "customid1", "header"); details.displayedoptions.add("customid1"); // custom list option printcustomitemlistoptiondetails option2 = details.createitemlistoption( "customid2", "contents"); option2.additem("customitemid1", "as seen on screen"); option2.additem("customitemid2", "summary view"); option2.additem("customitemid3", "full details"); option2.additem("customitemid4", "multiple columns"); details.displayedoptions.add("customid2"); // handle options changes details.optionchanged += onoptionchanged; } void onoptionchanged(printtaskoptiondetails sender, printtaskoptionchangedeventargs args) { // todo: handle custom options } } }
the problem having struggling "mywebviewpages" jerry generated onto "this.doc.setpreviewpage" , "this.doc.addpage" nathans example. due lack of pdf api's on winrt forced use webview since way have tables. please
Comments
Post a Comment