Unit Printers: How to get PageHeight/Width lazarus / 8-Other ---------------------------------------------------------------------- Nils:D · 2009-03-02 21:12 Hi, I want to print a StringList using the unit printers. The StringList is long (like a code of a program) and needs more than one page. So it is necessary to create a new page when one is full. So I need the height of the Page. Printer.PageHeight seems to be very big (~6000px) - the printer is on strike. Are there any other methods to get the pageheight ? ---------------------------------------------------------------------- bonmario · 2009-03-03 07:11 When i must print a StringList, i use this code: Code: [Select]  procedure StampaStringList(MyList:TStringList; Titolo:String);   var RigaInStampa, RigaAttuale, Pagina, AltezzaChr, PosY, RigheXPag, IdxLista:Integer;   begin     Printer.BeginDoc;     Printer.Title:=Titolo;     Printer.Canvas.Font.Name:='Courier New';     Printer.Canvas.Font.Size:=8;       AltezzaChr:=Printer.Canvas.TextHeight('Gg') + 2;       RigheXPag:=(Printer.PageHeight - 50) div AltezzaChr;       Pagina:=0;       RigaAttuale:=0;       for IdxLista:=0 to MyList.Count - 1 do begin         RigaAttuale:=RigaAttuale + 1;         RigaInStampa:=RigaAttuale - (Pagina * RigheXPag);         PosY:=RigaInStampa * AltezzaChr;         Printer.Canvas.TextOut(25, PosY, MyList[IdxLista]);         //Salto pagina         if (RigaInStampa = RigheXPag) and (IdxLista <> (MyList.Count - 1)) then begin           Printer.NewPage;           Pagina:=Pagina + 1;         end;       end;     Printer.EndDoc;   end; ---------------------------------------------------------------------- Nils:D · 2009-03-03 20:54 It is a nice code. I printed a short code of a program (~2 pages).  I printed the lines of a SynEdit which does not support linebreaks. This is bad, because on my 22" monitor I'm writing comments on the whole range. SynEdit forces every font to have chars with the same size. Is there a nice method to force linebreaks ? I think it is not very easy because I want something like WordWrap - a word won't be cut off. I solved the problem Here is my code for it with comments. I think it would be easier to understand the german comments *g*. Code: [Select]// Create linebreak if needed. It is solverd with tokens. procedure LineBreak(sl : TStrings; w : Integer; var Result : TStrings); // sl=Input; w=Width var i, j, c : Integer; // c=Length of current string     sWord   : String;  // sWord=Current word begin   for i := 0 to Pred(sl.Count) do   begin     // Saving memory     c     := Length(sl[i]);     sWord := '';     // When c >= w a linebreak is needed     if c >= w then     begin       // Analysing the current string       for j := 1 to c do       begin         // If the current char is not a punctuation character it can be added to the current word (sWord)         if (not (sl[i][j] in WordDelimiters)) and (j < c) then           sWord := sWord+sl[i][j]         else         begin           // If not the last char will be added           sWord := sWord+sl[i][j];           // and...           if Length(Result[Pred(Result.Count)])+Length(sWord) < w then             // ...if possible it will be added to the last added String             Result[Pred(Result.Count)] := Result[Pred(Result.Count)]+sWord           else             // ...added as a new string             Result.Add(sWord);           // Reset sWord for the next run           sWord := '';         end;       end;     end else       // Otherweise the string can be added directly       Result.Add(sl[i]);   end; end;