打印图像

 private string __ImagePath = string.Empty;// "C:\\";//发票图像路径,设置的路径
        private string __ImageFullPath = string.Empty;//发票全路径
        private Image __InvImgView = null;//存储发票图像  



/// <summary>
        /// 打印图像
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrintI_Click(object sender, EventArgs e)
        {
            this.__ImagePath = Holytax.Common.ConfigXML.InvoiceImagePath;
            try
            {
                bool isSelectInvoice = false;
                string thisInvImagePath = string.Empty;
                for (int i = 0; i < gridView1.DataRowCount; i++)
                {
                    object obj = gridView1.GetRowCellValue(gridView1.GetRowHandle(i), "COLCHK");
                    if ((int)obj == 1)
                    {
                        object objInvImagePathTp = gridView1.GetRowCellValue(gridView1.GetRowHandle(i), "IMAGEPATH");
                        if (objInvImagePathTp != null)
                        {
                            thisInvImagePath = objInvImagePathTp.ToString();
                        }
                        if (thisInvImagePath.Length > 0)
                        {
                            arrPrintImageFiles.Add(__ImagePath + thisInvImagePath);
                            isSelectInvoice = true;
                        }
                    }
                }
                if (isSelectInvoice)
                {
                    PrintImage();
                }
                else
                {
                    XtraMessageBox.Show("未选择发票或选择的发票找不到图像文件。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception err)
            {
                LogHelper.Write(err.Message, Holytax.Log.LogHelper.LogMessageType.Fatal, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                XtraMessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        } 


#region 图像打印


        private void pDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            string strSourceFileName = arrPrintImageFiles[i_current].ToString();
            try
            {
                if (!strSourceFileName.StartsWith("http://"))
                {
                    MyImage = Image.FromFile(strSourceFileName);
                }
                else
                {
                    HttpWebRequest httpRequest = WebRequest.Create(strSourceFileName) as HttpWebRequest;
                    WebResponse httpResponse = httpRequest.GetResponse();
                    MyImage = new Bitmap(httpResponse.GetResponseStream());
                }
            }
            catch (Exception err)
            {
                LogHelper.Write(err.Message, Holytax.Log.LogHelper.LogMessageType.Fatal, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                throw new Exception("找不到图像文件:" + err.Message);
            }
            MyImage = Common.ComTools.AlterPicResolution(MyImage, (float)(MyImage.Width * (float)2.54 / 24));
            e.Graphics.Clip = new Region(e.MarginBounds);
            e.Graphics.DrawImageUnscaled(MyImage, e.MarginBounds);
            i_current++;
            if (i_current < arrPrintImageFiles.Count)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }
        }

        System.Collections.ArrayList arrPrintImageFiles = new System.Collections.ArrayList();
        int i_current = 0;
        Image MyImage = null;
        private void PrintImage()
        {
            PrintDocument pDocument = new PrintDocument();
            //设置边距
            Margins margin = new Margins(100, 0, 100, 0);
            pDocument.DefaultPageSettings.Margins = margin;
            //横向打印
            pDocument.DefaultPageSettings.Landscape = true;
            pDocument.DocumentName = "发票图像";
            pDocument.PrintPage += new PrintPageEventHandler(this.pDocument_PrintPage);
            try
            {
                //print只能调用一次,e.HasMorePages控制打印的页数
                pDocument.Print();
                //清空打印所用变量,包括图像,打印页,图片数组
                if (MyImage != null)
                {
                    MyImage.Dispose();
                    MyImage = null;
                }
                i_current = 0;
                arrPrintImageFiles.Clear();
                XtraMessageBox.Show("打印完毕.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                pDocument.PrintController.OnEndPrint(pDocument, new PrintEventArgs());
            }
        }

        #endregion



//DevExpress 消息提示

//DevExpress.XtraEditors.XtraMessageBox.Show("打印完毕.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值