Forum > General

Printer Paper Orientation

<< < (2/4) > >>

paweld:
Instead of writing print and preview support from scratch, you can use ready-made components, such as fpReport. Sample in attachement.

J-G:

--- Quote from: paweld on August 15, 2022, 09:12:33 am ---Instead of writing print and preview support from scratch, you can use ready-made components, such as fpReport. Sample in attachement.
--- End quote ---
Hmmm...  I don't think so.

When I selected a 180k .png file it took over a minute (I'm guessing :) ) to show a blank 'preview' --- the 'image' appeared a little while later but 'draging' the preview about the screen was equally lethargic and even stopped all other mouse activity.

My 'preview' only needs to show the area that the final image will take up and it has to be 'dynamic' - ie. changing with each minor modification to the data.

The attached ScreenGrab shows two results - one Portrait the other View -  I've added the yellow box after taking the grab to indicate the part of the display that will actually be sent to the printer. The preview is just a TMemo on a TPanel but I may change that and draw a box on the panel since I don't see a way to add a border to the TMemo. In real life the memo outline can be seen but it's rather weak.

I suspect that trying to understand fpReport would take me vastly longer than writing the Print Code from scratch -- and of course I'll understand my own code  ::)

J-G:
I'm somewhat further forward, having three operational buttons to [Print], [Page Setup] & [Select Printer] but there is still an action which is eluding me.

I'm using the code :

--- 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";}};} ---procedure TForm1.PrintImgClick(Sender: TObject);  procedure PrintDescription;  begin    PrintCentrePage(10,Desc,1,16,1);  end;   procedure PrintTooth;  begin   end; begin  with Printer do   try     BeginDoc;     if P_Orient = 'P' then       Orientation := poPortrait     else       Orientation := poLandscape;      PrintDescription;//     PrintTooth;   finally     EndDoc;   end;end;to create the print   -  I haven't yet coded 'Print Tooth' as you can see, I'm just testing that the 'Description' prints at top centre which it does IF the Page Setup is in the correct orientation. That is lines 15 to 19 have no effect.

Using that same code in the [Page Setup] proc  - - - -

--- 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";}};} ---procedure TForm1.SetupClick(Sender: TObject);begin  if P_Orient = 'P' then    Printer.Orientation := poPortrait  else    Printer.Orientation := poLandscape;   PageSetup.Execute;end;
... correctly sets the orientation but only if I use that button each time. I would have expected that to be sufficient to make the approriate change in Code.  It seems wrong to need to insert 'PageSetup.Execute;' at Line 20 which would open the Dialogue every time.

It's useful to have the option to change the page size etc. using the [Page Setup] but it surely shouldn't be necessary to enter that dialogue explicitly when there is the facility to set 'Orientation' via code.

I've tested [Select Printer]  - ie. I can change the printer in use -- and that works   -  as long as the orientation has been set with similar code in the [Select Printer] Proc.

I must be missing a 'magiic bullet' of some kind but can't see what or where yet  :(





paweld:
Perhaps the attached example will help you.

J-G:

--- Quote from: paweld on August 16, 2022, 10:19:10 pm ---Perhaps the attached example will help you.
--- End quote ---
Thanks for your efforts @paweld. That's certainly an interesting program but I don't think it addresses my problem.

I work out whether the orientation needs to be Portrait or Landscape according to the height & width of the gear tooth  -  the object to be plotted  -  without overtly selecting the orientaion by use of a [button].

It seems reasonable (to me) that using the Printer.Orientaion := poXXXXXX  should do just that and I can't see what I need to do to make that so.

Working on a bitmap and selecting any part thereof is one thing but you still set the orientation by use of the RadioButtons.  If you determined the orientation according to the shape selected  that is; if the selection is taller than it is wide then the orientation should be set to poPortrait but if the selection is wider than it is tall then the orientation should be poLandscape -  if you could then set it without recourse to the RadioButtons you would be much closer to my problem.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version