|
-
Dec 22nd, 2003, 05:16 PM
#1
Thread Starter
New Member
[SOLVED] Change 'Document Name' property for a print job
I need to change the 'Document name' property of a job sent to a printer queue - I'm working in Windows 2000 using VB6 sp5.
In particular, I'd like to change the 'Document Name' property of a job submitted from a Ms Word object using the 'PrintOut' method of the Ms Word App object v. 9.0.
The print job is to be processed by an application (OCE Prisma Satellite) that MUST identify the job by its 'Document name' property. If the job doesn't have EXACTLY the required name the process fails. Ms Word prefixes every print job with the string 'Microsoft Word - ', thus screwing the whole thing up.
This external application will process the print job directly from the printing queue once this job has been submiited. Therefore, nothing else has to be done apart from submitting the print job with the correct name.
To sum up, all I need to do is to merge a MS Word template with a merge file and then send the merged document(s) to a printer setting the required 'Document name' property for the print job.
Please, help.
Last edited by jab2; Dec 25th, 2003 at 09:49 AM.
-
Dec 23rd, 2003, 06:05 AM
#2
Addicted Member
Re: Change 'Document Name' property for a print job
Originally posted by jab2
I need to change the 'Document name' property of a job sent to a printer queue - I'm working in Windows 2000 using VB6 sp5.
In particular, I'd like to change the 'Document Name' property of a job submitted from a Ms Word object using the 'PrintOut' method of the Ms Word App object v. 9.0.
The print job is to be processed by an application (OCE Prisma Satellite) that MUST identify the job by its 'Document name' property. If the job doesn't have EXACTLY the required name the process fails. Ms Word prefixes every print job with the string 'Microsoft Word - ', thus screwing the whole thing up.
This external application will process the print job directly from the printing queue once this job has been submiited. Therefore, nothing else has to be done apart from submitting the print job with the correct name.
To sum up, all I need to do is to merge a MS Word template with a merge file and then send the merged document(s) to a printer setting the required 'Document name' property for the print job.
Please, help.
Try changing the app.name for every print job and u'll see the app.name in the printer i hope.
Cute Member 
-
Dec 23rd, 2003, 06:18 AM
#3
Thread Starter
New Member
Thanks cutamacious.
What you say in your reply is totally correct, and it works when you print directly form VB without using the Ms Word Application Object (selectable from the project references).
The problem is:
1. The Word Application Object when used from a VB application will always add the prefix 'Microsoft Word - ' to anything you try to print using this object - whatever the .exe name is.
2. (LESS IMPORTANT) I have many different documents to print, and it would be better to find something that allows me to change the print job name directly.
Another helpful person pointed me to the link:
http://www.codeoftheweek.com/issues/0100.html
Which happens to be exactly what I need (apart from being code from 1999 probably vb4.0-based), but the site seems to be unactive/dead and cannot get to the source code because you need to subscribe and there's no one to process my application.
So still looking for something else, or someone who's got the source code that the link refers to.
Many thanks again.
Jordi
-
Dec 23rd, 2003, 06:55 AM
#4
I think I've seen something on this forum that can do that..
ah-ha! here's one.. http://www.vbforums.com/showthread.p...hreadid=258243
that should do nicely
-
Dec 23rd, 2003, 08:11 AM
#5
Lots and lots of code.....
VB Code:
Option Explicit
'\\ API declarations
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
DesiredAccess As Long
End Type
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 ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private mhPrinter As Long
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 PrintJobStatuses
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type
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
'\\ When changing information other than the position for JOB_INFO_1 and
'\\ JOB_INFO_2 you must set the Position member to JOB_POSITION_UNSPECIFIED
Private Const JOB_POSITION_UNSPECIFIED = 0
Private mJOB_INFO_1 As JOB_INFO_1
Private buffer() As Long
Private Sub RefreshJobInfo()
Dim lret As Long
Dim SizeNeeded As Long
ReDim Preserve buffer(0 To 1) As Long
lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer), SizeNeeded)
If SizeNeeded > 0 Then
ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer) * 4, SizeNeeded)
With mJOB_INFO_1
.JobId = buffer(0)
.lpPrinterName = StringFromPointer(buffer(1), 1024)
.lpMachinename = StringFromPointer(buffer(2), 1024)
.lpUserName = StringFromPointer(buffer(3), 1024)
.lpDocumentName = StringFromPointer(buffer(4), 1024)
.lpDataType = StringFromPointer(buffer(5), 1024)
.lpStatus = StringFromPointer(buffer(6), 1024)
.Status = buffer(7)
.Priority = buffer(8)
.Position = buffer(9)
.TotalPages = buffer(10)
.PagesPrinted = buffer(11)
'Submitted is also here...
With .Submitted
.wYear = LoWord(buffer(12))
.wMonth = HiWord(buffer(12))
.wDayOfWeek = LoWord(buffer(13))
.wDay = HiWord(buffer(13))
.wHour = LoWord(buffer(14))
.wMinute = HiWord(buffer(14))
.wSecond = LoWord(buffer(15))
.wMilliseconds = HiWord(buffer(15))
End With
End With
End If
End Sub
Private Sub SavePrintJobInfo()
Dim lret As Long
With mJOB_INFO_1
buffer(0) = .JobId '\\ This cannot change and is ignored
buffer(1) = LPCSTR(.lpPrinterName) '\\ This is ignored and cannot be changed
buffer(2) = LPCSTR(.lpMachinename) '\\ also ignored
buffer(3) = LPCSTR(.lpUserName)
buffer(4) = LPCSTR(.lpDocumentName)
buffer(5) = LPCSTR(.lpDataType)
buffer(6) = LPCSTR(.lpStatus)
buffer(7) = .Status
buffer(8) = .Priority
buffer(9) = .Position
buffer(10) = .TotalPages
buffer(11) = .PagesPrinted
With .Submitted '\\ Also ignored
buffer(12) = MakeLong(.wYear, .wMonth)
buffer(13) = MakeLong(.wDayOfWeek, .wDay)
buffer(14) = MakeLong(.wHour, .wMinute)
buffer(15) = MakeLong(.wSecond, .wMilliseconds)
End With
End With
lret = SetJob(mhPrinter, mJobId, Level, buffer(0), 0)
End Sub
...more follows....
-
Dec 23rd, 2003, 08:15 AM
#6
VB Code:
Public Sub ChangeDocName(byval JobId As Long, ByVal NewName As String)
pDef.DesiredAccess = PRINTER_ALL_ACCESS
lret = OpenPrinter(newname, mhPrinter, pDef)
If mhPrinter Then
Call RefreshJobInfo
mJOB_INFO_1.lpDocumentName = Newname
Call SaveJobInfo
Call ClosePrinter(mhPrinter)
End If
End Sub
-
Dec 24th, 2003, 08:57 AM
#7
Thread Starter
New Member
Thanks a lot si and Merrion. This is really helping me.
I started working on the post that si directed me to, and then added up the code that Merrion kindly posted.
I had to made several additions to the code, such as adding the StringFromPointer function and its references, declaring the SYSTEMTIME structure, and other minor declarations. Most of it I've taken from the very helpful Merrion's site.
Just three doubts about what I've done so far:
1- what shall I do with the SetJob's 'Level' variable (if anything),
2- I've referenced the EventVB dll but I'm not sure if I really need to, and
3- do I need to make any changes to the pDef variable other than setting the 'Desired Access' member to 'PRINTER_ALL_ACCESS' ?.
At present I'm stuck with the VB6 version of LPCSTR because I couldn't find it anywhere, and I need it to save the print job changes. If any of you guys knows where I can find the source code of a LPCSTR version for VB6, please let me know.
Thanks very much again, you guys are doing a great job here.
Jordi
-
Dec 25th, 2003, 09:10 AM
#8
Thread Starter
New Member
I've managed to copy the new name into the appropriate parameter passed onto the 'SetJob' API call. This is using the API function 'CopyMemory'.
However, the name of the document remains unchanged. This means that something it's not working here.
Before calling 'SetJob' I ensure that the parameter storing the 'Document Name' (a long pointer to string) points to the portion of memory containing the new name for the document.
I'm logged in as Administrator with all sort of rights and permissions.
I don't know why it fails.
Please, help.
-
Dec 25th, 2003, 09:47 AM
#9
Thread Starter
New Member
[SOLVED] Change 'Document Name' property for a print job
Just managed to fix the problem by resetting the mem area pointed and changing the level value. Thx.
-
Mar 13th, 2004, 09:32 AM
#10
New Member
Could you please post the code and an example of how you call it and do the necessary reset?
Thanks,
- Ido
[email protected]
-
May 20th, 2013, 01:36 AM
#11
New Member
Re: [SOLVED] Change 'Document Name' property for a print job
Hi jab2,
How did you get past the LPCSTR issue?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|