Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change print.orientation

96 views
Skip to first unread message

Jens Reinhardt

unread,
Dec 15, 2000, 11:58:17 AM12/15/00
to
Hi,

I wonder if there is a simple way to switch print orientation
(poLandscape, poPotrait) inside a Printer.BeginDoc-Printer.EndDoc
environment, such that I can give each page its individual orientation
as needed.

Or even better: A simple way of printing text horizontally as well as
vertically on the same page.

Thanks for any suggestion

Jens


Woody

unread,
Dec 15, 2000, 6:59:05 PM12/15/00
to
The BeginDoc/EndDoc functionality does not allow page orientation
changes on the fly. However, my PrintDrv component does allow you to
rotate text to any degree when printing among other many wonderful
things. It's free and you can get it at Torry's or the DSP if you want
to try it out. Download it and look at the demo program with it. You
might like it.

Woody

--
--------------------------------------------------------------
"AlGoreithm (al-gor-ith-m): A mathematical calculation performed
repeatedly
until a prior desired result is produced."
----------------------------------------------------------------

"Jens Reinhardt" <jrein...@foni.net> wrote in message
news:3A3A4DA9...@foni.net...

Peter Below (TeamB)

unread,
Dec 16, 2000, 12:38:29 PM12/16/00
to
In article <3A3A4DA9...@foni.net>, Jens Reinhardt wrote:
> I wonder if there is a simple way to switch print orientation
> (poLandscape, poPotrait) inside a Printer.BeginDoc-Printer.EndDoc
> environment, such that I can give each page its individual orientation
> as needed.

procedure TForm1.Button2Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
pDevMode: PDeviceMode;
begin
With Printer Do Begin
BeginDoc;
try
Canvas.font.size := 20;
Canvas.font.name := 'Arial';
Canvas.TextOut( 50, 50, 'This is portait');
GetPrinter(Device, Driver, Port, hDeviceMode);
pDevMode := GlobalLock( hDevicemode );
With pDevMode^ Do Begin
dmFields := dmFields or DM_ORIENTATION;
dmOrientation := DMORIENT_LANDSCAPE;
End;
{ Cannot use NewPage here since the ResetDc will
only work between EndPage and StartPage. As a consequence
the Printer.PageCount is not updated. }
Windows.EndPage( Printer.Handle );
If ResetDC( canvas.Handle, pDevMode^ ) = 0 Then
ShowMessage( 'ResetDC failed, '+SysErrorMessage(GetLastError));
GlobalUnlock( hDeviceMode );
Windows.StartPage( Printer.Handle );
Printer.Canvas.Refresh;
Canvas.font.size := 20;
Canvas.font.name := 'Arial';
Canvas.TextOut( 50, 50, 'This is landscape');
finally
EndDoc;
end;
End;
end;

>
> Or even better: A simple way of printing text horizontally as well as
> vertically on the same page.

You can rotate fonts (true-type fonts only) using API functions.

procedure TForm1.Button3Click(Sender: TObject);
var
lf: TLogfont;
begin
with printer do begin
begindoc;
canvas.font.Name := 'Arial';
canvas.font.Size := 24;
canvas.textout( 100, 100, 'Das ist normaler Text' );
GetObject( canvas.font.handle, Sizeof(lf), @lf);
lf.lfescapement := 450;
lf.lforientation := 450;
Canvas.Font.handle := CreateFontIndirect( lf );
canvas.TextOut( 100, 1500, 'Das ist gedrehter Text');
Canvas.Font.Handle := 0;
EndDoc;
end;
end;

Text placement can be bit tricky with rotated fonts.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so be
patient if i don't reply immediately.

ronald...@gmail.com

unread,
Sep 12, 2013, 6:30:17 AM9/12/13
to
Great post!

I've modified to code a bit and added a hack to modify the FPageNumber of the TPrinter class objects.

PLEASE NOTE: this has only been tested on Delphi XE2 - when the original TPrinter class differs in the first part (until FPageNumber), then one needs to modify the THackPrinterPageNumber class accordingly!

----

{$IFDEF VER230} // Delphi 2012 XE2 - Win32/win64
THackPrinterPageNumber = class(TObject)
private
FCanvas: TCanvas;
FFonts: TStrings;
FPageNumber: Integer; // We need to access this private variable
end;
{$ENDIF}
// RH: hack into the TPrinter object and increment FPageCount
Inc(THackPrinterPageNumber(Printer).FPageNumber);
0 new messages