How to see the data printed to a file

I created a "printer" that directs its output to a file. I look at the file in wordpad but I want to see a WYSIWYG view.

I need to write a series of reports and I do not want to kill a tree. I am looking into a Print Preview tool that would help, but I'd still like to be able to output print files and use them later.

I would also like to actually print some of these files, but how do I get the printer to understand that this is a printfile.

I have vague memories of a .prn file type.... Is there a viewer application (PrintViewer) of some kind? Or an option in Word or WordPad or....

I am hoping the answer is "Duh- just use BlahBlah" but if there is more to it I'll bump up the miserly 25 points.

Also, is there an easy way to default the outfile to clear and reuse the same print file each time?
Who is Participating?
inthedarkConnect With a Mentor Commented:
There is a simple answer emulate the printer object as a class module.  So here is some code which you can extened to meet your needs.

In the MyprClass you create all of the methods normally used in the printer. So in your report:

Dim MyPr as MyPRClass
Set MyPr = New MyPrClass

Instead of directly updating the printer you save the data to a file with a command for each operation.

You place a variable length command in the file but the trick is to prefix each command with a fixed length section to make read back simple.

You have to make some changes to you code but only small changes:

Printer.Line (10,20)- (30,40), RGB(10,20,30), BF




Public Sub Print(DataItem)

Redim Params(2)

SaveCommand Params,VarDataItem

End Sub

Public Sub Line(X1,Y1,X2,Y2,Color,BFParam)

Redim Params(6)
Params(0) = "LINE"
Params(1) = X1
Params(2) = Y1
Params(3) = X2
Params(4) = Y2
Params(5) = Color
Params(6) = BFParam

SaveCommand Params, ""

End Sub

Sub SaveCommand(Params, DataItem)

If MySpoolLfn<1 then
End if

HasFontChanged ' Call a sub that detects if font details have changed and saves a command first

dim CC as long
Dim Cmd as String

For CC=0 To UBound(Params)
    CMD = CMD + Cstr(Params(CC) + "|"
Next CC

' Rec is 10+Sep+4+Sep+Command+Data

Rec = format(len(CMD) + len(DataItem) + 16, "0000000000") + "|" + Format(Len(CMD),"0000") + "|" + CMD + DataItem

Put MySpoolLfn,Lof(MySpoolLfn)+1,Rec

End Sub

In the example above the numeric arguemnts are converted to strings.  But in graphics methods the picture to be printed will be a string of bytes.

To read back the file just get the first 16 bytes then you know how much to read:

Sub SpoolFile(PreView as Boolean, ZoomPercent)

zf = ZoomPercent / 100

If PreView Then
  Set PR  = frmDummy.picDummy
  Set Pr = Printer
End If


    If ps>Lof(MySpoolLFN) Then Exit Sub
    Get MySpoolLfn, PS, Rec
    BL = Val(Left(Rec,10)) ' Whole Length
    Rec = Space$(BL)
    Get MySpoolLfn, PS, Rec
    Process(Rec, Pr)


End Sub

Sub Process(Rec, Pr)

' First Extrct Params

ReDim Params(0) as string

TL = Val(Mid(Rec,1,10)) ' Whole length of record
CL = Val(Mid(Rec,12,4)) ' Length of Command

Params = Split(Mid(Rec,17, CL), "|")

DL = TL - CL - 16

If DL = 0 Then
    VarData = ""
    VarData = Mid(Rec, CL + 17)
End If

Select Case Ucase(Params(0))
    Case = "PRINT"
        Pr.CurrentX = Val(Params(1)) * zf
        Pr.CurrentY = Val(Params(2)) * zf
        PR.Print VarData;
    CASE = "LINE"
        X1 = Val(Params(1)) * zf
        Y1 = Val(Params(2)) * zf
        X2 = Val(Params(3)) * zf
        Y2 = Val(Params(4)) * zf
        Color = Val(Params(5))
        BFParam = Params(6)
        Select Case BFParam
           CASE = "BF"
              Pr.Line (X1,Y1) - (X2, Y2), Color, BF
        End Select
    Case = "FONT"
        Pr.Font.Name = Params(1)
        Pr.Font.Size = Val(Params(1))  * zf
        Pr.Font.Bold = Val(Params(1))
End Select

End Sub

I will leave you to do the rest, it is not rocket science.
wizard61Author Commented:
After looking at this for a while, I left wishing I had the time to spend making something nice.

Is there a 3rd party ocx that anyone can suggest for this?
Hi wizard61,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept inthedark's comment(s) as an answer.

wizard61, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
DanRollins -- EE database cleanup volunteer
Moving to the Paq

Experts Exchange Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.