Recent

Author Topic: [SOLVED] Simple (I hope) question  (Read 1459 times)

SteveSS

  • New Member
  • *
  • Posts: 43
[SOLVED] Simple (I hope) question
« on: November 25, 2023, 10:41:31 am »
I have some software written in Lazarus which details events which are to take place on a particular day.  There are two days per page and the number of events varies, also the use can select a number of dates so it may produce a number of pages.  This means that each page has a variable number of lines.  The lines are output to a stringlist which is then saved as a .txt file and opened and printed with Notepad from within the Lazarus software.

Now for the question : is there anything I can embed in the stringlist after the last event for the current day to force the printer to eject the current page and proceed to a new one?

The printer is an Epson XP-3200 if that makes any difference.

Thanks

Steve
« Last Edit: November 28, 2023, 04:29:01 pm by SteveSS »

AlexTP

  • Hero Member
  • *****
  • Posts: 2488
    • UVviewsoft
Re: Simple (I hope) question
« Reply #1 on: November 25, 2023, 11:25:26 am »
Change the topic title to 'How to sent StringList to printer', please.

No, you cannot. You must call NewPage method.
This is example for Delphi.
http://www.delphigroups.info/2/8b/315975.html

Code: Pascal  [Select][+][-]
  1. procedure PrintLines(Lines: TStrings);
  2. var
  3.   I, Line: Integer;
  4.   H: Integer; // TextHeight
  5.   MarginLeft,
  6.   MarginTop: Integer; // Margins' from printable area
  7.   Y: Integer; // Y-Position in Pixel
  8.   VR: Integer; // Vertical resolution in Pixel
  9. begin
  10.   with Printer do begin
  11.     Canvas.Font.Name := 'MS Sans Serif';
  12.     Canvas.Font.Size := 10;
  13.     MarginLeft := 10;
  14.     MarginTop  := 10;
  15.     // same as PageHeight
  16.     VR := GetDeviceCaps(Handle, VERTRES);
  17.     BeginDoc;
  18.     try
  19.        Line := 0;
  20.        for I := 0 to Lines.Count - 1 do begin
  21.           H := Canvas.TextHeight(Lines[I]);
  22.           if ((MarginTop + Line * H) >= (VR - MarginTop)) then begin
  23.              NewPage;
  24.              Line := 0;
  25.           end;
  26.           Inc(Line);
  27.           Y := MarginTop + Line * H;
  28.           Canvas.TextOut(MarginLeft, Y, Lines[I]);
  29.           Application.ProcessMessages; // for Printer.Abort();
  30.        end;
  31.     finally
  32.        EndDoc;
  33.     end;
  34.   end;
  35. end;
  36.  
But it has bug:

Quote
>>My code works, but with one wrong behaviour: At the end of a page, one or two lines were print on the non-printable area before a new page begins, so this lines were simply lost (on the paper). Were's the mistake?

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Simple (I hope) question
« Reply #2 on: November 25, 2023, 12:02:59 pm »
Hmm, in my app I first build a list with all the words in the text I want to print. I then iterate over that list keeping track of the X and Y positions, when we get near the bottom of the page, that is Y, this block cuts in -

Code: Pascal  [Select][+][-]
  1.     if CurrentY > MaxY then begin
  2.         Printer.EndDoc;
  3.         Printer.BeginDoc;
  4.         CurrentY := round(Printer.PageHeight * Margin);
  5.     end;  


Its pretty simple and quite reliable. See https://github.com/tomboy-notes/tomboy-ng/blob/master/source/k_prn.pas

Its probably more complicated than you need because my text contains content of varying size.

Davo

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

SteveSS

  • New Member
  • *
  • Posts: 43
Re: Simple (I hope) question
« Reply #3 on: November 25, 2023, 02:21:16 pm »
Thanks for the replies but this is all far too complicated.  If you have a message to display in your program that  needs to be two separate lines you code : showmessage('First Line' + #10#13 + 'Second Line');

I just want the string to embed in a text file to force ejection to a new page.

Steve

dseligo

  • Hero Member
  • *****
  • Posts: 1417
Re: Simple (I hope) question
« Reply #4 on: November 25, 2023, 03:26:01 pm »
You could try to insert 'Form feed' ASCII control character between pages (decimal 12, hexadecimal $0C). I don't know if it works with today's printers and with Windows printing.

Thanks for the replies but this is all far too complicated.  If you have a message to display in your program that  needs to be two separate lines you code : showmessage('First Line' + #10#13 + 'Second Line');

I just want the string to embed in a text file to force ejection to a new page.

If this is too complicated and you always print to the same printer, you could also count how many rows are already in your stringlist for each page and add empty lines until the end of the page.

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Simple (I hope) question
« Reply #5 on: November 25, 2023, 04:18:51 pm »
The NewPage property does not work for you?

that is supposed to scroll to the next page on the printer.
The only true wisdom is knowing you know nothing

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Simple (I hope) question
« Reply #6 on: November 26, 2023, 11:31:12 am »
Sending an embedded FF does not sound like a good idea unless you are treating the printer as a line printer.

Wow, I just went back and reread (or maybe read) the first post. You save the stringlist as a file, open it in notepad, get notepad to print it ? Seriously ?  Why not just print it from within your Pascal app ?

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

SteveSS

  • New Member
  • *
  • Posts: 43
Re: [SOLVED] Simple (I hope) question
« Reply #7 on: November 28, 2023, 04:37:34 pm »
I have never really got to grips with printing directly from Lazarus.  Another problem with this program is that it has two phases - one to print the dates and one to print the events - the phases use different fonts and sizes and different top/bottom/left/right margins.

I have taken the advice of dseligo and determined the number of lines required for each phase and ensured that the stringlist contains the correct number of lines to force a new page at the correct point.

Thanks for all your input.

Steve

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: [SOLVED] Simple (I hope) question
« Reply #8 on: November 30, 2023, 10:20:49 am »
Steve, see that unit I posted above. Its only 300 lines long (and I use a lot of comments).  You might just need to replace the KMemoRead function, it takes your input data and breaks it down into a list, each item in the list has its text and font details (size, normal, bold, italic). Don't think it handles different font type faces but easily extended.

David
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018