国庆节小报内容,703804散讲温州,小鹅与红房子
利用flowdocument进行模板打印
xaml
<dockpanel > <button content="preview" margin="15" click="button_click_1" dockpanel.dock="bottom" height="76"/> <flowdocumentpageviewer verticalalignment="top" width="300" name="fd" borderbrush="blue" borderthickness="2"> <flowdocument pagepadding="38" > <paragraph textalignment="center"> <run fontfamily="宋体" fontweight="bold">酒店名称:</run> [hotelname] </paragraph> <blockuicontainer> <line x1="0" y1="0" x2="800" y2="0" stroke="black"/> </blockuicontainer> <paragraph> <run fontweight="bold">日期:</run> [date] </paragraph> </flowdocument> </flowdocumentpageviewer> </dockpanel>
代码
private void button_click_1(object sender, routedeventargs e) { var filename = @"test.xaml"; using (filestream fs = new filestream(filename, filemode.openorcreate)) { xamlwriter.save(fd.document, fs); } var sts = file.readalltext(filename); sts = sts.replace("[hotelname]", "naradahotel") .replace("[date]", datetime.now.tolongdatestring()); var d = ((idocumentpaginatorsource)xamlreader.parse(sts)).documentpaginator; printdialog pd = new printdialog(); pd.printdocument(d, "test"); }
用string.replace进行替换,不知道也没有其他办法?
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论