Results 1 to 11 of 11

Thread: [SOLVED] Change 'Document Name' property for a print job

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    5

    Question [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.

  2. #2
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    5
    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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

  5. #5
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Lots and lots of code.....

    VB Code:
    1. Option Explicit
    2. '\\ API declarations
    3. Private Type PRINTER_DEFAULTS
    4.   pDatatype As String
    5.   pDevMode As Long
    6.   DesiredAccess As Long
    7. End Type
    8.  
    9. Private Declare Function OpenPrinter Lib "winspool.drv" _
    10.         Alias "OpenPrinterA" (ByVal pPrinterName As String, _
    11.         phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
    12.  
    13. Private Declare Function ClosePrinter Lib "winspool.drv" _
    14.         (ByVal hPrinter As Long) As Long
    15.  
    16. Private mhPrinter As Long
    17.  
    18. Private Type JOB_INFO_1
    19.     JobId As Long
    20.     lpPrinterName As String
    21.     lpMachinename As String
    22.     lpUserName As String
    23.     lpDocumentName As String
    24.     lpDataType As String
    25.     lpStatus As String
    26.     Status As PrintJobStatuses
    27.     Priority As Long
    28.     Position As Long
    29.     TotalPages As Long
    30.     PagesPrinted As Long
    31.     Submitted As SYSTEMTIME
    32. End Type
    33.  
    34. Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" _
    35.                           (ByVal hPrinter As Long, _
    36.                            ByVal JobId As Long, _
    37.                            ByVal Level As Long, _
    38.                            buffer As Long, _
    39.                            ByVal pbSize As Long, _
    40.                            pbSizeNeeded As Long) As Long
    41.  
    42. Private Declare Function SetJob Lib "winspool.drv" Alias _
    43.                      "SetJobA" (ByVal hPrinter As Long, _
    44.                                 ByVal JobId As Long, _
    45.                                 ByVal Level As Long, _
    46.                                 pJob As Long, _
    47.                                 ByVal Command As Long) As Long
    48.  
    49. '\\ When changing information other than the position for JOB_INFO_1 and
    50. '\\ JOB_INFO_2 you must set the Position member to JOB_POSITION_UNSPECIFIED
    51. Private Const JOB_POSITION_UNSPECIFIED = 0
    52.  
    53. Private mJOB_INFO_1 As JOB_INFO_1
    54. Private buffer() As Long
    55.  
    56. Private Sub RefreshJobInfo()
    57.  
    58. Dim lret As Long
    59. Dim SizeNeeded As Long
    60.  
    61.     ReDim Preserve buffer(0 To 1) As Long
    62.     lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer), SizeNeeded)
    63.  
    64.     If SizeNeeded > 0 Then
    65.         ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
    66.         lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer) * 4, SizeNeeded)
    67.  
    68.                 With mJOB_INFO_1
    69.                     .JobId = buffer(0)
    70.                     .lpPrinterName = StringFromPointer(buffer(1), 1024)
    71.                     .lpMachinename = StringFromPointer(buffer(2), 1024)
    72.                     .lpUserName = StringFromPointer(buffer(3), 1024)
    73.                     .lpDocumentName = StringFromPointer(buffer(4), 1024)
    74.                     .lpDataType = StringFromPointer(buffer(5), 1024)
    75.                     .lpStatus = StringFromPointer(buffer(6), 1024)
    76.                     .Status = buffer(7)
    77.                     .Priority = buffer(8)
    78.                     .Position = buffer(9)
    79.                     .TotalPages = buffer(10)
    80.                     .PagesPrinted = buffer(11)
    81.                     'Submitted is also here...
    82.                     With .Submitted
    83.                         .wYear = LoWord(buffer(12))
    84.                         .wMonth = HiWord(buffer(12))
    85.                         .wDayOfWeek = LoWord(buffer(13))
    86.                         .wDay = HiWord(buffer(13))
    87.                         .wHour = LoWord(buffer(14))
    88.                         .wMinute = HiWord(buffer(14))
    89.                         .wSecond = LoWord(buffer(15))
    90.                         .wMilliseconds = HiWord(buffer(15))
    91.                     End With
    92.                 End With
    93.        End If
    94. End Sub
    95.  
    96. Private Sub SavePrintJobInfo()
    97.  
    98. Dim lret As Long
    99.  
    100.     With mJOB_INFO_1
    101.         buffer(0) = .JobId '\\ This cannot change and is ignored
    102.         buffer(1) = LPCSTR(.lpPrinterName) '\\ This is ignored and cannot be changed
    103.         buffer(2) = LPCSTR(.lpMachinename) '\\ also ignored
    104.         buffer(3) = LPCSTR(.lpUserName)
    105.         buffer(4) = LPCSTR(.lpDocumentName)
    106.         buffer(5) = LPCSTR(.lpDataType)
    107.         buffer(6) = LPCSTR(.lpStatus)
    108.         buffer(7) = .Status
    109.         buffer(8) = .Priority
    110.         buffer(9) = .Position
    111.         buffer(10) = .TotalPages
    112.         buffer(11) = .PagesPrinted
    113.         With .Submitted '\\ Also ignored
    114.             buffer(12) = MakeLong(.wYear, .wMonth)
    115.             buffer(13) = MakeLong(.wDayOfWeek, .wDay)
    116.             buffer(14) = MakeLong(.wHour, .wMinute)
    117.             buffer(15) = MakeLong(.wSecond, .wMilliseconds)
    118.         End With
    119.     End With
    120.  
    121.     lret = SetJob(mhPrinter, mJobId, Level, buffer(0), 0)
    122.  
    123. End Sub

    ...more follows....

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    VB Code:
    1. Public Sub ChangeDocName(byval JobId As Long, ByVal NewName As String)
    2.  
    3. pDef.DesiredAccess = PRINTER_ALL_ACCESS
    4. lret = OpenPrinter(newname, mhPrinter, pDef)
    5.  
    6. If mhPrinter Then
    7.     Call RefreshJobInfo
    8.     mJOB_INFO_1.lpDocumentName = Newname
    9.     Call SaveJobInfo
    10.  
    11.      Call ClosePrinter(mhPrinter)
    12. End If
    13.  
    14. End Sub

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    5

    Arrow

    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    5
    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    London, UK
    Posts
    5

    Talking [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.

  10. #10
    New Member
    Join Date
    Mar 2004
    Location
    USA
    Posts
    2
    Could you please post the code and an example of how you call it and do the necessary reset?

    Thanks,
    - Ido
    [email protected]

  11. #11
    New Member
    Join Date
    May 2013
    Location
    Johannesburg, South Africa
    Posts
    2

    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
  •  



Click Here to Expand Forum to Full Width