Reputation: 6988
I need to send content to printer in C# .NET the same way as PRINT
command does.
I have Godex thermal printer with QLabel software bundled. Now it has the option to save the label as a command that you can pass to printer with command prompt PRINT
command. The file looks like this:
^Q80,3
^W100
^H10
^P1
^S3
^AD
^C1
^R2
~Q+0
^O0
^D0
^E35
~R200
^L
Dy2-me-dd
Th:m:s
AH,0,0,1,1,0,0,X
AH,744,0,1,1,0,0,X
AH,746,560,1,1,0,0,X
AH,0,550,1,1,0,0,X
AG,160,208,1,1,0,0,
AA,234,283,1,1,0,0,Haloo
E
That works when i do something like this:
net use LPT2 \\localhost\godexUsbPrinter /yes
print /D:LPT2 label.cmd
And it prints my label out nicely.
Now, if i open this in notepad and print, it just prints me this text.
I wonder what does PRINT
command do under the hood and how can i program my C# based program to replicate the behaviour? Because when i implement printing logic, it just prints me the plain text as notepad does.
I know i could call a PRINT
command with Process.Start from C#, but i need to replace some placeholder value in the label template all the time. I could create a temporary file on the disk and print that, but i would prefer to avoid such a scenario.
Upvotes: 5
Views: 851
Reputation: 151604
To be honest, the question title is the wrong way around. PRINT
doesn't do anything spectalular at all, it just flushes all its input to the printer. It's Notepad that, through Windows' print system, sends various commands for paging and line endings and whatnot and eventually the data you want to print. The code you show is raw printer data, so you'll have to send it 'raw' and not as text. So technically it's a duplicate of this question.
How to do so is explained here. It's using P/Invokes to winspool.Drv
.
Upvotes: 4