Recent

Author Topic: Printer Paper Orientation  (Read 2296 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Printer Paper Orientation
« Reply #15 on: August 17, 2022, 03:32:21 pm »
Attached to the previous post are the modified sources from which I removed the RadioGroup control.
Ah... apologies  -  I saw the reference to RadioGroup and made incorrect assumptions  :-[
Quote from: paweld
In Printer.Title you specify the name of the report, not the name of the target PDF file.
Look in the attached example, in my case the report title is passed to the PDF printer every time.
That is exactly what I'm doing  -  ???

Your latest code works exactly as I wish and I can follow the logic which is exactly the same as mine - albeit more robust and handling bitmaps -  I've now written a small project (,ZIP Attached) which only deals with the creation of a box which can be modified and the orientation evaluated from the size created.  The size is adjusted dynamically using two TTrack Components. I haven't included tests to limit the dimensions other than they can both be between 1 & 297.

This still leaves the Printer.orientation and the filename untouched so shows exactly what I'm not getting.

It doesn't have 'SetAutoPageOrientation' and I can't see anything in your Code/Form which allows me to create such an [Event]  -  I can see that it is in the 'Public' section but I can't see it in the [Events] of any of your components. I have no idea how you created it so I can't (as yet) add it into my code for testing.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

paweld

  • Hero Member
  • *****
  • Posts: 966
Re: Printer Paper Orientation
« Reply #16 on: August 17, 2022, 05:23:06 pm »
'SetAutoPageOrientation' procedure is called each time the preview generate
Best regards / Pozdrawiam
paweld

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Printer Paper Orientation
« Reply #17 on: August 17, 2022, 05:48:46 pm »
'SetAutoPageOrientation' procedure is called each time the preview generate
I can see that  -  what I can't see is how the procedure/event is created.

It's surely not simply 'typed' in?

Hmmm....  it is !!       since the Proc started 'TForm1.',   I had assumed that it was created by clicking on the [...] of an [Event] but I've just typed it into my test project and added the If...Then...Else structure - - - - which was already being called at each [Print]  - - - -  the project compiled without problem but it's had no effect on the problem so that isn't the solution.

Have you seen the result provided by my test project?  Do you get the same result?  ie. no filename at first run and orientation not being set.





FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

paweld

  • Hero Member
  • *****
  • Posts: 966
Re: Printer Paper Orientation
« Reply #18 on: August 17, 2022, 07:53:28 pm »
Move the print name and page orientation setting before calling BeginDoc;, and it will work, ie
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PrintImgClick(Sender: TObject);
  2. Var
  3.   W : word;
  4. begin
  5.   with Printer do
  6.    try                      
  7.      Title := F_Name+'.PDF';
  8.      if P_Orient = 'P' then
  9.        Orientation := poPortrait
  10.      else
  11.        Orientation := poLandscape;
  12.      BeginDoc;
  13.      with Canvas.Font do  
  14.   ...
instead of
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PrintImgClick(Sender: TObject);
  2. Var
  3.   W : word;
  4. begin
  5.   with Printer do
  6.    try
  7.      BeginDoc;
  8.      Title := F_Name+'.PDF';
  9.      if P_Orient = 'P' then
  10.        Orientation := poPortrait
  11.      else
  12.        Orientation := poLandscape;
  13.      with Canvas.Font do
  14.   ...
Best regards / Pozdrawiam
paweld

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Printer Paper Orientation
« Reply #19 on: August 17, 2022, 08:23:50 pm »
Move the print name and page orientation setting before calling BeginDoc;, and it will work,

D'oh!   --   I said that I must be missing a 'Magic Bullet'  !!

That's a day of both our lives that we won't get back  :D

However I have certainly learned quite a bit, and it may be that someone doing a search on this forum in the future may stumble across this answer which might save them some head-scratching.

Thanks for your efforts and tremendous patience in the face of my inability to really see how your Code differed from mine. I have spent the past hour going through not only your code line by line but even the settings of some of the components in the vain hope that I might see some difference.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018