I have a PCL file that I generated using "print to file".
What's the best way to programmatically print this file in C#?
(Given of course that the printer I am printing to supports PCL.)
I know that I can print by invoking from a prompt:
copy filename.pcl //location/printername
So I would imagine that I could also do the same thing programmatically (using copy)... I wonder if there is a cleaner way to do this, say using PrintDocument.
Note that when I use PrintDocument:
var pd = new PrintDocument
{
DocumentName = @"filename.pcl";
PrinterSettings = {PrinterName = @"\\location\printername"}
};
pd.Print();
I always get a blank page printed.
This article applies to Visual Basic, but it is easy enough to follow to be able to apply it to C#, I think. Otherwise, I'll gladly assist you with any problematic parts.
If the printer is on the network, here's a little funny example of how to talk directly to it. Not sure if it also works if you simply send the bytes of the PCL to the printer though.
I'm sorry to have come so late to this question, but I have some code that will do the job. It was not written by me originally. I received the code from another programmer's help site, but I can't remember which one. It works beautifully. Here is the project, which creates a dll. To do it yourself, select Create:/Project/Class Library (select Visual C# under project types).
Now, to use this code, add the resulting dll as a reference to your project, then call the functions as you need them. Here is some code where I used it, just today:
This program reads a PCL Font from a file. It wraps the font with code to assign a font id of 32545 to it, then calls the dll function SendStringToPrinter.
We use the following methods per DLL Import: