打印辅助类。

首先添加

using System.Windows.Printing;

命名空间

 1 public class SilverPrint
 2     {
 3         //设置每一项之间的间距
 4         int listPrintIndex = 0;
 5         private List<PrintStr> listStr = null;
 6         public void Print(List<PrintStr> strs)
 7         {
 8             listStr = strs;
 9             PrintDocument printDoc = new PrintDocument();
10             printDoc.PrintPage += OnPrintPage;
11             PrinterFallbackSettings settings = new PrinterFallbackSettings();
12             settings.ForceVector = true;
13             printDoc.Print("dd", settings, true);//dd是文档的名字
14         }
15         public void OnPrintPage(object sender, PrintPageEventArgs e)
16         {
17             Canvas printSurface = new Canvas();
18             //得到最顶端位置
19             double topPosition = e.PageMargins.Top;
20             //遍历当前的ListBox.Items
21             while (listPrintIndex < listStr.Count)
22             {
23                 //实例化TextBlock用来存放每一行的值
24                 TextBlock txt = new TextBlock();
25                 txt.FontSize = listStr[listPrintIndex].FontSize;
26                 txt.Text = listStr[listPrintIndex].Content;
27                 double measuredHeight = txt.ActualHeight;
28                 //如果打印的当前行高度不合适的话,则进行分页
29                 if (measuredHeight > (e.PrintableArea.Height - topPosition))
30                 {
31                     e.HasMorePages = true;
32                     topPosition = e.PageMargins.Top;
33                     break;
34                 }
35                 //设置TextBlock在Canvas中的位置
36                 txt.SetValue(Canvas.TopProperty, topPosition);
37                 txt.SetValue(Canvas.LeftProperty, e.PageMargins.Left);
38                 //将TextBlock添加到打印的元素中去
39                 printSurface.Children.Add(txt);
40                 listPrintIndex++;
41                 //追加高度
42                 topPosition = topPosition + measuredHeight;
43             }
44             e.PageVisual = printSurface;
45         }
46     }
47     //打印内容类
48     public class PrintStr
49     {
50        public string Content { set; get; }
51        public int FontSize { set; get; }
52        public PrintStr(string str,int size=10)
53        {
54            this.Content = str;
55            this.FontSize = size;
56        }
57     }

打印直接调用

new SilverPrint().Print(printStrs);

如果是silverlight5.0之前会弹出打印预览。。。如果是silverlight5.0 允许浏览器外允许 增加权限。就可以不用弹出打印预览,直接打印了。

silverlight 调用默认打印机相关推荐

  1. java调用默认打印机,打印小票(80mm)

    一.默认打印机工具类 package vpos.zs.print;import net.sf.json.JSONObject;import java.util.Map; import java.uti ...

  2. java调用默认打印机打印发货标签

    效果: 实现:主入口 public static void main(String[] args) {//获取默认的打印机PrintService defaultPrint = PrintServic ...

  3. java 调用 默认打印机 打印小票

    直接上代码 参考:java 实现58热敏票据打印 如有侵权,请联系QQ 1450648869 package com.example.demo.print;import java.awt.Color; ...

  4. C#调用系统默认打印机打印文字和图片

    本方法适用于有打印驱动的打印机打印.直接用电脑默认打印机进行打印文字和图片. 首先安装打印机驱动,然后在设备和打印机中将要用的打印机设为默认打印机,然后调用该方法即可 Pulic Void Print ...

  5. Android调用系统默认打印机并反射获取打印任务状态

    Android4.4通过PrintManger调用系统默认打印服务的默认打印机进行打印任务,并通过反射调用PrintManager的getPrintJob方法获取打印任务状态.不说太多,直接上代码.第 ...

  6. Delphi获取默认打印机名称及端口

    在前段时间写的收银系统中由于目前市场上很多电脑主板上已经没有并口,而POS机却又需要并口,所以目前需要用PCI转接卡,这个就导致不同门店使用的端口就有可能不同,这就给我们程序中弹出钱箱的指令带来一定的 ...

  7. winform设置默认打印机

    /// <summary> /// 设置默认打印机 /// </summary> public class Externs { [DllImport("winspoo ...

  8. python调用小票打印机_PyQt5中使用Qprinter打印热敏小票

    在<PyQt5中使用QWebChannel和内嵌网页进行js交互>一文中,我记录了如何使用QWebchannel与内嵌网页进行js交互,其根本目标在于使用Qt5调起打印机服务.在这篇文章中 ...

  9. JAVA调用TSC打印机打印标签(二维码,数据等)超详细!!

    本文打印机型号: TSC MA3400P 后端调用tsc打印机是通过DLL来进行调用的,首先你需要两个TSC文件直接复制到项目目录下边即可 可以直接去官网下载:https://www.chinatsc ...

最新文章

  1. java高并发(十八)线程池
  2. 原生js删除html,原生js操作dom添加删除替换class
  3. Array with Odd Sum CodeForces - 1296A
  4. python怎么调用列表_Python中列表的使用
  5. HDU 2588 GCD(欧拉函数)
  6. Django运行项目时候出现DisallowedHost at / Invalid HTTP_HOST header:
  7. Python基础1(2017-07-16)
  8. E站账号cookie分享_58云账号跨域实践总结
  9. No module named ‘pyqt5‘解决办法
  10. 14 款(移动端)UI 框架
  11. 保研推免经历经验分享——2018北大软微、北航计算机、南大计算机夏令营保研经历
  12. 数学函数模块math
  13. 夕阳美,美到骨子里了
  14. 【论文解读】关于基于视觉无人机自主降落平台的论文梳理
  15. java 获取apk版本号_纯JAVA环境获取APK信息:包名,版本,版本号,大小,权限...
  16. 华熙LIVE·五棵松商业北区明年国庆亮相 互动体验升级
  17. 关于在线课程及软件开发学习--给真正希望学习的朋友
  18. replace 与 replaceAll
  19. linux 替换多行内容,整理sed实战修改多行配置技巧
  20. 关于outlook展示发件人、收件人乱码的问题

热门文章

  1. 剑指offer面试题23:从上到下打印二叉树(树的层序遍历)
  2. Buy Tickets(poj 2828)
  3. Maven构建Struts2框架的注意事项
  4. IIS中架设二级域名网站
  5. 最强奥运会(互联网公司版)
  6. 在京东、天猫、淘宝都存在情况下,为什么聚美还能崛起?
  7. PMCAFF | App竞品分析报告:美丽说VS蘑菇街
  8. 【干货】PMcaff干货课程学习精彩分享:Apple Watch 技术特性详解
  9. springboot使用restTemplate post提交值 restTemplate post值
  10. 横向ListView(四) —— 添加滚动条