Re: Printing to a printer

new topic     » goto parent     » topic index » view thread      » older message » newer message

Craig Welch wrote:
> 
> 
> I'm trying to print a sequence (using printf, pretty print, print)
> to a printer (as opposed to standard output or a file).
> 
> The relevant code is:
> ============================================================
>         result = getPrinter()
>         if length(result) then
>     	   dummy = startDoc( "job" )
> 	   dummy = startPage()
>            pretty_print(Printer, kanji, {1,3,1,78,"%x"})
>            -- or print, or puts, or whatever
> 	   dummy = endPage()
> 	   dummy =  endDoc()
> 	   releasePrinter()
>   	end if
> ============================================================
> This brings up a printer dialogue, at which I have tried selecting
> different printers, or leaving it at the default printer. So far, so good.
> The output is created, and it appears as I would expect it to.
> 
> Only thing is, despite the printer ejecting a blank page, the output 
> doesn't go to the printer ... it goes to a DOS window ("standard output")
> as if I had said print(1, kanji).
> 
> Any ideas?

Sure. Firstly, pretty_print only works for output to DOS files, and that
includes the console 'files' STDOUT and STDERR. This means that the first
parameter to pretty_print MUST be a DOS file handle. 

Secondly, in Win32lib, the Printer has been allocated the Control Id value
of one (1). This is arbitary and might change with different releases. But
for now, it means that 'pretty_print(Printer, ...)' is the same as
'pretty_print(1, ...)' which is, of course, the STDOUT DOS file handle
(the screen).

To fix this, that is to send output to a WINDOWS printer, you need to do
it a whole other way. 

In Windows, you must think of printing in terms of Page Printing. That is,
you build up what your page is going to look like, then send that to the 
printer. This the idea behind the startPage() and endPage() routines.

You call startPage() for each new page. This prepares a new page area in
memory. You then need to 'draw' your text and lines and images on the page
using the normal wPuts(), drawText(), drawLine(), etc... calls. For each
of these you need to be aware of where the 'cursor' for the next page
drawing command will be. You probably should set the position
explictly before each drawing command. This will involve you calculating
the X/Y position based on the current font, line thickness, image size,
and printer-pixels per inch, etc... Note that you do NOT have to start
from the top left-hand edge and work across/down the page. You can draw
stuff anywhere on the page, even overlapping stuff already drawn.

After you have built up you page, the endPage() routine sends it to the
printer.

The endDoc() routine tells Windows that the document is complete and the
spooler can release the job to the physical printer.

Easy, no?

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu