KOCUBA
asked on
Using the Adobe ocx to print
I have an application that is going to download multiple pdf files. I am attempting to use the pdf.ocx to print these files after they are downloaded. Basically:
pdf1.LoadFile strDestFile
pdf1.PrintAll
But this does not seem to send anything to the printer. Any ideas why?
The only way I can get anything to print is with the PrintwithDialog, which is not what I want to do.
Has anyone had any luck with this ocx or wiht printing pdf files any other way?
Thanks in advance
Dave
pdf1.LoadFile strDestFile
pdf1.PrintAll
But this does not seem to send anything to the printer. Any ideas why?
The only way I can get anything to print is with the PrintwithDialog, which is not what I want to do.
Has anyone had any luck with this ocx or wiht printing pdf files any other way?
Thanks in advance
Dave
ASKER
Dang123,
This opens up a Adobe window. I'm not looking to do that. I'm trying to get this to work with out the Shell command.
Thanks
This opens up a Adobe window. I'm not looking to do that. I'm trying to get this to work with out the Shell command.
Thanks
HI KOCUBA,
Do you have the full ver of adobe acrobat? and which ver?
Do you have the full ver of adobe acrobat? and which ver?
ASKER
I have to free download of Acrobat Reader 6.0
HI KOCUBA,
Here is the Acrobat link for the SDK kit (free).
It has the info for printing and the .dlls for FDF files in using
file transferring and making all kinds of PDF file, etc.
http://partners.adobe.com/asn/developer/acrosdk/acrobat.html
Here is the Acrobat link for the SDK kit (free).
It has the info for printing and the .dlls for FDF files in using
file transferring and making all kinds of PDF file, etc.
http://partners.adobe.com/asn/developer/acrosdk/acrobat.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
planocz, The SDK is not free. Even though it does not show it as locked, when you clic kon it it wants you to be a 'paying' member now.
Richie_Simonetti, For two reason 1) Possible issues with the spooler. and B)This opens a Arocbat Window that I do not want opened.
Richie_Simonetti, For two reason 1) Possible issues with the spooler. and B)This opens a Arocbat Window that I do not want opened.
ASKER
planocz, Sorry. I thought they wanted $$. I will be giving this a try.
1) Instead of shellexecute use:
shellandwait:
THE CODE THE FUNCTION AND A SAMPLE TO USE THE FUNCTION
Option Explicit
'Private Const SW_HIDE = 0
'Private Const SW_SHOWNORMAL = 1
'Private Const SW_NORMAL = 1
'Private Const SW_SHOWMINIMIZED = 2
'Private Const SW_SHOWMAXIMIZED = 3
'Private Const SW_MAXIMIZE = 3
'Private Const SW_SHOWNOACTIVATE = 4
'Private Const SW_SHOW = 5
'Private Const SW_MINIMIZE = 6
'Private Const SW_SHOWMINNOACTIVE = 7
'Private Const SW_SHOWNA = 8
'Private Const SW_RESTORE = 9
'Private Const SW_SHOWDEFAULT = 10
'Private Const SW_MAX = 10
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
'_________________________ __________ __________ __________ __________ _____
Public Function ShellAndWait(ByVal strPath As String, _
ByVal iWindowStyle As Integer, ByRef lreturnCode As Long, _
Optional sWinTitle As String = "", _
Optional sDirectoryPath As String = "") _
As Boolean
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
On Error GoTo ShellAndWaiterr
' Initialize the STARTUPINFO structure:
start.cb = Len(start) ' you must set the size
start.dwFlags = &H1& ' STARTF_USESHOWWINDOW Use Show Window
start.wShowWindow = iWindowStyle
If Not IsMissing(sWinTitle) Then
' if there is a title set the window title
start.lpTitle = sWinTitle
End If
' Start the shelled application:
ret = CreateProcessA(0&, strPath, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, _
sDirectoryPath, start, _
proc)
' Wait for the shelled application to finish:
ret = WaitForSingleObject(proc.h Process, 100&)
Do While ret <> 0
If ret < 0 Then
ShellAndWait = False
Exit Function
End If
DoEvents
ret = WaitForSingleObject(proc.h Process, _
100&)
Loop
'get the return code
ret = GetExitCodeProcess(proc.hP rocess, _
lreturnCode)
'close the process handles
ret = CloseHandle(proc.hProcess)
ShellAndWait = True
Exit Function
ShellAndWaiterr:
ShellAndWait = False
Exit Function
Resume
End Function
'_________________________ __________ __________ __________ __________ _____
Sub main()
Dim lRet As Long
Dim bRet As Boolean
bRet = ShellAndWait("notepad.exe" , 1, lRet, _
"", "c:\windows")
End Sub
shellandwait:
THE CODE THE FUNCTION AND A SAMPLE TO USE THE FUNCTION
Option Explicit
'Private Const SW_HIDE = 0
'Private Const SW_SHOWNORMAL = 1
'Private Const SW_NORMAL = 1
'Private Const SW_SHOWMINIMIZED = 2
'Private Const SW_SHOWMAXIMIZED = 3
'Private Const SW_MAXIMIZE = 3
'Private Const SW_SHOWNOACTIVATE = 4
'Private Const SW_SHOW = 5
'Private Const SW_MINIMIZE = 6
'Private Const SW_SHOWMINNOACTIVE = 7
'Private Const SW_SHOWNA = 8
'Private Const SW_RESTORE = 9
'Private Const SW_SHOWDEFAULT = 10
'Private Const SW_MAX = 10
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
'_________________________
Public Function ShellAndWait(ByVal strPath As String, _
ByVal iWindowStyle As Integer, ByRef lreturnCode As Long, _
Optional sWinTitle As String = "", _
Optional sDirectoryPath As String = "") _
As Boolean
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
On Error GoTo ShellAndWaiterr
' Initialize the STARTUPINFO structure:
start.cb = Len(start) ' you must set the size
start.dwFlags = &H1& ' STARTF_USESHOWWINDOW Use Show Window
start.wShowWindow = iWindowStyle
If Not IsMissing(sWinTitle) Then
' if there is a title set the window title
start.lpTitle = sWinTitle
End If
' Start the shelled application:
ret = CreateProcessA(0&, strPath, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, _
sDirectoryPath, start, _
proc)
' Wait for the shelled application to finish:
ret = WaitForSingleObject(proc.h
Do While ret <> 0
If ret < 0 Then
ShellAndWait = False
Exit Function
End If
DoEvents
ret = WaitForSingleObject(proc.h
100&)
Loop
'get the return code
ret = GetExitCodeProcess(proc.hP
lreturnCode)
'close the process handles
ret = CloseHandle(proc.hProcess)
ShellAndWait = True
Exit Function
ShellAndWaiterr:
ShellAndWait = False
Exit Function
Resume
End Function
'_________________________
Sub main()
Dim lRet As Long
Dim bRet As Boolean
bRet = ShellAndWait("notepad.exe"
"", "c:\windows")
End Sub
2) to hide and close:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const WM_CLOSE = &H10
'Usage:
dim l as long
l=findwindow(vbnullstring, "Acrobat Reader - " & filename)
showwindow l,sw_hide
after shellandwait finishes:
postmessage l,wm_close,0&,0&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const WM_CLOSE = &H10
'Usage:
dim l as long
l=findwindow(vbnullstring,
showwindow l,sw_hide
after shellandwait finishes:
postmessage l,wm_close,0&,0&
ASKER
planocz, All I have acces to with out $$ is the header files. To get what you are mentioning I need to pay a member ship.
I have the ver 5.0 that was free. I can email to you. it should work with 6.0
ASKER
dave.kocuba@matcotools.com
ASKER
Richie_Simonetti, That will open the reader with the document just fine, But it won't automatically print. Least I can't get it to print.
you are right. I found some interesting thing:
printing pdf files from command line, so you could simply call Shell function or use shellandwait with the correct command line:
I don't know if you could access the site so i post a copy of the article below.
Issue
How can we print PDF files through the command line without displaying the print dialog?
Solution
As documented in the Acrobat Developer FAQ, you can use the /t command line to print silently. Please note that there is slightly different behavior between 4.05 and 5.05.
In Acrobat 4.0.5, /t launches Acrobat Reader in a hidden context and also supresses the Print Dialog box.
In Acrobat 5.0.5, /t launches Acrobat Reader in a minimized context in the taskbar and suppresses the Print Dialog box.
The following command line prints test.pdf on a network printer
AcroRd32.exe /t "C:\test.pdf" "\\servername\printername" "AdobePS Tektronix Phaser 840" "123.45.678.910"
The following command line without drivername and portname works, too.
AcroRd32.exe /t "C:\test.pdf" "\\servername\printername"
printing pdf files from command line, so you could simply call Shell function or use shellandwait with the correct command line:
I don't know if you could access the site so i post a copy of the article below.
Issue
How can we print PDF files through the command line without displaying the print dialog?
Solution
As documented in the Acrobat Developer FAQ, you can use the /t command line to print silently. Please note that there is slightly different behavior between 4.05 and 5.05.
In Acrobat 4.0.5, /t launches Acrobat Reader in a hidden context and also supresses the Print Dialog box.
In Acrobat 5.0.5, /t launches Acrobat Reader in a minimized context in the taskbar and suppresses the Print Dialog box.
The following command line prints test.pdf on a network printer
AcroRd32.exe /t "C:\test.pdf" "\\servername\printername"
The following command line without drivername and portname works, too.
AcroRd32.exe /t "C:\test.pdf" "\\servername\printername"
ASKER
Richie_Simonetti,
OK I get it to print, But since it doesn't close once it is done. I just sit there in ShellandWait. Where am I suppose to put that post message command?
OK I get it to print, But since it doesn't close once it is done. I just sit there in ShellandWait. Where am I suppose to put that post message command?
are you saying that waitforsingleobject function is never reached?
ASKER
It's reached. but it stays in that loop until I manually close Adobe. I assume I am doing something wrong.
I have the FindWindow, ShowWindow and PostMEssage commands after the ShellAndWait call.
I have the FindWindow, ShowWindow and PostMEssage commands after the ShellAndWait call.
I am studying/working on a different approach.
Since i haven't vb installed i had to do it in excel, check it out:
http://www.angelfire.com/realm/vb-shared/pdf_print.xls
http://www.angelfire.com/realm/vb-shared/pdf_print.xls
http://oldlook.experts-exchange.com/questions/20706656/Print-a-PDF.html
Dang123