Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have created a .prn file using c#. how can i print prn file in thermal printer.
using parallel port (LTP1, LTP2 ...)

My Text in .prn file is as below
C#
            * RETAIL INVOICE *
          ABCD EFG HIJ KLMNOP QRST
              Banglore
            Mob No: 5652323232332
           VAT No: 56565656565656
Bill No: 398 Date: 20/01/2016 8:50 PM
               [Duplicate]
------------------------------------------
Item                     Qty   Rate Amount
------------------------------------------
TEST My PRODUCT 11     1.000 400.00 400.00
------------------------------------------
Subtotal                            400.00
              CASH : 400.00
      Total Scheme Discount : 3.19%
        Thank You Visit Again  :-)
 
di


Please advice.

How can we print this document using c#. Is there any way to print this file.
Please suggest.

Thanks
Posted
Updated 23-Oct-17 2:31am

1 solution

If has nothing to do with WPF, specifically, but you can do it with .NET. This is not a natural way of printing though. The idea is: you have to perform a "copy /b" ("/b" means "binary", or, in this case, "as is") command to copy your file to a printer. You would need to use your shared printer UNC path name (see also second last link below for an example), or use default printer ("prn", and the printer should be configured). To do it programmatically, you will need to use System.Diagnostics.Process.Start:
Process.Start Method (System.Diagnostics)[^].

Basically, that's all. See also:
C# Corner : Error Display[^],
Directly print *.prn files using C#.net[^].

I hope you understand that your PRN file should be obtained for a compatible model of a printer. In case of mismatch, you can get only printer malfunction or just garbage.

—SA
 
Share this answer
 
v3
Comments
PKriyshnA 23-Jan-16 8:20am    
I have tried this one. and i got the error in cmd
Error is "The system cannot find the path specified."
i have given right path
i am not using any shared printer. printer is attached to my computer and my operation system is Windows 7 32 bit.
My tried command is
C:\Windows\System32>copy /b D:\MyTest\mytest.prn > LPT1
and
C:\Windows\System32>copy /b D:\MyTest\mytest.prn \\MyCurrentComputerName\PrinterName

but i doesn't work for me, Please advice.
Sergey Alexandrovich Kryukov 23-Jan-16 11:16am    
What do you mean by "cmd"?
Don't use >
—SA
PKriyshnA 23-Jan-16 11:20am    
i mean i have tried from cmd.exe(Windows Command Processor) file.
Sergey Alexandrovich Kryukov 23-Jan-16 11:31am    
Thank you for answering. I just want to make sure you don't use CMD.EXE programmatically. You don't, right?
Now, remove >...
—SA
PKriyshnA 23-Jan-16 11:34am    
Yes i don't use cmd.exe in programming. i just testing in cmd.exe because if i try using .bat i am not able to see error, so just trying to test in cmd.exe.

You mean my code should be
C:\Windows\System32>copy /b D:\MyTest\mytest.prn LPT1

am i right ?

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