Create the.PRN file on the first computer. Open the application, select print, select the proper printer, check the Print to File box, and give the file a name. Copy the file to removable media so you can carry it to the second computer (or use a network to transfer the file there in a location you can later find. 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!). 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: System System.Drawing System.Drawing.Printing These 3 Namespaces contain everything. A visual LPR printer for PRN files written in C# by Rick Dove This is a simple application for printing PRN files to a printers IP address using the LPR Port Monitor Service version 1.0 features: a button to browse folders and select a PRN file. The Syncfusion Essential Barcode control is used to create various types of barcodes. Using this control, you can print barcode on a printer using C# and VB.NET. Steps to print barcode on a printer programmatically: Create a new C# Windows Forms application project.
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:
- 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.
![C%23 C%23](/uploads/1/1/9/5/119595444/564966571.jpg)
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:- Page Size
- Page Orientation (Landscape, Portrait)
- Top Margin
- Left Margin
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:![.prn .prn](/uploads/1/1/9/5/119595444/699347518.gif)
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.Convert Print A Prn File
Based on Printing in C# by PsychoCoder