using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Drawing.Printing;
namespace BNCheckItemsClient.FormC.Specimen
{
    publicclass PrintSpecimenLabel
    {
        PrintDocument printDocument;
        privateint _PrintPage =0;//当前打印页
         privateint _TotalPage =1;//总页数 
         publicstring _PrinterName =string.Empty;// 打印机名称
        publicvoid DoPrint()
        {
            try
            {
                //准备数据
                PrepareData();
               
                if (_TotalPage <=0)
                    return;
                //设置打印机
                PrinterSetup();
                if (!string.IsNullOrEmpty(_PrinterName))
                {
                    printDocument.PrinterSettings.PrinterName = _PrinterName;
                    if (!printDocument.PrinterSettings.IsValid)
                    {
                        thrownew Exception("The printer is not Valid");
                    }
                }
                printDocument.Print();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //throw;
            }
        }
        privatevoid PrinterSetup()
        {
            //设置打印机属性
            printDocument.PrinterSettings.PrinterName ="ZDesigner 888-TT";//设置打印机
            printDocument.DefaultPageSettings.PaperSize =new System.Drawing.Printing.PaperSize("SpecimenLabel",110, 180);//页面大小
            printDocument.DefaultPageSettings.Landscape =true;//横向打印
            printDocument.PrintPage +=new PrintPageEventHandler(printDocument_PrintPage);
         }
        //在这里写打印的内容
        void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;
            float leftMargin = 5f; //左边距
              SolidBrush myBrush =new SolidBrush(Color.Black);//刷子
              float yPosition = 5f;//行定位
            Font printFont =new Font("宋体", 20f, FontStyle.Bold);//设置字体
            g.DrawString("这是要打印的第一行内容",printFont, myBrush, leftMargin + 140f, 7f, new StringFormat());
            yPosition += printFont.GetHeight(g);//另起一行
              printFont =new Font("宋体", 10f, FontStyle.Bold);//改变字体
            g.DrawString("这是要打印的第二行内容", printFont, myBrush, leftMargin, yPosition, new StringFormat());
            //如果要同时打印多个标签
              _PrintPage++;//页号
            if (_PrintPage < _TotalPage)
            { 
                e.HasMorePages =true;
            }
            else
            {
                e.HasMorePages =false;
            }
        }
    }
}

到打印机和传真文件夹-->右键-->服务器属性
添加了自己定义的纸类型 名称949W300H 宽9.49in,高3.00in

所以改了程序为

foreach(PaperSize ps in printDoc.PrinterSettings.PaperSizes)
{
 if(ps.PaperName=="949W300H")
 {
  printDoc.PrinterSettings.DefaultPageSettings.PaperSize=ps;
  printDoc.DefaultPageSettings.PaperSize=ps;
 }
}

就可以了 似乎纸张只能从printDoc.PrinterSettings.PaperSizes中选择

最新文章

  1. 如何提高Java并行程序性能??
  2. 图片浏览(CATransition)转场动画
  3. TabBarController
  4. Android系统目录结构
  5. FusionCharts 相关知识
  6. SQLite的简单应用
  7. grunt项目配置
  8. Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)
  9. JVM 进行线程同步背后的原理
  10. Compress、tar、gzip、zcat、bzip2、bzcat、打包解压命令行
  11. EMV规范 ---ISO7816 T=0协议的时间特性
  12. Linux经常使用命令(一) - ls
  13. Spring Cloud Zuul
  14. VUE 出现Access to XMLHttpRequest at &#39;http://192.168.88.228/login/Login?phone=19939306484&amp;password=111&#39; from origin &#39;http://localhost:8080&#39; has been blocked by CORS policy: The value of the &#39;Access-Contr
  15. mm-wiki安装部署
  16. webpack打包后该如何访问项目?
  17. 织梦自定义表单ajax提交范例
  18. 发布xxl-job executor dotnet core 执行器的实现
  19. Docker for Windows 代理设置(linux container)
  20. 查看CUDA和cuDNN的版本号

热门文章

  1. UIViewController三种不同的初始化view的方式
  2. hdu 4496(并查集)
  3. 多线程环境下调用 HttpWebRequest 并发连接限制
  4. ORA-00845 MEMORY_TARGET not supported on this system解决办法
  5. 【POJ3621】Sightseeing Cows 分数规划
  6. Vue基础-匿名插槽与作用域插槽的合并和覆盖行为
  7. MapRecude
  8. CentOS开启telnet连接
  9. ubuntu下安装myeclipse+破解
  10. Oracle 数存储——物理结构