简体   繁体   中英

How to get “printer ready bytes” from a source in c#?

I'm in a bit of trouble here, hoping you can help a fellow programmer out.

I have an application that receives a pointer to raw bytes (plus length and stuff) and sends said raw data to a printer. This is important, I have no choice but to use this method to get any printing done.

If I send a raw string, it will print with no problem. However, I need to be able to print formatted text, images, etc. So the thing is... I would like to be able to get printer ready bytes from a given source (maybe a pdf, or html, does not matter as long as it contains formatted text and/or images). It would be like "splitting" the print command like so:

a) Open file and read data b) Load printer data into memory c) Send bytes to printer

Obviously, I've got a) and c) covered, it's b) the one that's breaking my head.

Any thoughts?

Thanks in advance for your help.

What you need is the printer processor to receive your print command and create formatted data. You wouldn't want to do this yourself, I hope (formatting to printer-ready data, even if you know PS, AFP, PCL or what it is nowadays, by heart, is very hard and months work). Instead, the printer processor of Windows should be used.

If you're on Windows (I assume, because you use C#, but perhaps you use Mono), you can send any printer command to a file (simply use the FILE: port). To create the formatted data, use any PDF library you have, or use RTF, which is supported by the .NET Framework, and send it to the selected printer (which should match the same printer that's on the other end of your application), which is configured on port FILE:.

The raw print data is then on disk, which you can simply read in as a byte array and send to your actual printer using the application you already got.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM