Results 1 to 13 of 13

Thread: .NET PrintDocument -- sending raw text?

  1. #1

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96

    .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.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  3. #3

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    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.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  5. #5

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    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?

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  7. #7
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    You will need to use the API to send raw text to the printer.
    OpenPrinter, StartDoc, Endpage, EndDoc and ClosePrinter should do you.

  8. #8

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    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?

  9. #9
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160

    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.
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  10. #10

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    Sounds promising -- but I have no idea how to do it. Please advise.

    Thanks,
    Ken

  11. #11
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160

    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:
    1. .NET: Dim Circle as New Shape.Circle
    2.  
    3. 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.
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  12. #12

    Thread Starter
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96
    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?

  13. #13
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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
  •  



Click Here to Expand Forum to Full Width