Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adobe 8 Print Error 1

Status
Not open for further replies.

joebb3

Programmer
Feb 27, 2006
87
US
First off, I cannot use any 3rd party software to fix this issue and I cannot revert to previous versions of adobe. I am literally STUCK with what I have. (Adobe Reader 8.1.2)

I use this code to print a PDF Document.

Code:
Option Compare Database
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 3            'Open Maximized
Public Const WIN_MIN = 2            'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL:          ?fHandleFile("[URL unfurl="true"]http://home.att.net/~dashish",[/URL] WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
'                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
'                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
    'First try ShellExecute
    'lRet = apiShellExecute(hWndAccessApp, vbNullString, _
            stFile, vbNullString, vbNullString, lShowHow)
     lRet = apiShellExecute(hWndAccessApp, "print", _
            stFile, vbNullString, vbNullString, lShowHow)
           
    If lRet > ERROR_SUCCESS Then
        stRet = vbNullString
        lRet = -1
    Else
        Select Case lRet
            Case ERROR_NO_ASSOC:
                'Try the OpenWith dialog
                varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                        & stFile, WIN_NORMAL)
                lRet = (varTaskID <> 0)
            Case ERROR_OUT_OF_MEM:
                stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
            Case ERROR_FILE_NOT_FOUND:
                stRet = "Error: File not found.  Couldn't Execute!"
            Case ERROR_PATH_NOT_FOUND:
                stRet = "Error: Path not found. Couldn't Execute!"
            Case ERROR_BAD_FORMAT:
                stRet = "Error:  Bad File Format. Couldn't Execute!"
            Case Else:
        End Select
    End If
    fHandleFile = lRet & _
                IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'************ Code End **********

The problem is that I get an error After Adobe closes the print job (ver 8.1 has this error documented) and it stops my string of printing documents (I print a package of seperate documents all of different extentions)

Now, I found out that if you hold the SHIFT key down, it stops Adobe from loading plugins. So if I hold the SHIFT key, all works well. (With the added bonus of SILENT printing!)

My question is, "Can I simulate HOLDING DOWN the shift key during the print jobs with visual basic?" I print 3 pdfs, one after the other, so I guess I would have to release the shift key and repress it in between each document.

I REALLY hope someone has a suggestion!
Thanx in advance!
Joe
 
Addendum:

I just ran a test.

If I hold the SHIFT key down during my entire print job, EVERYTHING works like a champ! So the error is in the adobe plugins.

If I could simulate the SHIFT key press during the entire job, that would work! Or perhaps altering the shell comand to tell adobe NOT to load the plug ins.

Of course, if I knew how to do this, I wouldn't be asking. I would have written a faq instead. LOL!!!

Joe

PS: I guess I could use the low tech fix of a message box saying "Hold down the SHIFT key now!" but I don't really want to do that.
 
Well... I figured it out and I thought I'd post it just in case someone else has the same issue. It seem like a LOT to go through just to print a stinking PDF file, but it works.

Call
Code:
fHandleFile <<Full path of PDF as String>>, WIN_NORMAL
where you want to print the PDF.

here is the fHandleFile module (modified to PRINT). Put this code into a module.

Code:
Option Compare Database
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 3            'Open Maximized
Public Const WIN_MIN = 2            'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL:          ?fHandleFile("[URL unfurl="true"]http://home.att.net/~dashish",[/URL] WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
'                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
'                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
    
Call PressKeyVK(keyShift, True, False)
    
    'First try ShellExecute
    'lRet = apiShellExecute(hWndAccessApp, vbNullString, _
            stFile, vbNullString, vbNullString, lShowHow)
     lRet = apiShellExecute(hWndAccessApp, "print", _
            stFile, vbNullString, vbNullString, lShowHow)
           
    If lRet > ERROR_SUCCESS Then
        stRet = vbNullString
        lRet = -1
    Else
        Select Case lRet
            Case ERROR_NO_ASSOC:
                'Try the OpenWith dialog
                varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                        & stFile, WIN_NORMAL)
                lRet = (varTaskID <> 0)
            Case ERROR_OUT_OF_MEM:
                stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
            Case ERROR_FILE_NOT_FOUND:
                stRet = "Error: File not found.  Couldn't Execute!"
            Case ERROR_PATH_NOT_FOUND:
                stRet = "Error: Path not found. Couldn't Execute!"
            Case ERROR_BAD_FORMAT:
                stRet = "Error:  Bad File Format. Couldn't Execute!"
            Case Else:
        End Select
    End If
    fHandleFile = lRet & _
                IIf(stRet = "", vbNullString, ", " & stRet)
PauseFor (10)
'DoEvents
Call PressKeyVK(keyShift, False, True)


End Function
'************ Code End **********

Make another module and put the following code in it. This code is an alternative to sendkey. I found it on the web somewhere. Its not my code, but there is no "Credits" in the code, so I can't give specific credit to the author.

Code:
Option Explicit

Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Any) As Long

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

   
Public Enum eKeys
    keyBackspace = &H8
    keyTab = &H9
    keyReturn = &HD
    keyShift = &H10
    keyControl = &H11
    keyAlt = &H12
    keyPause = &H13
    keyEscape = &H1B
    keySpace = &H20
    keyEnd = &H23
    keyHome = &H24
    keyLeft = &H25
    KeyUp = &H26
    keyRight = &H27
    KeyDown = &H28
    keyInsert = &H2D
    keyDelete = &H2E
    keyF1 = &H70
    keyF2 = &H71
    keyF3 = &H72
    keyF4 = &H73
    keyF5 = &H74
    keyF6 = &H75
    keyF7 = &H76
    keyF8 = &H77
    keyF9 = &H78
    keyF10 = &H79
    keyF11 = &H7A
    keyF12 = &H7B
    keyNumLock = &H90
    keyScrollLock = &H91
    keyCapsLock = &H14
End Enum

Public Enum eLockKey
    CapsLock = keyCapsLock
    NumLock = keyNumLock
    ScrollLock = keyScrollLock
End Enum

Private zlKeyPressDelay As Long


'Purpose   :    Press a single key represented by a string
'Inputs    :    sKey                    The key to press.
'               [bHoldKeydown]          If True does not release the key press.
'               [bRelease]              If True releases a "HoldKeydown" key press (see above).
'Outputs   :    N/A


Public Sub SendKey(sKey As String, Optional bHoldKeydown As Boolean = False, Optional bRelease As Boolean = False)
    Dim lScan As Long, lExtended As Long, lVK As Long
    Dim bShift As Boolean, bCtrl As Boolean, bAlt As Boolean
    
    lVK = VkKeyScan(Asc(sKey))
    
    If lVK Then
        lScan = MapVirtualKey(lVK, 2)
        lExtended = 0
        If lScan = 0 Then
            lExtended = KEYEVENTF_EXTENDEDKEY
        End If
        lScan = MapVirtualKey(lVK, 0)
        
        bShift = (lVK And &H100)
        bCtrl = (lVK And &H200)
        bAlt = (lVK And &H400)
        
        lVK = (lVK And &HFF)
        
        If bRelease = False Then
            If bShift Then
                keybd_event eKeys.keyShift, 0, 0, 0
            End If
            If bCtrl Then
                keybd_event eKeys.keyControl, 0, 0, 0
            End If
            If bAlt Then
                keybd_event eKeys.keyAlt, 0, 0, 0
            End If
            keybd_event lVK, lScan, lExtended, 0
        End If
        
        If bHoldKeydown = False Then
            keybd_event lVK, lScan, KEYEVENTF_KEYUP Or lExtended, 0
        
            If bShift Then
                keybd_event eKeys.keyShift, 0, KEYEVENTF_KEYUP, 0
            End If
            If bCtrl Then
                keybd_event eKeys.keyControl, 0, KEYEVENTF_KEYUP, 0
            End If
            If bAlt Then
                keybd_event eKeys.keyAlt, 0, KEYEVENTF_KEYUP, 0
            End If
        End If
    End If
End Sub


'Purpose   :    Loops through a string and calls SendKey for each character
'Inputs    :    sString                 The string to press.
'               [bDoEvents]             If True returns control to the processor after every keypress.
'Outputs   :    N/A


Public Sub SendString(ByVal sString As String, Optional bDoEvents As Boolean = True)
    Dim sKey As String * 1, lKey As Long, lLen As Long
    
    lLen = Len(sString)
    For lKey = 1 To lLen
        sKey = Mid$(sString, lKey, 1)
        SendKey sKey
        Sleep zlKeyPressDelay
        If bDoEvents Then
            DoEvents
        End If
    Next

End Sub


'Purpose   :    Presses a virtual key (used for keys that don't have ascii equilivant)
'Inputs    :    ekeyPress               The virtual key to press
'               [bHoldKeydown]          If True does not release the key press.
'               [bRelease]              If True releases the key press.
'               [bCompatible]
'Outputs   :    N/A


Public Sub PressKeyVK(ekeyPress As eKeys, Optional bHoldKeydown As Boolean, Optional bRelease As Boolean, Optional bCompatible As Boolean)
    Dim lScan As Long
    Dim lExtended As Long
        
    lScan = MapVirtualKey(ekeyPress, 2)
    lExtended = 0
    If lScan = 0 Then
        lExtended = KEYEVENTF_EXTENDEDKEY
    End If
    lScan = MapVirtualKey(ekeyPress, 0)
    
    If bCompatible Then
        lExtended = 0
    End If
    
    If Not bRelease Then
        keybd_event ekeyPress, lScan, lExtended, 0
    End If
    
    If Not bHoldKeydown Then
        keybd_event ekeyPress, lScan, KEYEVENTF_KEYUP Or lExtended, 0
    End If

End Sub


'Purpose   :    Sets the status of the various Lock keys
'Inputs    :    LockKey                 The lock key to set the status of.
'Outputs   :    N/A


Public Sub SetLockStatus(LockKey As eLockKey, bOn As Boolean)
    Dim abKeys(0 To 256) As Byte
    abKeys(LockKey) = (bOn * -1)
    'Win 9x
    Call SetKeyboardState(abKeys(0))
    If GetKeyState(LockKey) <> IIf(bOn, 0, 1) Then    'GetKeyState returns 1 if OFF and 0 if ON
        'Win NT
        'Simulate Key Press
        keybd_event LockKey, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
        'Simulate Key Release
        keybd_event LockKey, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
    End If
End Sub

'Purpose   :    returns the status of the various Lock keys
'Inputs    :    LockKey                 The lock key to return the status of.
'Outputs   :    Returns True if the Lock status is on.


Public Function GetLockStatus(LockKey As eLockKey) As Boolean
    GetLockStatus = GetKeyState(LockKey)
End Function

'Determines the delay between subsequent keystrokes in the SendString routine
Property Get KeyPressDelay() As Long
    KeyPressDelay = zlKeyPressDelay
End Property

Property Let KeyPressDelay(Value As Long)
    zlKeyPressDelay = Value
End Property

Private Sub Class_Initialize()
    zlKeyPressDelay = 20 'Add a delay of 20 ms between pressing each key
End Sub

Public Sub PauseFor(intSeconds As Integer)
Dim dtEndTime As Date

dtEndTime = DateAdd("s", intSeconds, Now())
Do Until Now() >= dtEndTime
  DoEvents
Loop

End Sub

That should do it. When you call to print a PDF, this code holds down the SHIFT key and prints the PDF file. (Holding down the shift key stops Adobe Reader 8 from loading any plugins.)

The reason for this code is one of the plugins on my work machine was cause Adobe to crash while closing and would abort multiple document print jobs and I do not have the access to remove the offending plug in.

Whew,
Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top