Click here to Skip to main content
15,905,325 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all

Below is the code i am using to print in epson passbook printer from notepad

C#
string name;
                       name = "C:\\Display.txt";
                       // Open the file.
                       FileStream fs = new FileStream(name, FileMode.Open);
                       //printFont = new Font("Lucida Console", 9);
                       // Create a BinaryReader on the file.
                       BinaryReader br = new BinaryReader(fs);
                       // Dim an array of bytes big enough to hold the file's contents.
                       Byte[] bytes = new Byte[fs.Length];
                       int bSuccess=0;
                       // Your unmanaged pointer.
                       IntPtr pUnmanagedBytes = new IntPtr(0);
                       int nLength;

                       nLength = Convert.ToInt32(fs.Length);
                       // Read the contents of the file into the array.
                       bytes = br.ReadBytes(nLength);
                       // Allocate some unmanaged memory for those bytes.
                       pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
                       // Copy the managed byte array into the unmanaged array.
                       Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
                       PrtSetFont(10002);
                       PrtPosAbsV(2);
                       PrtPosAbsH(5);
                       PrtPosRelV(2);
                       PrtPosRelH(1);
                       fs.Close();
                       int lines1 = File.ReadAllLines(name).Count();
                       int Number1 = lines1 / 26;
                       if (lines1 > 26)
                       {
                           File.WriteAllText("C:\\Display-1.txt", String.Empty);
                           bSuccess = PrtWrite(pUnmanagedBytes, nLength);

                       }

Here i am taking the formatted data from notepad and writing to another notepad and sending to PrtWrite() which is printing the data at a time.

Now i have to send one line at a time.

Please tell me how to do this.
Posted

You can loop through the lines of the file and then do your processing. See http://msdn.microsoft.com/en-us/library/dd383503(v=vs.110).aspx[^]
for an example of how to loop through the lines of your source file using File.ReadLines()
 
Share this answer
 
Comments
Black_Rose 15-Oct-14 0:39am    
Thanks for your reply.
i did this below code

using (StreamReader srr = new StreamReader("C:\\Display.txt"))
{
line = srr.ReadToEnd();

line is a string variable which contains this when i see in HTML visualization

Date Particulars ChequeNo Withdrawals Deposits Balance -------------- -------------------------- --------- ----------- -------- -------- 1 07 Oct 2011 By INITIAL DEPOSIT 0 0.00 100.00 100.00 2 31 Mar 2012 By Half Yearly Interest 0.00 2.00 102.00 3 30 Sep 2012 By Half Yearly Interest 0.00 2.00 104.00 4 31 Mar 2013 By Half Yearly Interest 0.00 2.00 106.00 5 14 Jun 2013 By Cash 0 0.00 12170.00 12276.00 6 14 Jun 2013 To SCHOOL FEES FR SES JUN 0 11545.00 0.00 731.00 7 14 Jun 2013 To SCHOOL FEES FR AVG JUN 0 625.00 0.00 106.00
when i am printing it is printing like this only.
Please tell me how to format this.
ZurdoDev 15-Oct-14 7:19am    
I suggest you start a new question and post the relevant information.
First, you're not going anything at all "from notepad".

Those a "text files", not "notepads". Get the terminology correct before you start confusing the crap out of people when they can't figure out what you're talking about.
 
Share this answer
 
C#
nLength = Convert.ToInt32(fs.Length);

Why are you trying to convert an integer to an integer?
Also if these are text files then you should read How to: Read Text from a File[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900