Solved

Using the Adobe ocx to print

Posted on 2003-11-17
20
1,120 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:KOCUBA
  • 9
  • 7
  • 3
  • +1
20 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9765106
0
 

Author Comment

by:KOCUBA
ID: 9765618
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
 
LVL 27

Expert Comment

by:planocz
ID: 9765670
HI KOCUBA,
Do you have the full ver of adobe acrobat? and which ver?
0
 

Author Comment

by:KOCUBA
ID: 9765685
I have to free download of Acrobat Reader 6.0
0
 
LVL 27

Expert Comment

by:planocz
ID: 9765797
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
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 150 total points
ID: 9766016
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
 

Author Comment

by:KOCUBA
ID: 9766074
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
 

Author Comment

by:KOCUBA
ID: 9766104
planocz,  Sorry.  I thought they wanted $$.  I will be giving this a try.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9766117
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9766135
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:KOCUBA
ID: 9766172
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
 
LVL 27

Expert Comment

by:planocz
ID: 9766837
I have  the ver 5.0 that was free. I can email to you. it should work with 6.0
0
 

Author Comment

by:KOCUBA
ID: 9766851
dave.kocuba@matcotools.com
0
 

Author Comment

by:KOCUBA
ID: 9771935
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9779804
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
 

Author Comment

by:KOCUBA
ID: 9780745
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9780785
are you saying that waitforsingleobject function is never reached?
0
 

Author Comment

by:KOCUBA
ID: 9780810
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9786866
I am studying/working on a different approach.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9789513
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now