Thanks for your comment Radikal
By any chance how do i know how many of those pages that were sent to the printer are already printed? So that i may really know the amount of totalpages that have been printed, cause i might send 10 pages and cancel the printing job, so that none of the pages is printed and the way you suggest imigth end up counting pages that haven't been print.
I found something similar to what you posted here on the web, they suggest to use a timer and set the interval to 500 or less so i could catched the PagesPrinted but i tried it and it didn't do what i expected. There is a second option similar to both yours and the one i tried already, these third one i haven't had the chance to test it. So let see what happens.
Code i tested uses a line like thisone to get the total of printed pages, but doesn't work.
IntToStr( PTrabajo^[i].PagesPrinted
while the job is still in the spool and paused it gives me 0, once it is printing retrieves 0 and when the printing job is ended it returns nothing, as far as i have tested it.
The only difference between yours and the one i tested is that you use JOB_INFO_2 and that one uses JOB_INFO_1, everything else is pretty much the same.
I hope u understand what i want to get with the PagesPrinted.
Main Topics
Browse All Topics





by: RadikalQ3Posted on 2005-08-28 at 02:14:30ID: 14770515
Hi!
: TObject);
Driver, Port, hDeviceMode);
rinter; 0,
'+IntToStr(TrabajosRecibid os) );
opies )
;
You can enumerate the printer Jobs, using the JOB_INFO_2 structure and calculate the total pages of the document with the member TotalPages and the member pDevMode.dmCopies of that structure.
Here you have an example of printer jobs enumeration:
- Add Printers,Winspool to the uses line
- Put a TMemo (Memo1) in your form
procedure TForm1.Button1Click(Sender
function OpenDefaultPrinter: 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
Printer.GetPrinter(Device,
if not OpenPrinter(@Device, Result, @Defaults) then RaiseLastWin32Error;
end;
type
TTrabajos = array [0..9000] of JOB_INFO_2;
PTrabajos = ^TTrabajos;
var
MangoPrinter : Thandle;
PTrabajo : PTrabajos;
BytesRecibidos : DWord;
TrabajosRecibidos : DWord;
i : integer;
begin
MangoPrinter:=OpenDefaultP
try
{Get the size of the enumeration}
EnumJobs( MangoPrinter,0,9000,2,Nil,
BytesRecibidos,
TrabajosRecibidos );
{Get mem for response}
PTrabajo := AllocMem( BytesRecibidos );
try
if not EnumJobs( MangoPrinter,
0, //Empezando por el primero
9000, //Numero de jobs a enumerar
2,
PTrabajo,
BytesRecibidos,
BytesRecibidos,
TrabajosRecibidos) then RaiseLastWin32Error;
Memo1.Lines.Clear;
Memo1.Lines.Add('Trabajos:
{Llenamos el Memo1 con datos de los trabajos}
for i:= 0 to Pred(TrabajosRecibidos) do
memo1.lines.add( PTrabajo^[i].pDocument +' - Send By: '+
PTrabajo^[i].pMachineName +' - Pages: '+
IntToStr( PTrabajo^[i].TotalPages * PTrabajo^[i].pDevMode^.dmC
);
finally
FreeMem( PTrabajo );
end;
finally
ClosePrinter(MangoPrinter)
end;
end;