Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing text on dotmatrix printer

Status
Not open for further replies.

cerbadan

Programmer
Sep 7, 2004
4
RO
Does anyone knows (with full source code) how can I print text with an Epson dot matrix printer, so that I can print with Win XP just like in DOS. Continously, not related to a page size, just text. The biggest problem is to print 1 line of text so that the printer won't pull off the paper. (the printer should stop after 1 line of text, and the next time I print should continue from the next line,without taking off the paper(actualy takes off the entire page size-A4 A5 ))
Anyone?
Thanks,
Cerba Dan
 
Thanks alot, but DosPrint is not for free...
Fortes Report can print text without writing it into a document? I would like a command line like this:
WriteLN('any text here');
And the printer should stop exactly after the last line and execute the next command. I tryed it with a lot of "AssignPrn" stuff but it didn't work. Any free solution?
Thanks,
Cerba Dan
 
I write directly to the printer, but it doesn't print until you send the EndDoc and all my printing is on regular paper, so I don't know if it will stop after printin the single line or if it will eject until the end of the page.

Code:
const
dblleftmargin : double = 1.25;
dblLineHeight : double = 0.1875;

var
dblCurrentLine : double;
PixPerInX, PixPerInY, OffsetX, OffsetY : integer;

begin

  PixPerInX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  PixPerInY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
  OffsetX := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
  OffsetY := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);

  Printer.Canvas.Font.Name := 'Times New Roman';
  Printer.Canvas.Font.Size := 12;
  Printer.Canvas.Font.Style := [];

  Printer.Canvas.TextOut((trunc(dblleftmargin * PixPerInX) - OffsetX), trunc((dblCurrentLine * PixPerInY) - OffsetY) , 'This is the text to print on a line');
  dblCurrentLine := dblCurrentLine + ([COLOR=red]2.5[/color] * dblLineHeight);

  Printer.Canvas.TextOut((trunc(dblleftmargin * PixPerInX) - OffsetX), trunc((dblCurrentLine * PixPerInY) - OffsetY) , 'This is text to print on the next line'));
  dblCurrentLine := dblCurrentLine + ([COLOR=red]2.5[/color] * dblLineHeight);

  Printer.EndDoc;

The red 2.5 indicates that instead of moving a single line down, move 2 1/2 lines down.

Leslie
 
Exactly that's the problem. No matter how much you write, if you use enddoc it will take off the paper until the end of the paper size. Because of this I can't 100 invoices so that fit the pre-printed pages perfectly.
The point is to stop the printer from taking off the paper.
Anyone, any ideea?
Thank you,
Cerba Dan
 
Use procedure AssignPrn(var F: Text); (See Delphi Help) then use write(f, stringvar) and writeln(f, stringvar) to print lines or chars. You will need to send LF with write() but the form will not eject until you send the FF char. #12, I think... Been a long time since the DOS days. :)

HTH

Roo
Delphi Rules!
RooBoy.jpg
 
Here's a modified extract from a printing/preview tool that I wrote. This part was specifically designed for sending raw text to a dot-matrix printer for printing checks. Hope it helps.
[tt]
procedure PrintMe(Content: TStringList);
var
sPrinter, sDriver, sPort, sTitle: array[0..255] of Char;
hPrinter, hDevMode: THandle;
DocInfo1: TDocInfo1;
W: DWORD;
S: String;
C: Char;
I: Integer;
begin
// page-break
C := #12;

// initialize the document structure
with DocInfo1 do begin
pDocName := StrPCopy(sTitle, 'Your Title Here');
pOutputFile := nil;
pDatatype := 'RAW';
end;

// get the current printer (sPrinter)
Printer.GetPrinter(sPrinter, sDriver, sPort, hDevMode);

// open the printer
OpenPrinter(sPrinter, hPrinter, nil);
try
try
// start document to spooler
StartDocPrinter(hPrinter, 1, @DocInfo1);
StartPagePrinter(hPrinter);

// send the 'Source' to the printer
for I := 0 to Source.Count - 1 do begin
S := Source.Strings;
if not WritePrinter(hPrinter, PChar(S), Length(S), W) then
Break;
end;

// send a page-break to the printer (optional)
if not WritePrinter(hPrinter, @C, 1, W) then
Break;

// end the page
EndPagePrinter(hPrinter);

// end the document
EndDocPrinter(hPrinter);
finally
// close the printer
ClosePrinter(hPrinter);
end;
except
// abort the job
AbortPrinter(hPrinter);
raise;
end;
end;
[/tt]
 
Hi,
Thx, I'll try it.
Anyway, a pieceof codelike this works.


var f:textfile;
begin
assignfile(f,'LPT1');
rewrite(f);
writeln(f,'Any text');// orany escape codes
closefile(f);
end;


easyer than I thought.
:)))
I tryed something like this but instead of using 'LPT1' I tryed with 'LPT'
My mistake...
anyway... I NOW CAN PRINT A LINE AND MAKE PRINER STOP EXACTLY AFTER THAT LINE (or more lines).
Thx again
Cerba Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top