有一个winform窗体,用了两个控件,一个是webBrowser1,一个是printDialog1,
我这有部分代码,是通过webservice将数据得到,然后通过Pen linePen = new Pen(Color.Black)画出格式
将内容打印出来,
可我现在想在上面把图片加上去也打印出来,不知道怎么实现,怎样修改下面的代码啊因为我对webservice不了解,我们老大又让我修改,所以请大家帮帮忙,实现红色字体的功能(在下面的代码里做修改)
就在省略号那里修改
急急急急急急
部分代码如下
void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            bool printOK = true;
            string orderNo = "", op_seq = "" ;
            string strArea = "", strOrderNum = "", strCNum = "", strOrderType = "", strMat = "", strCover = "", strQuantity = "", strFilm = "", strPaper = "", strVendorNote = "";
            string strOrderSource = "", strAgent = "", strShopName = "";
            string strG_last = "", strG_first = "", strB_last = "", strB_first = "";
            string strG_lastKanji = "", strG_firstKanji = "", strB_lastKanji = "", strB_firstKanji = "";
            string strWedDate = "", strChurchName = "", strItemName = "", strItemCode = "", strEdit = "", strProduct = "", strEditSort = "";
            string strImageSource = "", strShipDate = "", strImageRevDate = "", strShipKind = "", strLayoutDate = "",strChurchCD="",strNegaNote="";
            string strItemNameOvr = string.Empty;
            string strotherName = string.Empty;
            string strArticleAreaCno = "";  //iwink号
            string strArticleShipDate = ""; //海外仪式日
            string strBox = "";
            bool hurry;
            string[] strWorkDate = { "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
            bool bIsSendEmail = false;
            try
            {
                string printDocument = "";
                service = new WebService();
                orderNo = orderList[checkedIndex++];
                printDocument = service.getPrintDocument(orderNo);
                if (!string.IsNullOrEmpty(printDocument))
                {
                    string[] printItems = printDocument.Split('&');
                    if (printItems.Length != 56)
                    {
                        throw new Exception("获取数据错误!");
                    }
                    hurry = Convert.ToBoolean(printItems[0]);
                    strArea = printItems[1];
                    strOrderNum = printItems[2];
                    strCNum = printItems[3];
                    strOrderSource = printItems[4];
                    strOrderType = printItems[5];
                    strAgent = printItems[6];
                    strShopName = printItems[7];
                    strG_last = printItems[8];
                    strG_first = printItems[9];
                    strG_lastKanji = printItems[10];
                    strG_firstKanji = printItems[11];
                    strB_last = printItems[12];
                    strB_first = printItems[13];
                    strB_lastKanji = printItems[14];
                    strB_firstKanji = printItems[15];
                    strWedDate = printItems[16];
                    strChurchName = printItems[17];
                    strItemCode = printItems[18];
                    strItemName = printItems[19];
                    strMat = printItems[20];
                    strCover = printItems[21];
                    strQuantity = printItems[22];
                    strFilm = printItems[23];
                    strPaper = printItems[24];
                    strLayoutDate = printItems[25];
                    strImageSource = printItems[26];
                    strImageRevDate = printItems[27];
                    strShipDate = printItems[28];
                    strShipKind = printItems[29];
                    for (int i = 0; i < 14; i++)
                    {
                        strWorkDate[i] = printItems[30 + i];
                    }
                    strVendorNote = printItems[44];
                    strEdit = printItems[45];
                    strProduct = printItems[46];
                    strChurchCD = printItems[47];
                    strNegaNote = printItems[48];
                    op_seq = printItems[49];
                    strEditSort = printItems[50].Trim();
                    strItemNameOvr = printItems[51].Trim();
                    strotherName = printItems[52].Trim();                    strArticleAreaCno = printItems[53].Trim();
                    strArticleShipDate = printItems[54].Trim();
                    strBox = printItems[55].Trim();
                }
                else
                    throw new Exception("获取数据错误!");                System.Drawing.Font font;
                Pen linePen = new Pen(Color.Black);
                #region 标题
                font = new System.Drawing.Font("宋体", 20, FontStyle.Bold);
                e.Graphics.DrawString("生 産 管 理 単", font, Brushes.Black, 293, 30);
                font = new System.Drawing.Font("C39HrP36DmTt", 36);
                //打印生产管理单的barcode(sha_seq)
                e.Graphics.DrawString("*" + orderNo + "*", font, Brushes.Black, new Rectangle(8, 10, 220, 80));
                font = new System.Drawing.Font("Arial", 8, FontStyle.Bold);
                e.Graphics.DrawString("PrintTime:" + DateTime.Now.ToString("  yyyy.MM.dd HH:mm"), font, Brushes.Black, 570, 20);
                e.Graphics.DrawString("WATABE WEDDING ARTICLE CO.,LTD", font, Brushes.Black, 570, 35);
                #endregion                #region 订单信息
                font = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
                e.Graphics.DrawString("Order NO:", font, Brushes.Black, 20, 100);
                //Order NO为:Area_cd + order_num
                e.Graphics.DrawString(strArea + strOrderNum, font, Brushes.Black, 180, 100);
                e.Graphics.DrawLine(linePen, 160, 120, 340, 120);
                e.Graphics.DrawString("Area/Cust#:", font, Brushes.Black, 20, 125);
                //Area/Cust#为:Area_cd + c_num
                e.Graphics.DrawString(strArea + strCNum, font, Brushes.Black, 180, 125);
                e.Graphics.DrawLine(linePen, 160, 145, 340, 145);
                e.Graphics.DrawString("OrderSource:", font, Brushes.Black, 20, 150);
                //OrderSource为:orderSource
                e.Graphics.DrawString(strOrderSource, font, Brushes.Black, 180, 150);
                e.Graphics.DrawLine(linePen, 160, 170, 340, 170);
                font = new System.Drawing.Font("黑体", 11, FontStyle.Bold);
                e.Graphics.DrawString("注文区分:", font, Brushes.Black, 20, 175);
                //注文区分为:订单种类(M_orderType)
                e.Graphics.DrawString(strOrderType, font, Brushes.Black, 180, 175);
                e.Graphics.DrawLine(linePen, 160, 195, 340, 195);
                e.Graphics.DrawString("AGT区分:", font, Brushes.Black, 20, 200);
                //AGT区分为:M_shop(agent_cd)
                e.Graphics.DrawString(strAgent, font, Brushes.Black, 180, 200);
                e.Graphics.DrawLine(linePen, 160, 220, 340, 220);
                e.Graphics.DrawString("AGT名:", font, Brushes.Black, 20, 225);
                //OrderSource为:M_shop(shop_name)
                e.Graphics.DrawString(strShopName, font, Brushes.Black, 180, 225);
                e.Graphics.DrawLine(linePen, 160, 245, 340, 245);
                #endregion
                ............
                ............
                
           }
           catch (Exception ex)
            {
                if (ex.GetType() == typeof(InvalidPrinterException))
                    MessageBox.Show("打印失败!");
                else
                    MessageBox.Show("不能打印!" + ex.Message);
                printOK = false;
            }
            if (printOK)
            {
                try
                {
                    service.insertPrintRecord(orderNo,user);
                    if (!Properties.Settings.Default.NotPrint.ToUpper().Contains(strArea.Trim().ToUpper()))
                    {
                        string file1 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + op_seq.Trim() + "_" + "piccfm.tsv";
                        string file2 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + "instructions.tsv";
                        string file3 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + "Bihada.tsv";                        if (File.Exists(file1))
                        {
                            printfile(file1);
                        }
                        if (File.Exists(file2))
                        {
                            printfile(file2);
                        }
                        if (File.Exists(file3))
                        {
                            printfile(file3);
                        }
                    }
                }
                catch(Exception ep)
                {
                    MessageBox.Show(ep.Message);
                }                // 如果是Photo Select订单,则向用户发送Email
                if (bIsSendEmail)
                {
                    // 留待考虑是否使用Family发送Email
                }
                
            }
            if (++currentPage < pageCount)
                e.HasMorePages = true;
        }

解决方案 »

  1.   


    void pd_PrintPage(object sender, PrintPageEventArgs e)
      {
      bool printOK = true;
      string orderNo = "", op_seq = "" ;
      string strArea = "", strOrderNum = "", strCNum = "", strOrderType = "", strMat = "", strCover = "", strQuantity = "", strFilm = "", strPaper = "", strVendorNote = "";
      string strOrderSource = "", strAgent = "", strShopName = "";
      string strG_last = "", strG_first = "", strB_last = "", strB_first = "";
      string strG_lastKanji = "", strG_firstKanji = "", strB_lastKanji = "", strB_firstKanji = "";
      string strWedDate = "", strChurchName = "", strItemName = "", strItemCode = "", strEdit = "", strProduct = "", strEditSort = "";
      string strImageSource = "", strShipDate = "", strImageRevDate = "", strShipKind = "", strLayoutDate = "",strChurchCD="",strNegaNote="";
      string strItemNameOvr = string.Empty;
      string strotherName = string.Empty;
      string strArticleAreaCno = ""; //iwink号
      string strArticleShipDate = ""; //海外仪式日
      string strBox = "";
      bool hurry;
      string[] strWorkDate = { "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
      bool bIsSendEmail = false;
      try
      {
      string printDocument = "";
      service = new WebService();
      orderNo = orderList[checkedIndex++];
      printDocument = service.getPrintDocument(orderNo);
      if (!string.IsNullOrEmpty(printDocument))
      {
      string[] printItems = printDocument.Split('&');
      if (printItems.Length != 56)
      {
      throw new Exception("获取数据错误!");
      }
      hurry = Convert.ToBoolean(printItems[0]);
      strArea = printItems[1];
      strOrderNum = printItems[2];
      strCNum = printItems[3];
      strOrderSource = printItems[4];
      strOrderType = printItems[5];
      strAgent = printItems[6];
      strShopName = printItems[7];
      strG_last = printItems[8];
      strG_first = printItems[9];
      strG_lastKanji = printItems[10];
      strG_firstKanji = printItems[11];
      strB_last = printItems[12];
      strB_first = printItems[13];
      strB_lastKanji = printItems[14];
      strB_firstKanji = printItems[15];
      strWedDate = printItems[16];
      strChurchName = printItems[17];
      strItemCode = printItems[18];
      strItemName = printItems[19];
      strMat = printItems[20];
      strCover = printItems[21];
      strQuantity = printItems[22];
      strFilm = printItems[23];
      strPaper = printItems[24];
      strLayoutDate = printItems[25];
      strImageSource = printItems[26];
      strImageRevDate = printItems[27];
      strShipDate = printItems[28];
      strShipKind = printItems[29];
      for (int i = 0; i < 14; i++)
      {
      strWorkDate[i] = printItems[30 + i];
      }
      strVendorNote = printItems[44];
      strEdit = printItems[45];
      strProduct = printItems[46];
      strChurchCD = printItems[47];
      strNegaNote = printItems[48];
      op_seq = printItems[49];
      strEditSort = printItems[50].Trim();
      strItemNameOvr = printItems[51].Trim();
      strotherName = printItems[52].Trim();  strArticleAreaCno = printItems[53].Trim();
      strArticleShipDate = printItems[54].Trim();
      strBox = printItems[55].Trim();
      }
      else
      throw new Exception("获取数据错误!");  System.Drawing.Font font;
      Pen linePen = new Pen(Color.Black);
      #region 标题
      font = new System.Drawing.Font("宋体", 20, FontStyle.Bold);
      e.Graphics.DrawString("生 産 管 理 単", font, Brushes.Black, 293, 30);
      font = new System.Drawing.Font("C39HrP36DmTt", 36);
      //打印生产管理单的barcode(sha_seq)
      e.Graphics.DrawString("*" + orderNo + "*", font, Brushes.Black, new Rectangle(8, 10, 220, 80));
      font = new System.Drawing.Font("Arial", 8, FontStyle.Bold);
      e.Graphics.DrawString("PrintTime:" + DateTime.Now.ToString(" yyyy.MM.dd HH:mm"), font, Brushes.Black, 570, 20);
      e.Graphics.DrawString("WATABE WEDDING ARTICLE CO.,LTD", font, Brushes.Black, 570, 35);
      #endregion  #region 订单信息
      font = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
      e.Graphics.DrawString("Order NO:", font, Brushes.Black, 20, 100);
      //Order NO为:Area_cd + order_num
      e.Graphics.DrawString(strArea + strOrderNum, font, Brushes.Black, 180, 100);
      e.Graphics.DrawLine(linePen, 160, 120, 340, 120);
      e.Graphics.DrawString("Area/Cust#:", font, Brushes.Black, 20, 125);
      //Area/Cust#为:Area_cd + c_num
      e.Graphics.DrawString(strArea + strCNum, font, Brushes.Black, 180, 125);
      e.Graphics.DrawLine(linePen, 160, 145, 340, 145);
      e.Graphics.DrawString("OrderSource:", font, Brushes.Black, 20, 150);
      //OrderSource为:orderSource
      e.Graphics.DrawString(strOrderSource, font, Brushes.Black, 180, 150);
      e.Graphics.DrawLine(linePen, 160, 170, 340, 170);
      font = new System.Drawing.Font("黑体", 11, FontStyle.Bold);
      e.Graphics.DrawString("注文区分:", font, Brushes.Black, 20, 175);
      //注文区分为:订单种类(M_orderType)
      e.Graphics.DrawString(strOrderType, font, Brushes.Black, 180, 175);
      e.Graphics.DrawLine(linePen, 160, 195, 340, 195);
      e.Graphics.DrawString("AGT区分:", font, Brushes.Black, 20, 200);
      //AGT区分为:M_shop(agent_cd)
      e.Graphics.DrawString(strAgent, font, Brushes.Black, 180, 200);
      e.Graphics.DrawLine(linePen, 160, 220, 340, 220);
      e.Graphics.DrawString("AGT名:", font, Brushes.Black, 20, 225);
      //OrderSource为:M_shop(shop_name)
      e.Graphics.DrawString(strShopName, font, Brushes.Black, 180, 225);
      e.Graphics.DrawLine(linePen, 160, 245, 340, 245);
      #endregion
      ............
    ............   
      }
      catch (Exception ex)
      {
      if (ex.GetType() == typeof(InvalidPrinterException))
      MessageBox.Show("打印失败!");
      else
      MessageBox.Show("不能打印!" + ex.Message);
      printOK = false;
      }
      if (printOK)
      {
      try
      {
      service.insertPrintRecord(orderNo,user);
      if (!Properties.Settings.Default.NotPrint.ToUpper().Contains(strArea.Trim().ToUpper()))
      {
      string file1 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + op_seq.Trim() + "_" + "piccfm.tsv";
      string file2 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + "instructions.tsv";
      string file3 = Properties.Settings.Default.DataFolder + strArea.Trim() + strCNum.Trim() + "_" + strItemCode.Trim() + "_" + op_seq.Trim() + @"\" + "Bihada.tsv";  if (File.Exists(file1))
      {
      printfile(file1);
      }
      if (File.Exists(file2))
      {
      printfile(file2);
      }
      if (File.Exists(file3))
      {
      printfile(file3);
      }
      }
      }
      catch(Exception ep)
      {
      MessageBox.Show(ep.Message);
      }  // 如果是Photo Select订单,则向用户发送Email
      if (bIsSendEmail)
      {
      // 留待考虑是否使用Family发送Email
      }
        
      }
      if (++currentPage < pageCount)
      e.HasMorePages = true;
      }
      

  2.   

    FileStream fs = new FileStream(strImageSource, FileMode.Open, FileAccess.Read);
    Image image = System.Drawing.Image.FromStream(StreamToPrint);      
    System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(topMargin, leftMargin, width, height);                      System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(topMargin, leftMargin, width, height);   
                    //向画布写入图片   
                     for (int i = 0; i < Convert.ToInt32(Math.Floor((double)image.Height/ 820)) + 1; i++)   
                       {   
                             
                           e.Graphics.DrawImage(image, destRect, i*820,i*1170 , image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);   
                           //走纸换页   
                           if (i * 1170 >= e.PageBounds.Height - 60)//页面累加的高度大于页面高度。根据自己需要,可以适当调整   
                            {   
                               //如果大于设定的高   
                               e.HasMorePages = true;   
                            /*  
                               * PrintPageEventArgs类的HaeMorePages属性为True时,通知控件器,必须再次調用OnPrintPage()方法,打印一个页面。  
                               * PrintLoopI()有一个用於每个要打印的页面的序例。如果HasMorePages是False,PrintLoop()就会停止。  
                              */  
                               return;   
                          }  
      

  3.   

     int leftMargin = Convert.ToInt32((e.MarginBounds.Left) * 3 / 4);  //左边距   
            int topMargin = Convert.ToInt32(e.MarginBounds.Top * 2 / 3);    //顶边距 int width = image.Width;   
                 int height = image.Height;
      

  4.   

    图片是利用二进制保存在数据库里,在打印的时候把满足order = 4020607的图片全部打印出来
    打印出来的格式是每排显示三张图片,怎么实现