Hi All,
Does anyone have an example of how to capture pring job information so it creates a log entry every time anything is sent to any printer(any printer or any print job ie date time job size etc). I think there are some APIs that can be used but i haven been able to find any information on the PB forums. Any ideas.
Thanks in advance.
Rick
Capturing print job information
> I guess this question is to hard
Try converting this: http://support.microsoft.com/kb/228769/EN-US/
Try converting this: http://support.microsoft.com/kb/228769/EN-US/
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
had some free time
Regards Klaus

Code: Select all
#MAX_PRINTERS=255
dwFlags=#PRINTER_ENUM_CONNECTIONS | #PRINTER_ENUM_LOCAL
Dim hPrinter(#MAX_PRINTERS)
pcbNeeded=0
pcReturned=0
dwBytesNeeded=0
dwReturned=0
*pJobInfo.JOB_INFO_2
*pinfo4.PRINTER_INFO_4
Dim previous(#MAX_PRINTERS)
For i=0 To #MAX_PRINTERS
previous(i)=0
Next
While Not EnumPrinters_(dwFlags,0,4,*pinfo4,dwBytesNeeded,@dwBytesNeeded,@dwReturned)
If GetLastError_()=#ERROR_INSUFFICIENT_BUFFER
If *pinfo4
FreeMemory(*pinfo4)
EndIf
*pinfo4=AllocateMemory(dwBytesNeeded * SizeOf(PRINTER_INFO_4))
Else
Debug "Enumprinters failed: "+Str(GetLastError_())
Goto Cleanup
EndIf
Wend
Debug "*******************************************************"
Debug "# OF PRINTERS (Local/Networked) INSTALLED ON YOUR MACHINE ="+Str(dwReturned)
If dwReturned
*pinfo4temp.PRINTER_INFO_4=*pinfo4
For i = 0 To dwReturned-1
Debug "Printer #"+Str(i+1)+": "+PeekS(*pinfo4temp\pPrinterName)
*pinfo4temp+SizeOf(PRINTER_INFO_4)
Next
*pinfo4temp.PRINTER_INFO_4=*pinfo4
For i = 0 To dwReturned-1
If Not OpenPrinter_(PeekS(*pinfo4temp\pPrinterName),@hPrinter(i),0)
Debug "OpenPrinter failed: "+Str(GetLastError_())
Goto Cleanup
EndIf
*pinfo4temp+SizeOf(PRINTER_INFO_4)
Next
Repeat ; Keep polling ForEver And dump the info whenever a job is submitted To any printer.
*pinfo4temp.PRINTER_INFO_4=*pinfo4
For i = 0 To dwReturned-1
While Not EnumJobs_(hPrinter(i), 0, 1, 2, *pJobInfo, pcbNeeded, @pcbNeeded, @pcReturned)
If GetLastError_()=#ERROR_INSUFFICIENT_BUFFER
If *pJobInfo
FreeMemory(*pJobInfo)
*pJobInfo=0
EndIf
*pJobInfo = AllocateMemory(pcbNeeded * SizeOf(JOB_INFO_2))
Else
Debug "EnumJobs on printer "+Str(i+1)+" failed: "+Str(GetLastError_())
Goto Cleanup
EndIf
Wend
If pcReturned>0
If *pJobInfo\JobId Not previous(i)
previous(i) = *pJobInfo\JobId
Debug "PRINTER # "+Str(i+1)+" IS PRINTING ************"
Debug "DUMP THE INFO FROM THE CURRENT JOB - devmode"
;******************************************************
*pDevMode.DEVMODE=*pJobInfo\pDevMode
If *pDevMode\dmFields & #DM_YRESOLUTION
Debug "dmYResolution: "+Str(*pDevMode\dmYResolution)+" dpi"
EndIf
If *pDevMode\dmPrintQuality & (#DMRES_HIGH | #DMRES_MEDIUM | #DMRES_LOW | #DMRES_DRAFT)
Debug "Print Quality: "+Str(*pDevMode\dmPrintQuality)+" dpi"
EndIf
;******************************************************
;* Check if Orientation is Portrait or Landscape *
;******************************************************
If *pDevMode\dmOrientation = #DMORIENT_PORTRAIT
Debug "Orientation:Portrait"
EndIf
If *pDevMode\dmOrientation = #DMORIENT_LANDSCAPE
Debug "Orientation:Landscape"
EndIf
;******************************************************
If *pDevMode\dmFields & #DM_COPIES
Debug "Num of Copies: "+Str(*pDevMode\dmCopies)
EndIf
If *pDevMode\dmFields & #DM_PAPERLENGTH
Debug "Paper Length: "+Str(*pDevMode\dmPaperLength)
EndIf
If *pDevMode\dmFields & #DM_PAPERWIDTH
Debug "Paper Width: "+Str(*pDevMode\dmPaperWidth)
EndIf
;******************************************************/
If *pDevMode\dmDuplex & #DM_DUPLEX
Debug "Duplex Mode ON"
EndIf
If *pDevMode\dmColor = #DMCOLOR_COLOR
Debug "Color Image"
Else
Debug "Monochrome Image"
EndIf
If *pDevMode\dmFields & #DM_BITSPERPEL
Debug "Bits Per Pel: "+Str(*pDevMode\dmBitsPerPel)
EndIf
Debug "JOB INFO-2 dump **************"
Debug "JobId : "+Str(*pJobInfo\JobId)
Debug "Printer Name : "+PeekS(*pJobInfo\pPrinterName)
Debug "Machine Name : "+PeekS(*pJobInfo\pMachineName)
Debug "User Name : "+PeekS(*pJobInfo\pUserName)
Debug "Document : "+PeekS(*pJobInfo\pDocument)
Debug "Notify Name : "+PeekS(*pJobInfo\pNotifyName)
Debug "Datatype : "+PeekS(*pJobInfo\pDatatype)
Debug "Print Processor : "+PeekS(*pJobInfo\pPrintProcessor)
Debug "Parameters : "+Str(*pJobInfo\pParameters)
Debug "Driver Name : "+PeekS(*pJobInfo\pDriverName)
Debug "TotalPages : "+Str(*pJobInfo\TotalPages)
Debug "Size : "+Str(*pJobInfo\iSize)
SystemTimeToTzSpecificLocalTime_(0,*pJobInfo\Submitted,LocalTime.SYSTEMTIME)
Debug "Date Submitted : "+Str(LocalTime\wYear)+"/"+RSet(Str(LocalTime\wMonth),2,"0")+"/"+RSet(Str(LocalTime\wDay),2,"0")
Debug "Time Submitted : "+RSet(Str(LocalTime\wHour),2,"0")+":"+RSet(Str(LocalTime\wMinute),2,"0")+":"+RSet(Str(LocalTime\wSecond),2,"0")
EndIf
EndIf
Next
Delay(10)
ForEver
EndIf
Cleanup:
For i = 0 To dwReturned-1
If Not ClosePrinter_(hPrinter(i))
Debug "ClosePrinter failed: "+Str(GetLastError_())
EndIf
Next
If *pJobInfo
FreeMemory(*pJobInfo)
EndIf
If *pinfo4
FreeMemory(*pinfo4)
EndIf
Last edited by ABBKlaus on Sun Jun 10, 2007 12:39 pm, edited 1 time in total.
Code: Select all
Line 134: GetLastError() is not a function, array, macro or linked list
Code: Select all
Debug "ClosePrinter failed: "+Str(GetLastError_())
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re:
Sorry for raising such an old thread, but this is a fantastic piece of code example.ABBKlaus wrote:had some free time![]()
Is it possible to obtain (raw?) data from these structures so one could use DOC_INFO_1 structure to set output to file and than print it out with WritePrinter() which requires pointer to data in order to work? I was skimming through documentation but can't seem to find anything useful so far.
So basically, once print job is detected, I would like to obtain data that is being printed and save it somewhere else apart from them being printed out; perhaps in that case, I don't even have to use WritePrinter() put can save data as a raw document with inbuilt PureBasic functions... Is that even theoretically possible with API?
Thank you in advance for any clues whatsoever!
With my best,
Bruno