|
-
Jan 19th, 2004, 11:29 PM
#1
Thread Starter
Lively Member
.NET PrintDocument -- sending raw text?
The .NET PrintDocument control is great if you want to convert your text into graphics and do fancy stuff with it, but what if you just want to send raw text to the printer and let it print using its own built-in fonts? I'm trying to print to a Samsung SRP-350 receipt printer. As far as I can tell, receipts don't need a whole lot of fancy formatting and graphical text manipulation.
Another issue is that to send a command to this printer (such as "cut receipt") you have to use a special "command font" and then specify a character in that font that tells the printer what to do. Here is an example from the SRP-350 Programmer's Reference that is written for VB6:
Code:
'Set up the control font.
Printer.FontSize = 9.5
Printer.FontName = "FontControl"
Printer.Print "P".
‘Use special-function character to cut the paper
‘P: Partial cut
‘g: Partial cut without paper feeding
Printer.EndDoc
How do I accomplish this in VB.NET? And for that matter, is there any .NET equivalent of the old VB6 Printer object?
Thanks.
-
Jan 19th, 2004, 11:31 PM
#2
Frenzied Member
Can't you just send the text via a shell?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 19th, 2004, 11:36 PM
#3
Thread Starter
Lively Member
I'm not sure how to do that. Can you give me an example? This is a POS program, so when the user clicks a button to close out an invoice, the receipt is automatically printed and then the printer should cut the receipt.
-
Jan 19th, 2004, 11:45 PM
#4
Frenzied Member
Well, I was thinking of using a shell command like Copy whatever > LPT1 but that was not a good idea.
The answer is here:
http://support.microsoft.com/default...;EN-US;Q322090
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 20th, 2004, 12:21 AM
#5
Thread Starter
Lively Member
Thanks, I'll give it a try. Looks like the optimal solution would be to use the standard .NET print document for the body of the receipt, and then use this "rawprinterhelper" class to send the control characters.
Only question I have now is about the printer settings -- especially the font. How do I change the font programatically using the rawprinterhelper class?
-
Jan 20th, 2004, 12:30 AM
#6
Frenzied Member
As the name implies it sends raw text to printer, so in this case I am not sure if there is a way to manipulate the printer font unless the printer has some codes that you can send to it as string before starting the main printing job.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 20th, 2004, 04:55 AM
#7
You will need to use the API to send raw text to the printer.
OpenPrinter, StartDoc, Endpage, EndDoc and ClosePrinter should do you.
-
Jan 21st, 2004, 01:23 AM
#8
Thread Starter
Lively Member
Any further clues on how to do that, or pointers to some good articles, would be greatly appreciated.
I tried using the rawprinterhelper class that Lunatic3 pointed me to, but I can't get it to do anything. Both of my printers do absolutely nothing when I try to send them something using it. One printer has a hexadecimal dump mode, so that it will print whatever incoming data it receives in a hex dump format, but it is apparently not getting anything from rawprinterhelper.
There are a lot of methods with rawprinterhelper, but no documentation on how to use them or clues on what the cryptic required arguments are. rawprinterhelper is a raw deal, if you ask me!
Any ideas?
-
Jan 21st, 2004, 06:31 AM
#9
Addicted Member
Import Old Com Object
You could import the VB6 Printer Object into VB.NET. If you are not sure on how to do that let us know.
-
Jan 21st, 2004, 02:33 PM
#10
Thread Starter
Lively Member
Sounds promising -- but I have no idea how to do it. Please advise.
Thanks,
Ken
-
Jan 21st, 2004, 03:45 PM
#11
Addicted Member
COM in .NET
Of course. All you need to do is add the reference under the COM tab in the Add Refernce dialog for your project.
When you add a reference to a COM object visual studio automatically generates the interop assembly for the object and places it in the projects /bin folder.
You will use the COM object the same way you do with .NET objects. For instances
VB Code:
.NET: Dim Circle as New Shape.Circle
COM: Dim Circle as New Shape.Circle
I couldnt tell you what DLL is the printer DLL that was built on COM. It doesnt appear to be named printer or microsoft printer so I cant help you find it, maybe someone else knows the dll name for it.
-
Jan 23rd, 2004, 12:06 PM
#12
Thread Starter
Lively Member
Can anyone offer a clue as to why rawprinterhelper does not seem to work on my machine? I analyzed the code in it and it is calling all the API calls that Merrion suggested. The method "sendstringtoprinter" returns true, indicating that it was successful. If I watch the printer window for the printer I am trying to print to, the print job appears, then quickly disappears, but there is not a stir from the printer. Seems like the print job is spooling but never being sent to the printer, even though EndDoc is called within the rawprinterhelper class. The code for rawprinterhelper can be found here.
I am running Windows XP Home -- could that be it?
-
Jan 23rd, 2004, 05:30 PM
#13
Frenzied Member
Just a thought: Check advanced properties of your printer and set it to print directly to printer, let me know if that helps.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|