7
Answers

Printing Bank Cheques in c#

Anant

Anant

15y
24.4k
1

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)
2
Frogleg

Frogleg

NA 7.9k 33k 14y

Attachment ChequeText.zip

to print to a preprinted check
Look at this and modify as you need.
You will have to create a custom paper size in your printer preferences the same size as cheque'
Add more text boxes for more lines and alter printDocument_PrintPage as needed 



0
Frogleg

Frogleg

NA 7.9k 33k 14y

Attachment Cheque.zip

If you don't want to bother creating a custom paper size, you can use say A4 size - but set the print lower -refer diagram
0
sajan yamaha

sajan yamaha

NA 16 0 14y
This is great...i ddnt expected this much...so now i have change printer preferences rt ???

thanks dude.. you made my day.
0
sajan yamaha

sajan yamaha

NA 16 0 14y
hey mahesh..this is all abot printing the whole document.

but wat about printing only values to a document,
like printing amount into a cheque leaf.

eg user puts his chequebook into printer and press print button in the software.the values gets printed into the cheque leaf.

its urgent ...
0
Mahesh Chand

Mahesh Chand

2 286.9k 123.7m 14y

Read this article. This shows how to print a Windows Form.
Printing out your W2 Form using C# and .NET
0
antoine  Peterson

antoine Peterson

NA 2 0 14y

Tharesh.. seems you revived a very old thread.. However solution is fairly simple.
Use a pdf lib such as QPDF I think there free version should do the trick.
Scan your cheque(s) to get exact text box positions x1 x2 y1 y2
Store All details in table of sorts.
A simple class number to words
Once you have all the positions & text. you will be able to write to pdf at relevent positions.. also making sure text fits relevant boxes. by changing textbox width.
Once done you can either save the file or print directly from mem.
If I can do it in VBa am sure you can in c# ;-)
 
 
 
 
0
tharesh hn

tharesh hn

NA 2 0 14y
Chequeprinting.DataLayer.Chqcord Chqcord = new Chequeprinting.DataLayer.Chqcord(); where is this class..evn i want to print  name,amount and date on check..through program in c#..

pls help me..
thanx in advance