Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print to / from file

0 views
Skip to first unread message

Koger

unread,
Jun 2, 2003, 5:55:51 AM6/2/03
to
Hi

I'm looking for information how to print to a file and then print from the
file at a later point.

Printing to a file should not be a big issue, but how do I present the file
to the printer at a later moment ?

Any good links and comments will be much appreciated.

Eric Hill

unread,
Jun 2, 2003, 9:26:57 AM6/2/03
to
Since the printer could be a different type, save the information required
to *generate* the print, then render the print at a later time.

If this isn't an option, you can set a printer to print to a file, but I'm
not quite sure how to get it back to the printer later.

You could also look into the PDF format...

Just some ideas...

Eric

Ignacio Vazquez

unread,
Jun 2, 2003, 9:27:27 AM6/2/03
to
"Eric Hill" <er...@ijack.net> wrote in message
news:3edb4fcd$1...@newsgroups.borland.com...

> If this isn't an option, you can set a printer to print to a file, but I'm
> not quite sure how to get it back to the printer later.

Just copy it to the printer port.

> You could also look into the PDF format...

Always a good idea.

Cheers,
Ignacio


Peter Below (TeamB)

unread,
Jun 2, 2003, 1:39:13 PM6/2/03
to
In article <3edb...@newsgroups.borland.com>, Koger wrote:
>
> I'm looking for information how to print to a file and then print from the
> file at a later point.
>
> Printing to a file should not be a big issue, but how do I present the file
> to the printer at a later moment ?

You use the Winspool.WritePrinter function for that.

<quote
source="http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=19374
">


Printing a file directly to a printer in Win32, code by Joe Hecht.

Note that you have to include WinSpool in the uses clause.


procedure PrintFile(const sFileName: string);
const
BufSize = 16384;
type
TDoc_Info_1 = record
pDocName: pChar;
pOutputFile: pChar;
pDataType: pChar;
end;
var
Count, BytesWritten: cardinal;
hPrinter: THandle;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
DocInfo: TDoc_Info_1;
f: file;
Buffer: Pointer;
begin
Printer.PrinterIndex := -1;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not WinSpool.OpenPrinter(@Device, hPrinter, nil) then exit;
DocInfo.pDocName := 'MyDocument';
DocInfo.pOutputFile := nil;
DocInfo.pDatatype := 'RAW';
if StartDocPrinter(hPrinter, 1, @DocInfo) = 0 then
begin
WinSpool.ClosePrinter(hPrinter);
exit;
end;
if not StartPagePrinter(hPrinter) then
begin
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
exit;
end;
System.Assign(f, sFileName);
try
Reset(f, 1);
GetMem(Buffer, BufSize);
while not eof(f) do
begin
Blockread(f, Buffer^, BufSize, Count);
if Count > 0 then
begin
if not WritePrinter(hPrinter, Buffer, Count, BytesWritten) then
begin
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
FreeMem(Buffer, BufSize);
exit;
end;
end;
end;
FreeMem(Buffer, BufSize);
EndDocPrinter(hPrinter);
WinSpool.ClosePrinter(hPrinter);
finally
System.Closefile( f );
end;
end;

</quote>


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

0 new messages