Board index » delphi » Q: Easier printing on printer.canvas regardless of printer type

Q: Easier printing on printer.canvas regardless of printer type

I want to divide the printpage into standard rows and columns, as you
would on a Courier 10 typewriter. Then I want to say "at this row, at
this column print these characters".

The user might have a dot-matrix, laser or inkjet printer attached, so
I cannot rely on printer control codes (passthrough command). I know
you can paint on the printer.canvas, but how do I make it "standard"
so it works for absolutely any printer.

Report Smith is much too complicated for my simple purpose, I would
think. The text just has to come out approximately where I ask it
regardless of printer type.

I want to design a simple user function which translates as: At Row,
Col print "MyText", where a page has a standard 63 lines down and 80
characters across, like a "normal" page of A4. I also need a command
that will do a page eject regardless of printer type.

I have never done this under Windows, I'd appreciate any tips.

Email appreciated. I respond to every email.
Matthew

 

Re:Q: Easier printing on printer.canvas regardless of printer type


Matthew <Com...@lottery.powernet.co.uk  > wrote in article
<5hlp9d$ha...@power2.power.net.uk>...

Quote
> I want to divide the printpage into standard rows and columns, as you
> would on a Courier 10 typewriter. Then I want to say "at this row, at
> this column print these characters".
> ...

First you should use GetDeviceCaps API call to get the physical resolutioin
of your printer (ie dots per row/column). Then the task is easy, there
remains no philosophy, only mathematics. You divide dots per column/row
with number of characters you wish to appear in certain row/column and get
the constant that should multiply with character position of each character
in your text. This is theory, right now I have no time to write out on
example, but I will send the example to you if you wish.

Quote
> I also need a command that will do a page eject regardless of printer
type.

You do it simply by calling the NewPage method in your code. If you don't
know how, I'll send you some example.

Quote
> I have never done this under Windows, I'd appreciate any tips.

Hope this will help you a bit. If you read some examples instead of tips,
I'll send it to you. But remeber, first try making it yourself by trying
this, you'll feel much better when you achieve the result yourself, than if
I helped you. But I'm here to help!

Best regards!

--
-----------------------------------------
Vjekoslav Babic
Zagreb, Croatia

alv...@urgentmail.com
vjeba...@jagor.srce.hr
http://jagor.srce.hr/~vjebabic    - still under construction, sorry

Re:Q: Easier printing on printer.canvas regardless of printer type


Quote
Com...@lottery.powernet.co.uk  (Matthew) wrote:
>I want to divide the printpage into standard rows and columns, as you
>would on a Courier 10 typewriter. Then I want to say "at this row, at
>this column print these characters".
>>> snip <<<

Hi Matthew.

I have some code in different applications that prints label-sheet,
tab-separated columns, normal text-pages with headers/footers and
so on.

If you dont find any other hints, then mail me whith a litle more
specific description of what you want to print, and I will try to
find some codesnip to you.

---------------------------------------------
  Ove Kjeldgaard
    !o_kj...@post4.tele.dk
      Remove the ! if you wish to e-mail me
---------------------------------------------

Re:Q: Easier printing on printer.canvas regardless of printer type


In article <01bc3d26$009a6020$9be21dc3@default>

Quote
"Vjekoslav Babi?" <alv...@urgentmail.com> wrote:
> First you should use GetDeviceCaps API call to get the physical resolutioin
> of your printer (ie dots per row/column). Then the task is easy, there
> remains no philosophy, only mathematics. You divide dots per column/row
> with number of characters you wish to appear in certain row/column and get
> the constant that should multiply with character position of each character
> in your text. This is theory, right now I have no time to write out on
> example, but I will send the example to you if you wish.

This works great for text output.
I have to print graphics, too.
I think it is a bad idea to write a draw procedure which draws the graphics in
dependance from the printer resolution. So I paint the graphis to a PaintBox
and do a copyrect from paintbox.canvas to printer.canvas.
So far my method works great for dot-matrix printers.
But it does not at all work for laser or inkjet printers - the copyrect
does nothing, the area of the graphics is empty.

To check this out, create a form with only a button and a paintbox.
Add this procedurtes:
--------
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  with paintbox1.canvas do
    textout(100, 100, 'text written to paintbox');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  dest: trect;
begin
  with Printer do
  with Canvas do
  begin
    BeginDoc;
    CopyRect(Rect(0, 0, paintbox1.width, paintbox1.height), paintbox1.canvas,
                   Rect(0, 0, paintbox1.width, paintbox1.height));
    textout(400, 400, 'Text written directly to printer.canvas');
    enddoc;
  end;
end;
-------

If I set the standard printer to a dot-matrix, both lines of text get printed.
If I set the standard printer to a laser or inkjet, only one line of text gets printed.

Is there anybody with any ideas why it works only with some printers?

Frank Heyne
http://rcs.urz.tu-dresden.de/~fh/

Re:Q: Easier printing on printer.canvas regardless of printer type


Quote
Frank Heyne wrote:

> In article <01bc3d26$009a6020$9be21dc3@default>
> "Vjekoslav Babi?" <alv...@urgentmail.com> wrote:

> > First you should use GetDeviceCaps API call to get the physical resolutioin
> > of your printer (ie dots per row/column). Then the task is easy, there
> > remains no philosophy, only mathematics. You divide dots per column/row
> > with number of characters you wish to appear in certain row/column and get
> > the constant that should multiply with character position of each character
> > in your text. This is theory, right now I have no time to write out on
> > example, but I will send the example to you if you wish.

> This works great for text output.
> I have to print graphics, too.
> I think it is a bad idea to write a draw procedure which draws the graphics in
> dependance from the printer resolution. So I paint the graphis to a PaintBox
> and do a copyrect from paintbox.canvas to printer.canvas.
> So far my method works great for dot-matrix printers.
> But it does not at all work for laser or inkjet printers - the copyrect
> does nothing, the area of the graphics is empty.

> To check this out, create a form with only a button and a paintbox.
> Add this procedurtes:
> --------
> procedure TForm1.PaintBox1Paint(Sender: TObject);
> begin
>   with paintbox1.canvas do
>     textout(100, 100, 'text written to paintbox');
> end;

> procedure TForm1.Button1Click(Sender: TObject);
> var
>   dest: trect;
> begin
>   with Printer do
>   with Canvas do
>   begin
>     BeginDoc;
>     CopyRect(Rect(0, 0, paintbox1.width, paintbox1.height), paintbox1.canvas,
>                    Rect(0, 0, paintbox1.width, paintbox1.height));
>     textout(400, 400, 'Text written directly to printer.canvas');
>     enddoc;
>   end;
> end;
> -------

> If I set the standard printer to a dot-matrix, both lines of text get printed.
> If I set the standard printer to a laser or inkjet, only one line of text gets printed.

> Is there anybody with any ideas why it works only with some printers?

> Frank Heyne
> http://rcs.urz.tu-dresden.de/~fh/

CopyRect will not work on most printers. You need to use
StretchDiBits(). An example can be found at our web site. ou need
technical document:

Ti3155 - A Better Way To Print a Form

Joe
--
Joe C. Hecht
Borland Delphi Developer Support Group
Technical Documents and Online Forums are available at
http://www.borland.com

Other Threads