ورود

View Full Version : فونت و سایز متن در چاپ فایل متنی



majid_n
جمعه 16 بهمن 1383, 00:21 صبح
می دونیم که یکی از روش های چاپ فایل متنی یا فرستادن متن به چاپگر بصورت زیر است :


var
myFile : TextFile;
printDialog : TPrintDialog;

begin
// Create a printer selection dialog
printDialog := TPrintDialog.Create(Form1);

// If the user has selected a printer (or default), then print!
if printDialog.Execute then
begin
// Try to open a printer file
AssignPrn(myFile);

// Now prepare to write to the printer
ReWrite(myFile);

// Write a couple of well known words to this file -
// they will be printed instead
WriteLn(myFile, 'Hello');
WriteLn(myFile, 'World');

// Close the file
CloseFile(myFile);
end;
end;


سوال من اینه که آیا در این روش میشه اندازه متن و فونت اونو هم تعیین کرد . و یا به طور کلی بهترین روش واسه چاپ یک فایل متنی چه روشیه ؟؟؟
مرسی :flower:

majid_n
شنبه 17 بهمن 1383, 20:13 عصر
کسی نمی تونه کمکم کنه ؟؟؟؟؟؟؟
:گیج:

majid_n
یک شنبه 18 بهمن 1383, 09:25 صبح
آیا کامپوننت به درد بخوری واسه این کار هست ؟؟؟؟ :flower:

hr110
یک شنبه 18 بهمن 1383, 10:20 صبح
سلام
در این روش شما به سادگی نمیتوانید فونت ، اندازه و ... را تعیین نمایید و از فونت پیش فرض چاپگر استفاده مینماید.

برای اینکار ابزارهای متنوعی در دلفی وجود دارد که میتوانید از آنها استفاده نمایید.
به عنوان مثال از quickreport یا rave

ضمناً فکر کنم شما بتوانید از Canvas پرینتر نیز بهره لازم را ببرید، چرا که شما در این canvas از فونت، رنگ ، اندازه و position استفاده کنید.

hr110
یک شنبه 18 بهمن 1383, 10:23 صبح
مثال زیر هم ترکیبی از روش ارائه شده شما و پیشنهاد آخر من میباشد.





......
uses
Printers;
......

procedure TForm1.Button1Click(Sender: TObject);
var
PrintText:TextFile;
i,Th,Ph,Lpp,CurrentLine:integer;
const
TopMargin=4;
LeftMargin=' ';
begin
{Preliminary}
Printer.Canvas.Font.Name:='Book Antiqua';
Printer.Canvas.Font.Size:=14;
Th:=Printer.Canvas.TextHeight('P'); {Height of current font in pixels}
Ph:=Printer.PageHeight; {Page Height (printable) in pixels}
Lpp:=Ph div Th; {Lines Per Page}
AssignPrn(PrintText);
Rewrite(PrintText); {Open print file}
CurrentLine:=1;
{Top Margin}
for i:=0 to TopMargin-1 do
begin
Write(PrintText,#10); {#10 is a newline. Could have used Writeln(PrintText,'')}
Inc(CurrentLine);
end;
{Print report}
Write(PrintText,LeftMargin+'TextHeight = '+IntToStr(Printer.Canvas.TextHeight('P')));
Writeln(PrintText,#09#09#09'Line number = '+IntToStr(CurrentLine)); {#09 is a horizontal tab}
Inc(CurrentLine);
Write(PrintText,#10#10#10);
Inc(CurrentLine,3);
Writeln(PrintText,LeftMargin+'Another Line. Line number '+IntToStr(CurrentLine));
Inc(CurrentLine);
Writeln(PrintText,'');
Inc(CurrentLine);
for i:=1 to (Lpp-CurrentLine) do WriteLn(PrintText,'');
Write(PrintText,LeftMargin+'The last line on the page. Line number '+IntToStr(Lpp));
CloseFile(PrintText);
end;

majid_n
یک شنبه 18 بهمن 1383, 11:40 صبح
آقای ربیعی عزیز دست گلت درد نکنه . امتحانش می کنم ببینم چی میشه :flower:
:D