Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am using LPR command for printing PDF file, which is created by using iTextSharp.
For printing, I am passing PDF file path, saved on my machine.
C#
Process objP = new Process();
objP.StartInfo.FileName = "lpr";
objP.StartInfo.Arguments = " -P " + printerName + " " + fileName;

Now what I want is, sending PDF bytes directly to printer, instead of sending PDF file path.

I want to avoid saving of PDF file on machine for every print command, and then deleting it after printing completes.

I get PDF bytes from iTextSharp. Can I pass these bytes to process?

What I have tried:

I am able to print PDF file, y giving its physical path.
Posted
Updated 20-Nov-16 22:21pm
v2

1 solution

Good question, :-)

The fact is that this program allows you to strip out the file name from the command, then what it reads is the input that you pass to it, man page for lpr[^], reads as,
Quote:
If no names appear, the standard input is assumed.
Input can be the bytes that you want to send. In C# however, you would use the standard input for the process, Process.StandardInput Property (System.Diagnostics)[^]. Then you write the bytes to this property (it is a writer object, read documentation for more).

To get the bytes, just use File.ReadAllBytes(string) of System.IO namespace, that would work perfectly. Then pass them via writer to the input stream.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900