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
KOCUBAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KOCUBAAuthor Commented:
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
0
planoczCommented:
HI KOCUBA,
Do you have the full ver of adobe acrobat? and which ver?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

KOCUBAAuthor Commented:
I have to free download of Acrobat Reader 6.0
0
planoczCommented:
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 
0
Richie_SimonettiIT OperationsCommented:
why don't you simply use shellexecute api?

Private Declare Function ShellExecute 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

sub PrintPDF(Filename as string)
shellexecute me.hwnd,"print",Filename ,vbnullstring,vbnullstring,vbhide
end sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KOCUBAAuthor Commented:
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.
0
KOCUBAAuthor Commented:
planocz,  Sorry.  I thought they wanted $$.  I will be giving this a try.
0
Richie_SimonettiIT OperationsCommented:
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.hProcess, 100&)
Do While ret <> 0
  If ret < 0 Then
      ShellAndWait = False
      Exit Function
  End If

  DoEvents

  ret = WaitForSingleObject(proc.hProcess, _
      100&)
Loop

'get the return code
ret = GetExitCodeProcess(proc.hProcess, _
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
0
Richie_SimonettiIT OperationsCommented:
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&
0
KOCUBAAuthor Commented:
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.
0
planoczCommented:
I have  the ver 5.0 that was free. I can email to you. it should work with 6.0
0
KOCUBAAuthor Commented:
dave.kocuba@matcotools.com
0
KOCUBAAuthor Commented:
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.
0
Richie_SimonettiIT OperationsCommented:
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"
0
KOCUBAAuthor Commented:
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?
0
Richie_SimonettiIT OperationsCommented:
are you saying that waitforsingleobject function is never reached?
0
KOCUBAAuthor Commented:
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.
0
Richie_SimonettiIT OperationsCommented:
I am studying/working on a different approach.
0
Richie_SimonettiIT OperationsCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.