change fonts going to printer lazarus / 64-FPC development ---------------------------------------------------------------------- DesJardins · 2018-08-14 23:26 I want to send the following simple spreadsheet to a modern printer. (only a few lines of the whole print out are shown to keep this inquiry short, but you get the idea of what I am trying to do) The font used by either the program, the computer, or the printer (I don't know which it is) is proportionally spaced, so formatting does not let me line it all into nice clean columns. If I use something like "Courier New" which I use to open it from a file that I saved so I can open it in Word or Notes then the length of each cell works fine.  But I have not figured out how to format it for transmittal directly to a printer.  To see a picture of the full screen you can visit my website @ www.rjdesjardins.com.  All I want to do is print it without saving to a file and using Notes or Word to print it.  In Python you can write a program to save to a file and then print the file all with one click..  I still have not found where I can do in FP.  Note that the program is strictly Free Pascal.  It does not use Lazarus controls, like grid, Can I combine FP and Laz and use font controls from Laz? This is what Courier New spacing looks like:  (actually I had to modify this to get it to line up for this demo, it is not perfect).  The object is pretty columns. HOT WATER        95.00   STACK HT.        10.00                   PRESSURE DROPS COLD WATER      85.00   STACK DIA        19.04   INLET LVRS       0.284    PLEN HT W WET BULB          78.00   FAN DIA            18.00   FILL                0.388              3.00 DRY BULB           95.00   HUB DIA             4.00   ELIMINATOR      0.038    PLEN HT L ALTITUDE            0.00   FAN TYPE     HUDSON     PLENUM            0.025              6.00 FILL TYPE   OF21MA       NO BLADES          9.00    SUBTTL    0.735               1.3 FILL HT.              4.00    MOTOR RPM   1750.00    EXTNL      0.035              1.44 INLET HT.            5.00    GEAR RATIO        8.50   TOTAL       0.770   FANDK HT L This is Arial or something like Arial that goes to the printer.  nothing lines up in columns.  HOT WATER        95.00   STACK HT.         10.00                   PRESSURE DROPS COLD WATER       85.00   STACK DIA         19.04   INLET LVRS        0.284   PLEN HT W WET BULB         78.00   FAN DIA           18.00   FILL              0.388         3.00 DRY BULB         95.00   HUB DIA            4.00   ELIMINATOR        0.038   PLEN HT L ALTITUDE          0.00   FAN TYPE     HUDSON       PLENUM            0.025         6.00 FILL TYPE   OF21MA       NO BLADES          9.00   SUBTTL        0.735          1.3 FILL HT.          4.00   MOTOR RPM       1750.00   EXTNL         0.035         1.44 INLET HT.         5.00   GEAR RATIO         8.50   TOTAL         0.770   FANDK HT L How do I change the font? I have tried a lot of Format controls fmt, setlength, strLength, etc.  I have tried repeat/until, adding spaces to give me 12 wide, etc.  Sometimes I get some really weird results.  Here is what I am using to send to find a default printer and print it: Unit myPrinterUnit5;   {last update 8/26/17  from C:\psy\psy\psy_11_30_17}  {$mode objfpc}{$H+}  interface procedure BeginPrinting(const sPrinter: string); {procedure myPrintLn(const S: String);} procedure PageReady; function GetDefaultPrinter: string; {procedure testprint;} procedure PU(const S: string); var   hdcPrint: hDc;   DocInfo: TDocInfo;   PenPos: TPoint;    PrintRes: TPoint; implementation function GetDefaultPrinter: string; var    DefaultPrinter: array [0 .. 79] of Char;     I: Integer; begin   GetProfileString('windows', 'device', '', DefaultPrinter, SizeOf(DefaultPrinter) - 1);   I := Pos(',', DefaultPrinter);   if I = 0 then I := Length(DefaultPrinter) + 1;   GetDefaultPrinter := Copy(DefaultPrinter, 1, I - 1); end; procedure BeginPrinting(const sPrinter: string); begin   hdcPrint := CreateDC(pchar('WINSPOOL'), pchar(sPrinter), nil, nil);   FillChar(DocInfo, SizeOf(DocInfo), #0);   DocInfo.cbSize := SizeOf(DocInfo);   DocInfo.lpszDocName := 'Myprogram';   if StartDoc(hdcPrint, DocInfo) = 0 then Exit;   if not StartPage(hdcPrint) = 0 then   begin     EndDoc(hdcPrint);   end;   PrintRes.X := GetDeviceCaps(hdcPrint, LOGPIXELSX);   PrintRes.Y := GetDeviceCaps(hdcPrint, LOGPIXELSY);   PenPos.X := round((0.5 * PrintRes.X) / 2.54); // margin 0.5 cm   PenPos.Y := round((0.5 * PrintRes.Y) / 2.54); end; procedure PageReady; begin   EndPage(hdcPrint);   EndDoc(hdcPrint);   DeleteDc(hdcPrint); end; procedure PU(const S: string); begin   if S <> '' then     TextOut(hdcPrint, PenPos.X, PenPos.Y, @S[1], Length(S));     PenPos.Y := PenPos.y + round((1 / 6) * PrintRes.Y); // 6 lines per inch end; end. This is the code for reading the cells:   for J:=1 to FYmax do   begin     Line:='';     for I:='A' to FXmax do     begin       with Sheet[I,J] do       begin         while (Length(Line)