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 72 73 74
| procedure TForm1.btnPrintClick(Sender: TObject);
begin
PrintRichEdit(RichEdit1);
end;
procedure TForm1.PrintRichEdit(re: TRichEdit);
var
XPixelsParPouce, YPixelsParPouce,
//LeftSpace, TopSpace, RightSpace, BottomSpace, RightEnd, BottomEnd,
HauteurPage, LargeurPage, HauteurDoc, LargeurDoc,
LeftSaisie, TopSaisie, RightSaisie, BottomSaisie: Integer;
R: TRect;
function XPixels2MM(pix: integer): integer;
begin
Result := trunc( pix / XPixelsParPouce * 25.4);
end;
function YPixels2MM(pix: integer): integer;
begin
Result := trunc( pix / YPixelsParPouce * 25.4);
end;
begin
if PageSetupDialog1.Execute then
with Printer do
begin
// Mise sous variables des Edits de saisie du compo
LeftSaisie := PageSetupDialog1.MarginLeft;
TopSaisie := PageSetupDialog1.MarginTop;
//?? RightSaisie := PageSetupDialog1.MinMarginRight;
//?? BottomSaisie := PageSetupDialog1.MinMarginBottom;
RightSaisie := PageSetupDialog1.MarginRight;
BottomSaisie := PageSetupDialog1.MarginBottom;
// Adaptation sortie des edits de saisie du compo...
LeftSaisie := LeftSaisie DIV 100; // Convertir en millimètres
TopSaisie := TopSaisie DIV 100;
RightSaisie := RightSaisie DIV 100;
BottomSaisie := BottomSaisie DIV 100;
// Nombre de pixels par pouce pour l'imprimante
XPixelsParPouce := GetDeviceCaps(Handle, LOGPIXELSX);
YPixelsParPouce := GetDeviceCaps(Handle, LOGPIXELSY);
// Obtenir les zones non imprimables = les marges...
// Inutile, sauf si on veut contrôler que la saisie du user est valide
//LeftSpace := GetDeviceCaps(Handle, PHYSICALOFFSETX);
//TopSpace := GetDeviceCaps(Handle, PHYSICALOFFSETY);
//RightSpace := GetDeviceCaps(Handle, PHYSICALWIDTH) - LeftSpace - GetDeviceCaps(Handle, HORZRES);
//BottomSpace := GetDeviceCaps(Handle, PHYSICALHEIGHT) - TopSpace - GetDeviceCaps(Handle, VERTRES);
//RightEnd := GetDeviceCaps(Handle, PHYSICALWIDTH) - RightSpace;
//BottomEnd := GetDeviceCaps(Handle, PHYSICALHEIGHT)- BottomSpace;
HauteurPage := YPixels2MM(GetDeviceCaps(Handle, PHYSICALHEIGHT));
LargeurPage := XPixels2MM(GetDeviceCaps(Handle, PHYSICALWIDTH));
HauteurDoc := HauteurPage - TopSaisie - BottomSaisie;
LargeurDoc := LargeurPage - LeftSaisie - RightSaisie;
R.Left := XmmToPixels(LeftSaisie);
R.Top := YmmToPixels(TopSaisie);
R.Right := XmmToPixels(LeftSaisie + LargeurDoc);
R.Bottom := YmmToPixels(TopSaisie + HauteurDoc);
{ShowMessage('R.Left ' + (IntToStr(R.Left)) + ' ' +
'R.Top ' + (IntToStr(R.Top)) + ' ' +
'R.Right ' + (IntToStr(R.Right)) + ' ' +
'R.Bottom ' + (IntToStr(R.Bottom))); }
RichEdit1.PageRect := R;
// Imprime, donc penser à copier/coller du texte dans RichEdit1, avant de cliquer !
RichEdit1.Print('');
end;
end; |
Partager