Rob Mason
Rob Mason

Reputation:

Print PRN files from C#

I'm in the process of converting some Visual Basic 6.0 code to C#. The code deals with taking pre-generated PRN files and sending these to a printer.

However I'm a little confused as to how to do this using C#. I've looked at PrintDocument, but I don't think that's doing what I want to do as I intend to send the PRN file straight to the printer (in some cases I need to modify the data before it gets sent to the printer).

In Visual Basic 6.0 we used the following:

intPrinter = FreeFile
Open gstrPrinter For Output As #intPrinter

intFileChn = FreeFile
Open strOverlay For Binary As #intFileChn

Do Until EOF(intFileChn)
    Get #intFileChn, , strDatIn
    Print #intPrinter, strDatIn;
Loop

I'm looking at doing something similar where it either streams a file or loads it first then sends this to the printer.

I know I could possibly go down the route of using xps files using the new printing as part of WPF, but ideally I'd like to keep the input files as they are and just change the Visual Basic 6.0 code over to C# which is doing the actual printing.

Upvotes: 3

Views: 6944

Answers (1)

Anand Shah
Anand Shah

Reputation: 14913

It's not that straightforward as in VB 6.0; the C# way is a bit lengthy. See Printing Directly to the Printer.

Upvotes: 1

Related Questions