Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Skriv ut en fil till skrivaren
|
Kategori: Skrivare
Inlagt: 2003-08-01
Läst: 1443
Inlagt av: Staffan Berg
|
Beskrivning |
Detta exempel skickar en fil direkt till skrivaren.
|
Kod |
procedure PrintPCL;
var
Handle: THandle;
numwrite: DWORD;
Docinfo1: TDocInfo1;
PrintFile, InFile, SampForm: TMemoryStream;
buffer: array[0..4096] of char;
HPLetter, HPLegal, NC: array[0..15] of char;
temp: array[0..3] of char;
FF: char;
numread : longint;
x: integer;
FileName: String;
begin
if (OpenPrinter(PrinterName, Handle, nil)) then
begin
FF := Chr(12);
strcopy(HPLetter, chr(27));
strcat(HPLetter, '&l6d66p1h2A');
strcopy(HPLegal, chr(27));
strcat(HPLegal, '&l6d84p4h3A');
strcopy(NC, chr(27));
strcat(NC, '&l');
strcat(NC, StrPCopy(temp, InttoStr(NumCopies)));
strcat(NC, 'X');
try
PrintFile := TMemoryStream.Create;
for x := 0 to Printlist.Count - 1 do
begin
FileName := Copy(PrintList[x], 1, pos(',', printlist[x]) - 1);
InFile := TMemoryStream.Create;
InFile.LoadFromFile(FileName);
if (Integer(filename[Length(FileName) - 1]) = 49) then
PrintFile.Write(HPLetter, Strlen(HPLetter))
else
PrintFile.Write(HPLegal, Strlen(HPLegal));
PrintFile.Write(NC, strlen(NC));
PrintFile.CopyFrom(InFile, 0);
InFile.Free;
if Sample then
begin
try
SampForm := TMemoryStream.Create;
SampForm.LoadFromFile(AppPath + 'SAMPLE.PRN');
PrintFile.Copyfrom(SampForm, 0);
finally
SampForm.Free;
end;
end;
PrintFile.Write(FF, SizeOf(FF));
end;
DocInfo1.pDocName := PChar('PCLPrinter');
DocInfo1.pOutputFile := nil;
DocInfo1.pDataType := 'RAW';
PrintFile.Seek(0, 0);
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
numread := 0;
numwrite := 0;
while (numread = numwrite) and (PrintFile.Position <> PrintFile.Size) do
begin
numread := PrintFile.Read(buffer, sizeof(buffer));
WritePrinter(Handle, @buffer, numread, numwrite);
UpdateProgress(round((PrintFile.Position / PrintFile.Size) * 100));
end;
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
finally
PrintFile.Free;
end;
end;
end;
|
|
|