Thread View: borland.public.delphi.nativeapi.win32
2 messages
2 total messages
Started by Charles Collins
Thu, 17 Jul 2008 19:56
Windows print spool file
Author: Charles Collins
Date: Thu, 17 Jul 2008 19:56
Date: Thu, 17 Jul 2008 19:56
14 lines
1615 bytes
1615 bytes
Is there a way to tell the spooler to close and finish the current print job? I have Delphi 7, running on Windows XP Pro. I am working with a 3rd party product (no source available, a standalone program) that spools reports to a shared Windows printer, and the last report leaves the last page in the queue. The only way to get it to print is to have the program either print another report or to terminate. Terminating the program is not an option, as it is in use for 10 to 14 hours per day, and the reports are needed when printed. I have setup a "report" to print a blank page, but would prefer a method that does not waste a page for each user print and the requirement that the user print the blank page "report" after their actual report. Thanks.
Re: Windows print spool file
Author: Peter Below (TeamB)
Date: Fri, 18 Jul 2008 17:48
Date: Fri, 18 Jul 2008 17:48
58 lines
3480 bytes
3480 bytes
Charles Collins wrote:
> Is there a way to tell the spooler to close and finish the current
> print job? I have Delphi 7, running on Windows XP Pro.
>
> I am working with a 3rd party product (no source available, a
> standalone program) that spools reports to a shared Windows printer,
> and the last report leaves the last page in the queue. The only way
> to get it to print is to have the program either print another report
> or to terminate. Terminating the program is not an option, as it is
> in use for 10 to 14 hours per day, and the reports are needed when
> printed. I have setup a "report" to print a blank page, but would
> prefer a method that does not waste a page for each user print and
> the requirement that the user print the blank page "report" after
> their actual report.
Windows has a print spooler API (the WinSpool unit declares most of it
in Delphi) that allows you to enumerate existing jobs and manipulate
them, if you have sufficient rights. Look at the following API
functions: OpenPrinter (you need that to get the API handle of the
printer, not in any way related to a VCL TPrinter.Handle!), EnumJobs,
GetJob, SetJob. You should be able to cancel a pending job, but I'm not
sure you can *end* it (so it will print the last page). You 3rd-party
program seems to fail to properly end the job (it does not call
EndDoc). You cannot do that for it, unfortunately, since you don't have
the required device context handle.
{-- GetCurrentPrinterHandle -------------------------------------------}
{: Retrieves the handle of the current printer
@Returns an API printer handle for the current printer
@Desc Uses WinSpool.OpenPrinter to get a printer handle. The caller
takes ownership of the handle and <b>must</b> call ClosePrinter on it
once the handle is no longer needed. Failing to do that creates a
serious resource leak! <P>
Requires Printers and WinSpool in the Uses clause.
@Raises EWin32Error if the OpenPrinter call fails.
}{ Created 30.9.2000 by P. Below
-----------------------------------------------------------------------}
function GetCurrentPrinterHandle: THandle;
const
Defaults: TPrinterDefaults = (
pDatatype : nil;
pDevMode : nil;
DesiredAccess : PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER );
var
Device, Driver, Port : array[0..255] of char;
hDeviceMode: THandle;
begin { GetCurrentPrinterHandle }
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
Win32Check( OpenPrinter(@Device, Result, @Defaults));
end; { GetCurrentPrinterHandle }
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads