Forum > General

Printer Paper Orientation

(1/4) > >>

I've used Printers4Lazarus to great effect in the past but never had the need to change from 'Portrait' to 'View'. With my current Project this has become necessary so I've reviewed the Wiki page 'Using the printer' along with the 'Printers' Unit. The former makes no reference to changing the orientation and although I do find a reference to SetOrientation (and Get...) in the Unit, I'm not having any joy in impementing a change.

Using the 'auto-complete' facility, I can access the property - Printer.SetOrientation - which requires a 'Value' which I assume may be 0 or 1 or something else entirely, but the compiler returns an 'Identifier not found' for SetOrientation() or a wierd (to me) 'Syntax error, "EXCEPT" expected but "(" found' if I reduce that to 'Orientation'.

The first error seems most peculiar when auto-complete offers the property.

Whilst I would be interested (academically) in the reasons behind the error messages, what I really want to know is how do I set the paper orientation?

A secondary question though is  how can I invoke the Printer Set Up Dialogue or the Page Set Up Dialogue?  both of which I have placed on the form but the [Events] associated with them don't have [OnClick]  -  I have to assume that a third party component (with [On Click]) is needed but can't yet fathom how I can link the two.

A positive answer to this secondary question may well mean that the first question becomes irrelevant!


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  Printers; procedure TForm1.Button1Click(Sender: TObject);begin  //run printer dialog  ShowMessage('Current printer: ' + Printer.PrinterName);  if PrintDialog1.Execute then    ShowMessage('Printer changed to: ' + Printer.PrinterName + #13#10 +      ' and number of copies set to: ' + IntToStr(Printer.Copies));end; procedure TForm1.Button2Click(Sender: TObject);const  poarr: array [TPrinterOrientation] of String = ('portait', 'landscape', 'reverse portait', 'reverse landscape');begin  //run page setup dialog  ShowMessage('Current orientation: ' + poarr[Printer.Orientation]);  if PageSetupDialog1.Execute then    ShowMessage('Orientation changed to: ' + poarr[Printer.Orientation] + #13#10 +      ' and paper size: ' + Printer.PaperSize.PaperName);end; procedure TForm1.Button3Click(Sender: TObject);begin   //change paper orientation  if Printer.Orientation = poPortrait then    Printer.Orientation := poLandscape  else    Printer.Orientation := poPortrait;end;          

!! @ paweld !!

On opening your reply I was at first somewhat taken aback

- just code without explanation ??

... but it didn't take me long to appreciate that it is a most succinct but fullsome reply providing all the answers I could want !

I'll have to do some testing and 'adjustment' but that's all the better since (hopefully) I'll learn so much more.

Many thanks.

Hi @J-G,My written English is not very good, and often sample code with short comments will help you understand more than the description.


--- Quote from: paweld on August 14, 2022, 11:17:37 pm ---Hi @J-G,My written English is not very good, and often sample code with short comments will help you understand more than the description.
--- End quote ---

It's vastly superior to my Polish!!   :D

I haven't done much work on it yet, I've spent most of this evening working out how to show a 'Print Preview'  -  just showing the size of the final image within and A4 outline --  which I think I cracked about half-an-hour ago.  It can determine whether to use Portrait or View Orientation so will be used when I come to code the actual Print routine.


[0] Message Index

[#] Next page

Go to full version