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<hs> 0.735 1.3
FILL HT. 4.00 MOTOR RPM 1750.00 EXTNL<hs> 0.035 1.44
INLET HT. 5.00 GEAR RATIO 8.50 TOTAL<hs> 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<HS> 0.735 1.3
FILL HT. 4.00 MOTOR RPM 1750.00 EXTNL<HS> 0.035 1.44
INLET HT. 5.00 GEAR RATIO 8.50 TOTAL<HS> 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)<XPOS-4) do Line:=Line+' ';
if (Constant in CellStatus) or (Formula in CellStatus) then
begin
if not (Locked in CellStatus) then
begin
Str(Value:FW:DEC,P); {FW does usually set the width of a cell properly}
Line:=Line+P;
end;
end else Line:=Line+Contents; {Contents is type AnyString;}
{EVERY TIME I TRY TO SET WIDTH OF CONTENTS IT GIVES UNEVEN WIDTH OF CELL}
end; { With }
end; { One line }
PU(Line); {PU calls myPrinterUnit5}
end; { End Column }
PageReady; {this sends it to the default printer}
Grid;
LowVideo;
update;
GotoCell(FX,FY);
end
______
UNIT CF20_2;
(* Program cf20_2.pas
This is the spread sheet portion of the counterflow program
which is included in Cflow11.pas LAST UPDATE 1/10/93 *)
{$mode objfpc}{$H+}
INTERFACE
USES crt,dos, sysutils, Cf20Var, CF20error, CF20Fan, CF20fan1, CF20psychro, myPrinterUnit5;
const
FXMax: Char = 'G'; FYMax = 21;
type
Anystring = string[70];
String3 = string[3];
SheetIndex = 'A'..'G';
Attributes=(Constant,Formula,Txt,OverWritten,Locked,Calculated);
CellRec = record
CellStatus: set of Attributes;
Contents: Anystring;
Value: Real;
DEC,FW: 0..20; {number of decimals width}
end;
Cells = array[SheetIndex,1..FYMax] of CellRec;
const { (3,14,25,36,47,58,69);}
XPOS: array[SheetIndex] of integer = (3,16,29,42,55,68,81);
BFX: SheetIndex = 'B';
DFX: SheetIndex = 'D';
FFX: SheetIndex = 'F';
GFX: SheetIndex = 'G';
var
FileName: anystring;
Line: string[100];
Var S1, S2 : AnsiString; {used with date time}
var
Sheet: Cells;
FX: SheetIndex;
FY: Integer;
{ Ch: Char; } {Ch now in CFLOWVAR as a master}
RDFile: file of CellRec;
AutoCalc: boolean;
AutoSave: boolean;
Temp: real; {a holding value for NewData}
{ S: anystring;} { this was not here in the original}
The length of “Value” for numbers seems to work properly. But “Contents” and other text does not.
Am I wrong in thinking I need to change the font to one that has evenly spaced characters?
Thanks for reading.
Richard