1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
procedure TMainForm.acPrintExecute(Sender: TObject);
const
LeftMargin = 100;
TopMargin = 200;
BottomMargin = 200;
HEADLINE = 'APTEC sarl / Le ';
var
I, Y, LineHeight, NbPages: Integer;
HeadMargin, FootMargin, TitleMargin : Integer;
PrintString: String;
begin
// Fermer si la liste est vide
if MainGrid.RowCount =1 then Exit;
if PrintDialog.Execute then
begin
// Si Impression fichier alors init nom du fichier
with Printer do
try
if PrintDialog.PrintToFile = true then
begin
FileName := ExtractFileNameWithoutExt(OpenedFileName)+'.ps';
end;
Orientation := poReverseLandscape; // Orientation de la page
//Orientation := poPortrait;
LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I'))); // Calcule hauteur ligne
// Démarre le document
BeginDoc;
Canvas.Font.Name := 'Courier New'; // Init le nom de la police
Canvas.Font.Color := clBlack; // Init couleur de la police
Canvas.Font.Size := 10; // Init taille de la police
Canvas.Font.Bold := true;
// Calcule le nombre de pages
NbPages := ((LineHeight*MainGrid.RowCount)+(TopMargin*2))div PageHeight;
// Imprimer entete document
Y := TopMargin; // Position début écriture
PrintString := HEADLINE + DateTimeToStr(Now)
+' - Page' +inttostr(PageNumber)
+'/'+inttostr(NbPages)+' - Document : '
+ExtractFileNameOnly(OpenedFileName);
Canvas.TextOut(LeftMargin, Y, PrintString);
Canvas.Line(LeftMargin, Y+LineHeight, PageWidth-LEFTMARGIN, Y+LineHeight);
// Imprimer entete du tableau
Canvas.Font.Size := 12; // Init taille de la police
Y := Y+(LineHeight); // Position début écriture
PrintString := Format('%-5s', ['Ordre'])+' '+
Format('%-10s', [MainGrid.Columns[6].Title.Caption])+' '+
Format('%-100s', [MainGrid.Columns[7].Title.Caption]);
Canvas.TextOut(LeftMargin, Y, PrintString);
//Imprimer listing
Canvas.Font.Bold := False;
for i:=1 to MainGrid.RowCount-1 do
begin
if (Y >= (PageHeight-BottomMargin)) then
begin
Y := TopMargin;
NewPage;
end;
Y := Y+(LineHeight);
PrintString := Format('%-5s', [MainGrid.Cells[0, i]])+' '+
Format('%-10s', [MainGrid.Cells[7, i]])+' '+
Format('%-100s', [MainGrid.Cells[8, i]]);
Canvas.TextOut(LeftMargin, Y, PrintString);
//ShowMessage(inttostr(Y));
end;
finally
EndDoc;
end;
end;
end; |
Partager