I would like to get a unique identifer into the inf file that pdfspooler writes it uses the env var REDMON_DOCNAME
When I print from with a vb app using printer.print it is always set to 'Microsoft Visual Basic'
what do i need to set in the vb app to pass a different doc name to the print spooler
I am not sure if it is possible with the VB built in functions, but the REDMON_DOCNAME contains the Print jobs name. This normally is passed by the printing application (as it says Micorsoft Visual Basic in your case), only under Windows 2000 it will say "Print Job n".
Maybe you could settle over the the PDFCreator COM Object to control the conversion process. There you can set all PDF Fields from inside your application.
regards,
Philip
OK here is 1 way
change the name of the job when you know it is first in the q might be kinda nice to add that to PDFCreator
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As Long 'LPDEVMODEA
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As Long 'PSECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
JobsCount As Long
AveragePPM As Long
End Type
Private Type JOB_INFO_1
JobID As Long
lpPrinterName As String
lpMachinename As String
lpUserName As String
lpDocumentName As String
lpDataType As String
lpStatus As String
Status As Long
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
DesiredAccess As Long
End Type
Private Enum PrinterAccessRights
' ##ENUMERATION_MEMBER_DESCRIPTION PRINTER_ACCESS_ADMINISTER Allows administration of a printer
PRINTER_ACCESS_ADMINISTER = &H4
' ##ENUMERATION_MEMBER_DESCRIPTION PRINTER_ACCESS_USE Allows printer general use (printing, querying)
PRINTER_ACCESS_USE = &H8
' ##ENUMERATION_MEMBER_DESCRIPTION PRINTER_ALL_ACCESS Allows use and administration.
PRINTER_ALL_ACCESS = &HF000C
End Enum
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function GetPrinterApi Lib "winspool.drv" Alias _
"GetPrinterA" (ByVal hPrinter As Long, _
ByVal Level As Long, _
buffer As Long, _
ByVal pbSize As Long, _
pbSizeNeeded As Long) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal _
hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, _
pJob As Long, ByVal cdBuff As Long, pcbNeeded As Long, pcBytesReturned As Long) As Long
Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" _
(ByVal hPrinter As Long, _
ByVal JobID As Long, _
ByVal Level As Long, _
buffer As Long, _
ByVal pbSize As Long, _
pbSizeNeeded As Long) As Long
Private Declare Function SetJob Lib "winspool.drv" Alias _
"SetJobA" (ByVal hPrinter As Long, _
ByVal JobID As Long, _
ByVal Level As Long, _
pJob As Long, _
ByVal Command As Long) As Long
Private Declare Function GetSpoolFileHandle Lib "winspool.drv" Alias "GetSpoolFileHandleA" _
(ByVal hPrinter As Long) As Long
Private Declare Function CloseSpoolFileHandle Lib "winspool.drv" Alias "CloseSpoolFileHandleA" _
(ByVal hPrinter As Long, ByVal hFile As Long) As Long
'eg
'PORT= PDFCreator:
'JOB= 8
'PRINTER ecPDFWriter
'MACHINE= \\W2K3-TOPCAT
'USER administrator
'DOCNAME Microsoft Visual Basic
'SESSIONID 0+
'FileName D:\tmp\PDFSpooler\PDFCreatorSpool\~PSA4.tmp
'SPACCT SYSTEM
'COMPUTER W2K3-TOPCAT
'CREATED 6/22/2007 10:21:24 PM
'All Prpoerty Assigments might want to make a class of these options
Private mOutputDirectory As String
Private mFilename As String
Private mSpoolFilename As String
Private mDocumentName As String
Private mPDFAuthor As String
Private mPDFKeywords As String
Private mPrinterHandleDC As Long
Private msDeviceName As String
Private mJobDocumentName As String
Public Property Let DeviceName(ByVal sDeviceName As String)
Dim lRet As Long
Dim pDef As PRINTER_DEFAULTS
'http://www.vbforums.com/showthread.php?t=443160
If sDeviceName <> msDeviceName Then
msDeviceName = sDeviceName
If mPrinterHandleDC <> 0 Then
Call ClosePrinter(mPrinterHandleDC)
If Err.LastDllError Then
'ReportError Err.LastDllError, CLSNAME & ":DeviceName", GetLastSystemError
Debug.Print Err.LastDllError
Else
mPrinterHandleDC = 0
End If
End If
If mPrinterHandleDC = 0 Then
'\\ If the access hasn't been pre-specified, try all access
If pDef.DesiredAccess = 0 Then
pDef.DesiredAccess = PRINTER_ALL_ACCESS
End If
'\\ Need to get the printer handle for the printer device named
lRet = OpenPrinter(sDeviceName, mPrinterHandleDC, pDef)
If Err.LastDllError Then
'ReportError Err.LastDllError, CLSNAME & ":DeviceName (Let)", GetLastSystemError
Debug.Print Err.LastDllError
End If
RefreshPrinterInfo
End If
End If
End Property
Public Property Let JobDocumentName(ByVal sJobDocumentName As String)
Const sJobDocName = "Microsoft Visual Basic"
Dim sDocName As String
Dim dJobInfo1 As JOB_INFO_1
Dim lRet As Long
Dim pcbSizeRequired As Long, pcbBytesReturned As Long
Dim pJobId As Long
Dim lJobID As Long
Dim buffer() As Long
ReDim Preserve buffer(0) As Long
'Call the enum jobs using the Opened printer handle
lRet = EnumJobs(mPrinterHandleDC, 0, 255, 1, buffer(0), UBound(buffer), pcbSizeRequired, pcbBytesReturned)
If pcbSizeRequired > 0 Then
'\\ Need to resize our array to cope with this data
ReDim Preserve buffer(0 To (pcbSizeRequired / 4) + 3) As Long
lRet = EnumJobs(mPrinterHandleDC, 0, 255, 1, buffer(0), UBound(buffer) * 4, pcbSizeRequired, pcbBytesReturned)
'\\ Note any error if this has failed
If Err.LastDllError <> 0 Then
'Call ReportError(Err.LastDllError, CLSNAME & ":PrintJobs", GetLastSystemError)
Debug.Print Err.LastDllError
End If
'\\ At this stage buffer() contains an array of JOB_INFO_1 structures
'\\ For each job...
For pJobId = 0 To (pcbBytesReturned - 1) 'each record is 16 bytes long
lJobID = buffer(0)
sDocName = StringFromPointer(buffer(4), 1024)
If sDocName = sJobDocName Then
SavePrintJobInfo mPrinterHandleDC, lJobID, sJobDocumentName
Exit For
End If
Next pJobId
mJobDocumentName = sJobDocumentName
End If
Private Sub SavePrintJobInfo(ByVal hPrinter As Long, JobID As Long, sDocumentName As String)
'On Error GoTo Error
Dim lRet As Long
Dim SizeNeeded As Long
Dim buffer() As Long
ReDim Preserve buffer(0 To 1) As Long
lRet = GetJob(hPrinter, JobID, 1, buffer(0), UBound(buffer), SizeNeeded)
If SizeNeeded > 0 Then
ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
lRet = GetJob(hPrinter, JobID, 1, buffer(0), UBound(buffer) * 4, SizeNeeded)
End If
buffer(4) = LPCSTR(sDocumentName)
lRet = SetJob(hPrinter, JobID, 1, buffer(0), 0)
If Err.LastDllError Then
'ReportError Err.LastDllError, CLSNAME & ":ResumeJob", GetLastSystemError
Debug.Print Err.LastDllError
End If
End Sub