Board index » delphi » set printer margins?

set printer margins?

In this procedure writeln() is used to send output to a printer. The
problem is that the left and top margin are to small (10mm).
With "OffsetWindowOrg(Printer.Canvas.Handle, -200, -200)" the margins
of the first page are wide enough (20mm), but on following pages
margins are to small again. Is there a possibilty to set the margins
fixed to 20mm?

procedure TDlgGrid.ButtonPrintClick(Sender: TObject);

var iField: integer;
    F: TextFile;
    bm: TBookmark;
    BlobStream: TBlobStream;
    Buffer: Array[0..255] of Char;
    BytesRead: Byte;

begin

AssignPrn( F );

Rewrite(F);

OffsetWindowOrg(Printer.Canvas.Handle, -200, -200);

Writeln(F, caption);

Writeln(F);

With DBGridSource.datasource.dataset do try

     screen.cursor := crHourGlass;

     bm := GetBookmark;

     disableControls;

     first;

     while not eof do begin

     for iField := 0 to FieldCount - 1 do begin
         if Fields[iField].DataType <> ftMemo then
            Writeln(F, Copy( Fields[iField].text )
         else
            try
            Writeln(F);
            BlobStream :=
TBlobStream.Create(TMemoField(Fields[iField]), bmRead);
            repeat
            BytesRead := BlobStream.Read(Buffer, 255);
            Buffer[BytesRead] := Chr(0);
            write( F, buffer );
            until ( BytesRead = 0 );

            finally
            BlobStream.free;
            Writeln(F);
            end;

      end;

      Writeln(F);

      next;

      end; {not eof}

finally

     GotoBookmark(bm);

     FreeBookmark(bm);

     enableControls;

     screen.cursor := crDefault;

end;   {with datasource}

CloseFile(F);

end;

 

Re:set printer margins?


As I understand it, you have to call OffsetWindowOrg every time the printer
starts a new page.

I don't know how you detect this event when you are using AssignPrn. If you
want more control over the printing process, you might be better off writing
to the Printer.Canvas using TextOut, which lets you specify the co-ordinates
of the text.

--
Stephen Brown
sbr...@sprocket.win-uk.net

Quote
Rene wrote in message <35fc2cf6.10470...@netnews.uci.kun.nl>...
>In this procedure writeln() is used to send output to a printer. The
>problem is that the left and top margin are to small (10mm).
>With "OffsetWindowOrg(Printer.Canvas.Handle, -200, -200)" the margins
>of the first page are wide enough (20mm), but on following pages
>margins are to small again. Is there a possibilty to set the margins
>fixed to 20mm?

Re:set printer margins?


On Mon, 14 Sep 1998 02:05:21 +0100, "Stephen Brown"

Quote
<sbr...@sprocket.win-uk.net> wrote:
>As I understand it, you have to call OffsetWindowOrg every time the printer
>starts a new page.

>I don't know how you detect this event when you are using AssignPrn. If you
>want more control over the printing process, you might be better off writing
>to the Printer.Canvas using TextOut, which lets you specify the co-ordinates
>of the text.

The reason I used AssignPrn has something to do with this piece of the
routine:

try

 Writeln(F);

 BlobStream:=TBlobStream.Create(TMemoField(Fields[iField]),bmRead);

 repeat
  BytesRead := BlobStream.Read(Buffer, 255);
  Buffer[BytesRead] := Chr(0);
  write( F, buffer );
  until ( BytesRead = 0 );

  finally
            BlobStream.free;
            Writeln(F);
  end;

When textout() is used you have to retrieve one line from the
memofield at a time and I don't know how to do this. The problems are
of cause that not all lines have the same lenght and lines can be
longer than the width of a page.
(I the routine I currently use DBMemo.lines[x] is used, but I want to
rewrite the routine without this component)

Any suggestions how to solve this problem?

Quote
>Rene wrote in message <35fc2cf6.10470...@netnews.uci.kun.nl>...
>>In this procedure writeln() is used to send output to a printer. The
>>problem is that the left and top margin are to small (10mm).
>>With "OffsetWindowOrg(Printer.Canvas.Handle, -200, -200)" the margins
>>of the first page are wide enough (20mm), but on following pages
>>margins are to small again. Is there a possibilty to set the margins
>>fixed to 20mm?

Re:set printer margins?


I've just been making a component that encapsulates a number of printing
routines, like setting margins, fonts, left, centre and right justification,
word wrapping, printing columns and tables, etc.

I haven't finished testing and documenting it yet, but if you want to give
it a try let me know and I'll send you the source code (D2) and some notes
on how to use it.

--
Stephen Brown
sbr...@sprocket.win-uk.net

Quote
Rene wrote in message <35fd7762.1048...@netnews.uci.kun.nl>...
>The reason I used AssignPrn has something to do with this piece of the
>routine:

Snipped..
Quote
>When textout() is used you have to retrieve one line from the
>memofield at a time and I don't know how to do this. The problems are
>of cause that not all lines have the same lenght and lines can be
>longer than the width of a page.

Other Threads