Believe me, it is easy. As with any class, before we can use any of the Classes, Events and Objects available to us in the .Net Framework we need to import the Namespaces we need. For this we need 3 namespaces. VB.Net users only required 2 because VB.Net assumes the System Namespace, whereas C# isn’t so kind:
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. May 23, 2020 Select Local printer and deselect any detection options. Click through to the panel where you select your printer port. From the drop down menu, select FILE: (Print to File) As you move through the Add Printer Wizard, you’ll see a long list of manufacturers and printers.
.prn File Viewer
Mar 20, 2013 Answer: According to your needs, you choose the right software: PCL Converter which can be used to convert PCL, PXL PRN and other printing file formats files to PDF fast and accurately. And for this software, there is also developer version and SDK version, which allows you to call it together with the C#. How to send.prn file directly to USB local printer? This utility consists mainly of two.PRN files, one of which you print about 3 copies, then turn the pages over so that the printed sides get re-fused and clean off the fuser rollers as they exit (they also use a LOT of toner, so that the HP guys make a lot of money!). To print a PRN file in Windows, use the Command Line interface: Start menu-Run-'cmd'. In Mac OS X, PRN files are printed by dragging the file to the desktop printer icon. In case the printer is connected via USB, type: COPY /B filename.prn Computer NameShared Printer Name If the printer is connected via an older parallel port connection.
- System
- System.Drawing
- System.Drawing.Printing
These 3 Namespaces contain everything we need for this class, so you will need to add the following lines to the top of your class file:
Now we have to inherit the
PrintDocument
Class. To do this, make the following change to the declaration of your class:So now we have a shell to work with that inherits from the
PrintDocument
Class, so lets add some functionality and other code to our class. In our class we will have 2 properties, one to hold the text that we are printing, and one to hold the Font we will be using when printing our document. We will also add a variable to hold the current character we are working with. This is necessary for more than one page texts.Adding the Font property allows us to override the default font.
Next we will incorporate some Constructors for our class. Since we are inheriting from a separate class, we need to call the Constructor of the base class. This is done by using
base()
, this will call the Constructor of our base class, the PrintDocument
Class:Now we have our
Properties
and our Constructors
, next we will add a couple methods to our class. In our printing class we will be overriding 2 of the PrintDocument
methods, those will be the OnBeginPrint
method and the OnPrintPage
method. In the OnBeginPrint
method we will override the default font with the font we specify, and in the OnPrintPage
we will be setting up the specifics of our page. We will be setting the following properties:How To Print .prn File Using C 232
- Page Size
- Page Orientation (Landscape, Portrait)
- Top Margin
- Left Margin
How To Print .prn File Using C# On Mac
First, the
OnBeginPrint
method, as with our Constructors
we will need to call our base class’s OnBeginPrint
method, then we can do our custom work:As you can see, here we call the base class’s
OnBeginPrint
method, then we check to see if a font was provided, if no one was, we default to Times New Roman. The OnPrintPage
method is quite a bit larger and complex, this is where we will be doing the bulk of our work.In this method we will be setting the size of the print area (the page size), we will determine if the user selected Landscape or Portrait as the print style, we will determine how many lines we are printing and how many lines will fit in our page size, and finally we will tell the printer whether we have more pages to print. As with our
OnBeginPrint
method, we will need to call our base class’s OnPrintPage
method before doing our customizing of the method. Let’s take a look at our overridden OnPrintPage
method:You will notice that in this method we reference a function called
RemoveZeros
. This is the last function in our class, and it has an important role. We will create a function that will check our value, and if it’s a 0 (not the number, but a memory space with a value of zero – ascii 0 -) we will replace it with a 1 (ascii 1). Zero’s can cause bad things to happen when it comes to printing and determining page size and margins, so to alleviate that we use our RemoveZeros
Function:And there you have it, our completed printing class. Now I know some are asking “I see this class, but how do I use it?”. Well I’m glad you asked, this class is very easy to use. In your Form’s code add a procedure named
printDocument
. Then inside that procedure create an instance of the printer class. Set its properties (PrinterFont, TextToPrint) and then issue a print command, like this:Some other functions and classes you may find useful are
DrawRectangle
, FillRectangle
, Arc
, Brushes
and Pen
. All these basic functions will help you get beautiful reports if you have the patience to put them together.Based on Printing in C# by PsychoCoder