mam komponent listview na którym znajduje się 12 elementów i chciał bym to wydrukować ale niektóre elementy mi się nie mieszczą w kolumnach inne maja je wolne ale za duże jak można to podzielić żeby mi ładnie wszystko wydrukowało mój kod do drukowania to
var
pSzerokosc, pWysokosc, i: Integer;
v, h: Real;
DotPozycja, IloscKolumn: Integer;
aKolumny: array of Integer;
iCalkowitaSzerokosc, iSzerokosc, GornyMargines, IloscLinii, Linia, SzerokoscTekstu, Kolumna: Integer;
R: TRect;
Tekst: string;
LewaStrona, IloscStron, Pozycja: Integer;
ColumnCaption : String;
begin
if PrintDialog1.Execute then
begin
IloscKolumn := lvRaport.Columns.Count;
SetLength(aKolumny, IloscKolumn + 1);
Printer.Title := 'Drukowanie raportu';
Printer.Copies := 1;
Printer.Orientation := poLandscape;
Printer.BeginDoc;
pWysokosc := Printer.PageHeight;
pSzerokosc := Printer.PageWidth;
v := (pWysokosc + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY))) / (39.7 * 0.85);
h := (pSzerokosc + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX))) / 20;
iCalkowitaSzerokosc := 0;
for i := 0 to IloscKolumn - 1 do
begin
iCalkowitaSzerokosc := iCalkowitaSzerokosc + lvRaport.Columns[i].Width;
end;
aKolumny[0] := Round(0.4 * h);
aKolumny[IloscKolumn + 0] := pSzerokosc - Round(0.9 * h);
iSzerokosc := aKolumny[IloscKolumn + 0] - aKolumny[0];
for i := 0 to IloscKolumn - 1 do
begin
aKolumny[i + 1] := aKolumny[i] + Round(lvRaport.Columns[i].Width / iCalkowitaSzerokosc * iSzerokosc);
end;
GornyMargines := Round(2.5 * v);
with Printer.Canvas do
begin
Font.Size := 8;
Font.Style := [];
Font.Name := 'Times New Roman';
Font.Color := RGB(0, 0, 0);
SzerokoscTekstu := Printer.Canvas.TextHeight('xxx');
IloscLinii := Round((pWysokosc - (5 * v)) / SzerokoscTekstu);
IloscStron := 1;
while (IloscStron * IloscLinii) < lvRaport.Items.Count do
begin
inc(IloscStron);
end;
Linia := 0;
for DotPozycja := 0 to lvRaport.Items.Count - 1 do
begin
if (Linia > IloscLinii) or (Linia = 0) then
begin
if (Linia > IloscLinii) then Printer.NewPage;
Linia := 1;
if Printer.PageNumber = IloscStron then
begin
MoveTo(aKolumny[1], GornyMargines);
for i := 1 to IloscKolumn - 1 do
begin
LineTo(aKolumny[i], GornyMargines + (SzerokoscTekstu * (lvRaport.Items.Count - DotPozycja + 2)));
MoveTo(aKolumny[i + 1], GornyMargines);
end;
end
else
begin
for i := 1 to IloscKolumn - 1 do
begin
MoveTo(aKolumny[i], GornyMargines);
LineTo(aKolumny[i], GornyMargines + (SzerokoscTekstu * (IloscLinii + 1)));
end;
end;
Font.Style := [fsBold];
for i := 0 to IloscKolumn - 1 do
begin
ColumnCaption := StringReplace(lvRaport.Columns.Items[i].Caption, 'ma/wyk/zos', '', [rfIgnoreCase]);
TextRect(Rect(aKolumny[i] + Round(0.1 * h), GornyMargines - Round(0.1 * v), aKolumny[i + 1] - Round(0.1 * h)
, GornyMargines + SzerokoscTekstu - Round(0.1 * v)), ((aKolumny[i + 1] - aKolumny[i]) div 2) +
aKolumny[i] - (TextWidth(ColumnCaption) div 2),
GornyMargines - Round(0.1 * v), ColumnCaption);
end;
MoveTo(aKolumny[0] - Round(0.1 * h), GornyMargines + SzerokoscTekstu - Round(0.05 * v));
LineTo(aKolumny[IloscKolumn] + Round(0.1 * h), GornyMargines + SzerokoscTekstu - Round(0.05 * v));
Font.Size := 8;
Font.Style := [];
Pozycja := (TextWidth('Data wydruku: ' + DateToStr(Date) + ' Strona: ' +
IntToStr(Printer.PageNumber) + ' / ' + IntToStr(IloscStron))) div 2;
Pozycja := pSzerokosc - Round(1.5 * h) - (Pozycja * 2);
Font.Size := 8;
Font.Style := [];
TextOut(Pozycja, Round(0.5 * v), 'Data wydruku: ' + DateToStr(Date) +
' Strona: ' + IntToStr(Printer.PageNumber) + ' / ' + IntToStr(IloscStron));
Font.Size := 10;
Font.Style := [];
end;
R.Top := GornyMargines + (Linia * SzerokoscTekstu);
R.Bottom := GornyMargines + ((Linia + 1) * SzerokoscTekstu);
for Kolumna := -1 to IloscKolumn -2 do
begin
R.Left := aKolumny[Kolumna + 1] + Round(0.1 * h);
R.Right := aKolumny[Kolumna + 2] - Round(0.1 * h);
try
if Kolumna = -1 then
Tekst := lvRaport.Items[DotPozycja].Caption
else
Tekst := lvRaport.Items[DotPozycja].SubItems[Kolumna];
except
Tekst := '';
end;
LewaStrona := R.Left;
TextRect(R, LewaStrona, R.Top, Tekst);
end;
Inc(Linia);
end;
end;
Printer.EndDoc;
end;
end;