Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Text File

Status
Not open for further replies.

UKmedia

Programmer
Nov 2, 2002
90
Hey All,

I have come to the concluesion with POS printing.

1. I cannot find any good OPOS examples
2. Printer function in I cannot get it to format the receipt within code proberly.
3. When printing from vb there is a 15sec delay before it will print.

So what I want to do is write the information to a txt file and send that txt file direct to the printer. But does anyone know where I can find a good example on how to format text when writting it to a txt file so I can align text and make txt bold, italic and so forth.

Cheers

UKmedia productions
 
Have you thought about creating a template Word document and updating that with your info then sending the Word doc to the printer?

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Text (ASCII) files are just plain text, you can not choose fonts, bold, etc. Basically, whatever you can do with NotePad is what you are limited to.

If you want rich-text, you need to send it through something that can create the formatting. Word is one option, if you have it. Otherwise you will need some sort of report engine (like Crystal reports). VB6 comes with a basic report engine (but it's pretty limited).

Joe Schwarz
Custom Software Developer
 
Have you tried the Printer Object

With Printer
.Font = "Garmond"
.FontBold = True
.FontItalic = True
.CurrentX = 0
.CurrentY = 0
.FontSize = 17
.ForeColor = vbBlue
' .TextHeight = 405

End With
 
Windows printers are GDI devices. The whole reason behind having Windows printer drivers is to map between GDI's native page description language and a specific printer's markup language. For simple printers this just becomes things like escape sequences around formatted data, etc.

This is why VB has the Printer object.

It's like using a disk device. You don't map data onto disk sectors, update directory blocks yourself, etc.
 
>Windows printers are GDI devices

Are you sure that you meant this?
 
You did mention OPOS and the printing conventions there are a bit different than those for "stndard" windows devices. Here's an example from the demo software provided by Epson.

Code:
Private Sub cmdPrint_Click()

    Dim ESC As String * 1
    Dim fDate As String

'Initialization
    ESC = Chr(&H1B)                                     'ESC command
    fDate = Format(Now, "mmmm dd, yyyy  AM/PM h:mm")           'system date

    With OPOSPOSPrinter1
    'print
        'Print address
        '   ESC|N = Normal char
        .PrintNormal PTR_S_RECEIPT, ESC + "|N" + "123xxstreet,xxxcity,xxxxstate " + vbLf
        'Print phone number
        '   ESC|rA = Right side char
        .PrintNormal PTR_S_RECEIPT, ESC + "|rA" + "TEL 9999-99-9999   C#2" + vbLf
        'Print date
        '   ESC|cA = Centering char
        .PrintNormal PTR_S_RECEIPT, ESC + "|cA" + fDate + vbCrLf + vbCrLf
        'Print buying goods
        .PrintNormal PTR_S_RECEIPT, "apples                  $20.00" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "grapes                  $30.00" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "bananas                 $40.00" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "lemons                  $50.00" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "oranges                 $60.00" + vbCrLf + vbCrLf
        'Print the total cost
        '   ESC|bC = Bold
        '   ESC|uC = Underline
        '   ESC|2C = Wide charcter
        .PrintNormal PTR_S_RECEIPT, ESC + "|bC" + "Tax excluded.          $200.00" + ESC + "|N" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, ESC + "|uC" + "Tax  5.0%               $10.00" + ESC + "|N" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, ESC + "|bC" + ESC + "|2C" + "Total   $210.00" + ESC + "|N" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "Customer's payment     $250.00" + vbCrLf
        .PrintNormal PTR_S_RECEIPT, "Change                  $40.00" + vbCrLf + vbCrLf

        'Feed the receipt to the cutter position automatically, and cut.
        '   ESC|#fP = Line Feed and Paper cut
        .PrintNormal PTR_S_RECEIPT, ESC + "|fP"
    End With

End Sub
 
>Windows printers are GDI devices

Are you sure that you meant this?
I'm pretty sure I did.

Printer Output

Printing Overview

There is also GDI+ printing, and of course there is the newer XML-based approach with XPS drivers as well. Though even via GDI there were "escape" options to allow passthrough of direct printer control sequences.

And then there are alternatives like OPOS and other methods to provide "direct" printer access or "raw" spooled printing.

But if the topic is OPOS most of that is off-topic anyway.
 
None of that turns any printer whatsoever into a GDI device (although there were attempts at GDI printer devices years back, and I guess there might be one or two around today).

A printer DC is simply a hardware abstraction. And sure, a printer DC is a GDI device. But the printer itself knows nothing about device contexts or GDI. The GDI commands to the DC are basically recorded in an EMF and then the EMF is played back through the printer driver which converts the GDI calls into the necessary native calls on the device such as PCL or PostScript.

(And I'm absolutely sure that you know all this; I just have problems with the phrase you used, as what I think you really meant was something more akin to "Windows printer device contexts are GDI devices")
 
Well I realize there can be confusion with the old "Win Printer" devices that had most of the page composition done within the host PC.

I suppose what I was getting at is that in Windows a printer is normally a "GDI device" in the same sense that a disk drive is a "filesystem device." So you use GDI operations to print unless you bypass the usual mechanism, just as you might to get sector-level access to a disk drive.

But perhaps the confusion comes more from the software concept of a "device" which is an abstraction presented to an application program. In the case of printers this abstraction is made precisely so applications don't need to know whether a printer speaks PostScript, PCL, or Epson escape sequences.

Thus to programs most printers in Windows are "GDI devices" - certainly in terms of the way VB's Printers collection and Printer object are used.


So I suppose it all comes down to what you think the word "device" refers to, which is contextual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top