|
Icetips Article
Back to article list
Search Articles
Add Comment
Printer friendly
Direct link
Par2: Print directly to printer
2003-12-08 -- Bjarne Havnen
If you don't need that much format, it is pretty easy to print line by line
to a printer. The following takes an ascii file, opens, reads and prints
each line to the printer. Pretty easy to modify to i.e. a queue of data. It
may be a problem with ascii vs. printerfonts regarding special characters.
(Norwegian characters æoå I had to translate differently for different
printers.)
!Global map
Module('win32')
openprinter(*cstring,*unsigned,ulong),bool,pascal,raw,name('openprintera')
startdocprinter(unsigned,byte,*doc_info_1),bool,pascal,raw,name('startdocpri
ntera') !*
enddocprinter(unsigned),bool,pascal,raw
writeprinter(unsigned,string,long,*long),bool,pascal,raw
startpageprinter(unsigned),bool,pascal,raw
endpageprinter(unsigned),bool,pascal,raw
closeprinter(unsigned),bool,pascal,raw
End
!Global data
DOC_INFO_1 GROUP ,Type
pdocname Long
poutputfile Long
pdatatype Long
END
The procedure
PrintAsciiApi PROCEDURE (String pFilename,) !
Declare Procedure
! Beginning of "Data Section"
! [Priority 5000]
OutputFile File,Driver('Ascii'),Pre(Out)
Record Record
Line String(500)
End
End
BytesWritten Long
skriver Cstring(50)
HPRINT Unsigned
pInfo Group(Doc_Info_1),Pre(pinfo)
End
pDocname cstring(20)
pDatatype Cstring(10)
pOutputFile cstring(20)
Uttekst Like(Out:Line), Over(Out:Line)
! End of "Data Section"
CODE ! Begin processed code
! Beginning of "Processed Code"
! [Priority 5000]
pDocname='PrintAscii'!'!My documen'
pdatatype='RAW'
pOutputfile=''
!
pInfo.pDocname = Address(pdocname)
Pinfo.pDatatype = Address(pDatatype)
pinfo.pOutputfile =Address(pOutputfile)
If Omitted(2) Or Not pSkriver
If PrinterDialog('Print '&pFilename)
Skriver=Printer{Propprint:Device}
Else
Return
End
Else
Skriver = pSkriver
End
If Not OpenPrinter(Skriver,hPrint,0)
!something wrong
Message('Open printer fails')
Return
End!if
! Info:pDatatype=testvar
If startdocprinter(hprint,1,pinfo) <=0
!sometthing wrong
Message('StartDoc printer fails '&GetLastError())
R#=ClosePrinter(hprint)
Return
End
If Not StartPagePrinter(hPrint)
Message('Start page printer fails'&GetLastError())
R#=EndDocPrinter(hprint)
R#=ClosePrinter(Hprint)
Return
End!if
OutPutFile{Prop:Name}=pFilename
Open(OutputFile)
If Errorcode()
Message(Error())
End
Set(Outputfile) !position to begyinn
Loop
Next(OutputFile)
If Errorcode() Then Break.
Out:Line=Clip(Out:Line)&'<13,10>'
If
WritePrinter(HPrint,Out:Line,Len(Clip(Out:Line))+2,BytesWritten)=False
!something wrong
Message('Write printer fails')
Break
Else
End
End!loop
Close(Outputfile)
ret#=endpageprinter(hprint)
ret#=enddocprinter(hprint)
ret#=closeprinter(hprint)
CLEAR(HPRINT)
Today is November 21, 2024, 8:33 am This article has been viewed 35318 times.
Back to article list
Search Articles
Add Comment
Printer friendly
|
|
|