C# Raw Printing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to print raw byte data (PCL) to a printer in C# .NET 2.0. I was
disappointed that the BinaryWriter.Write method seems to specifically forbid
it. I would like to print to device names (e.g. lpt2:) and also network queue
names. Is there a way to do this using .NET? Failing that, can it be done by
importing win32 dll functions? Does anyone know of example code to do this?
Thanks.
 
I think there are a few librarys out there to control the ports
directly, hence you could get driverless controll of a printer.

It's not much fun though. Iv'e written a pure asembly util for printing
on a inkjet before purly by manipulating the port (skiping the bios
services). (This is dos days).

I can tell you that printers willl piss you of from a low level
programming point of view.

Their just plain un-co-operative and quite often they seem to behave
eraticly, the documentation you can get on controlling a printer in
this way would be good but each printer has its own quirks.

-dm
 
Hi Richard,

The .NET Framework cannot send preformatted printer-ready data to a
printer, you need to use with Win32 spooler functions to send raw data to a
printer.

I suggest you refer to the following MSDN KB article for the details on how
to read the contents of a preformatted file into memory, and then send
those bytes to the printer by using WritePrinter.

How to send raw data to a printer by using Visual C# .NET
http://support.microsoft.com/?kbid=322091

I hope the above information helps, if you have any questions or concerns,
please do not hesitate to let me know. I am standing by to help you.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you Gary, once again you have provided me with exactly what I was
looking for.

Thanks Duckman, I am already communicating with the printer successfully in
my legacy application, it is just a matter of porting to .NET. If I was
starting something new, I would use the proper .NET way of doing it.
 
Hi Richard,

I am very glad to help you on this issue, have a nice day. :)

Good Luck!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hey Richard,
I like your comment --- " proper .NET way of doing it. "

It sounds like an new world order or something.

-dm
 
Gary,

I implemented the code provided in the kb article to send raw data to
the printer and it works. But i need to print in a landscape mode. Is
it possible to define page orientation using the code ?

Please help,

Thanks,
-V
 
Got it to work...

I set it as:

string landScape;

landScape = Convert.ToChar(27).ToString() +
Convert.ToChar(38).ToString() + Convert.ToChar(108).ToString() +
Convert.ToChar(49).ToString() + Convert.ToChar(79).ToString();

//Send Landscape orientation
WritePrinter(hPrinter,landScape,landScape.Length, ref pcWritten);

// Write the bytes.
WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
 
Back
Top