Anant

Anant

  • NA
  • 8
  • 0

Printing Bank Cheques in c#

Dec 21 2009 8:08 AM

Hi All
I am developing one windows application where i have to print the contains on bank cheques. my current code is printing that details on  cheque but my problem is that text is not clear beacouse for printing the contains of particular panel, I have to capture the screenshot image of that panel and seve it into memory stream as bitmap image and because of printing image,my print quality is become so poor and text is getting faded. so is there any othe way to print those text on cheque with good quality print like word or excel does. following is the code which i have written for printing.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace Chequeprinting
{
    public partial class ChequeforPrinting : Form
    {
        Chequeprinting.DataLayer.Chqcord Chqcord = new Chequeprinting.DataLayer.Chqcord();
        Chequeprinting.DataLayer.Numbertostringconv numstr=new Chequeprinting.DataLayer.Numbertostringconv();
        private Bitmap memoryImage;
        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

        public ChequeforPrinting()
        {
            InitializeComponent();
        }

        private void ChequeforPrinting_Load(object sender, EventArgs e)
        {

            // This code willget user defined positions for the controls like Payee,date,amount,
            //amount in words etc. and set that coordinates to controls
             DataSet ds = Chqcord.showrec(int.Parse(Chequeprinting.DataLayer.MaintainSessions.bankid));
            Control[] cnt = new Control[] { lblpay, lblrswords, lblrs, lbldate, pictureBox6 };
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataTableReader dtrr = ds.CreateDataReader();
                int i = 0;
                Font ft;
                while (dtrr.Read())
                {
                    ft = new Font(dtrr[6].ToString(), 11);
                    cnt[i].Font = ft;
                    int x = int.Parse(dtrr[3].ToString());
                    int y = int.Parse(dtrr[4].ToString());

                    cnt[i].Location = new System.Drawing.Point(x, y);
                    i++;

                }
                int accpaystat = Chequeprinting.DataLayer.MaintainSessions.accpaystat;
                if (accpaystat == 0) pictureBox6.Visible = false;
                lblpay.Text = Chequeprinting.DataLayer.MaintainSessions.payee;
                lblrs.Text = Chequeprinting.DataLayer.MaintainSessions.amt;

                lblrswords.Text = numstr.Custrupees(lblrs.Text);
                lbldate.Text = Chequeprinting.DataLayer.MaintainSessions.date;
            }
            this.Close();
        }
        private void CaptureScreen(Panel p)
        {
            //this code will capture the image of a panel and store it into memory stream
            Graphics myGraphics = p.CreateGraphics();
            Size s = p.Size;

            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            IntPtr dc1 = myGraphics.GetHdc();
            IntPtr dc2 = memoryGraphics.GetHdc();
            BitBlt(dc2, 0, 0, p.ClientRectangle.Width, p.ClientRectangle.Height, dc1, 0, 0, 13369376);
            myGraphics.ReleaseHdc(dc1);
            memoryGraphics.ReleaseHdc(dc2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //this will print that image on bank cheques but the printing is very fad and
            //of less quality becaiuse i have converted text to image
            CaptureScreen(panel1);
            printDocument1.DefaultPageSettings.Landscape = true;
            printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 840, 1180);
            printDocument1.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
            printDocument1.Print();

           
        }
}


Answers (7)