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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acrobat Reader and ShellExecute

Status
Not open for further replies.

Nro

Programmer
May 15, 2001
337
0
16
CA
Hi. I have problem printing PDF or even opening Acrobat reader files from VFP. On Abode site I found in the SDK documentation, some acrobat call parameters;

AcroRd32.exe /p pathname — Start Adobe Reader and display the Print dialog box.
AcroRd32.exe /t path "printername" "drivername" "portname" — Start Adobe Reader and print a file while suppressing the Print dialog box. The path must be fully specified.

These commands worked fine when I run it in Windows (Vista enterprise). But if I do a run in fox, nothing append. So I decide to use ShellExecute. Here some code;

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ;
 INTEGER hndWin, ;
 STRING cAction, ;
 STRING cFileName, ;
 STRING cParams, ;
 STRING cDir, ;
 INTEGER nShowWin

tcPdfFile = "P:\Objitech\Apps\Mis\Web\PDF\A_FR_COFA_8123_M5L01RFC.PDF"
IF FILE(tcPdfFile) THEN 
   ?  ShellExecute(0, "AcroRd32.exe", tcPdfFile, "", "", 0)
ENDIF

CLEAR DLLS ShellExecute

The program return 31 and MSDN said;

The ShellExecute() function returns the value 31 if there is no association for the specified file type or if there is no association for the specified action within the file type
Any suggestions?
I’ve tried it with XP and end up with the same message.
Thanks in advance.
Nro
 
I haven't had need to open Acrobat Reader from VFP so I cannot comment on that, although I am sure others here have done so.

But as to "I have problem printing PDF"...
Many of us have accomplished this quite successfully without using Adobe.

We have used PDF Print drivers and merely 'printed' the document to that 'printer'. There are a variety of PDF Print drivers to be found on the web. Some are even free downloads.

My personal experience has been best with products which could be pre-configured via the Windows Printer Properties to 'print' to one fixed destination and one fixed output file name.

I had VFP output its report through that 'printer' and then followed up by moving the known file from its known location to where it was needed and, if necessary, renaming it along the way.

Good Luck,
JRB-Bldr
 
I think what NRO is trying to do is print an existing .PDF file. I have done this for a client that needed a combination of VFP generated form letters and a corporate form printed with each new contract. The VFP letters contain customer specific information while the corporate form is maintained by their legal department and is used corporate wide. When this form is updated, they simple drop the new version of the .PDF into the same location and are ready to go.

As for the problem using the ShellExecute, this is the code that I used in Windows - XP:

* Call Windows to print file
DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

cFileName = g_currdir+"\q6505100.pdf"
cAction = "print"
ShellExecute(0,cAction,cFileName,"","",0)

I think your problem is in the cAction value. I hope that I have correctly interpreted your question and that this helps.

Kindest Regards,
BongoB1
 
Nro,

Your syntax is slightly wrong. You should be passing the action verb as the second param, and the document name as the third. Thus:

Code:
ShellExecute(0, "print", tcPdfFile, "", "", 0)

Give it a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks for all your replies. I’m sorry if my post was not very clear. BongoB1 is correct. I don’t want to “convert” VFP report into PDF, but to manage PDF documents. Now, my main target is to print these PDF to different printers. I’ve read some Mike’s post about changing the default printer with

Code:
DECLARE INTEGER SetDefaultPrinter IN winspool.drv STRING lcPrinter
tcPdfFile = "P:\Objitech\Apps\Mis\Web\PDF\A_FR_COFA_8123_M5L01RFC.PDF"
loFrmView = NEWOBJECT("_frmpdfviewer", COU_CLSSTHCRYSCLASS, "", tcPdfFile)
loFrmView.AddObject("olePDF","olePDFControl2")
loFrmView.olePDF.Loadfile(tcPdfFile])

DECLARE INTEGER SetDefaultPrinter IN winspool.drv STRING lcPrinter
SetDefaultPrinter("\\PIII933\Canon iP1800 series")
loFrmView.olePDF.PrintAll()

but it worked erratically on some of my stations. It also open Acrobat reader, so I have to code to close it (verify first if it was not already opened), and so on ...
The solution Adobe proposes is to run Acrobat Reader, pass the PDF name, printer name, driver name and port name. It is also possible to start a separate instance of Acrobat, even if one is currently open, and start it in a minimized window. All in one line of code. It’s just what I want to do, but if I try this code ;
Code:
RUN "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe" /t P:\Objitech\Apps\Mis\Web\PDF\A_FR_COFA_8123_M5L01RFC.PDF 'Canon iP1800 series on PIII933' 'Canon iP1800 series' 'USB001'

Nothing append, except that I have one DOS box flashing with a message too fast to read. I found foxrun.pif and uncheck “Close on exit” and nothing change. It’s why I don't want to use Run.

I’m stuck.

Thanks

Nro
 
RUN executes DOS programs (hence the DOS window you see).

Try RUN /N instead.
 
Nro,

I really think the ShellExecute() method is better. It's simple and reliable, and it respects the user's choice of PDF reader (in case the user has installed a third-party reader).

I've used this approach in my own apps, without any problems.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi all. I finally figure how to work with ShellExecute (instead or RUN, sorry, bad habits) and I can invoke Acrobat, open the PDF file and invoke the print window;
Code:
DECLARE INTEGER ShellExecute IN shell32.dll ;
 INTEGER hndWin, ;
 STRING cAction, ;
 STRING cFileName, ;
 STRING cParams, ;
 STRING cDir, ;
 INTEGER nShowWin

tcPdfFile = "PDF\A_FR_COFA_8123_M5L01RFC.PDF"
 IF NOT EMPTY(tcPdfFile) AND FILE(tcPdfFile) THEN 
 lcParam = " /p /s " + tcPdfFile
 lnErrCode = ShellExecute(0, "open", "AcroRd32.exe", lcParam, "", 0)
ENDIF

The /p invoke print window and /s remove Splash screen.
The Acrobat documentation mentions that it is possible to print a PDF, without the acrobat Print dialog, directly on one specified printer;

AcroRd32.exe /t path "printername" "drivername" "portname"

So ...

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ;
 INTEGER hndWin, ;
 STRING cAction, ;
 STRING cFileName, ;
 STRING cParams, ;
 STRING cDir, ;
 INTEGER nShowWin

tcPdfFile = "PDF\A_FR_COFA_8123_M5L01RFC.PDF"
lcParam = " /t " + tcPdfFile

lcParam = lcParam + ' "\\PIII933\Canon iP1800 series"'
lcParam = lcParam + ' "Canon iP1800 series"'
lcParam = lcParam + ' "USB001"'

IF FILE(tcPdfFile) THEN 
 lnErrCode = ShellExecute(0, "open", "AcroRd32.exe", lcParam, "", 0)
 WAIT WINDOW "Wait ... " TIMEOUT 5
ENDIF

CLEAR DLLS ShellExecute

I’ve tried this code, and it worked very well. It prints the PDF on the specified printer. It’s what I want to do from the beginning. The only thing left is to close the Acrobat window, and I’m still searching for an answer. Thanks.

Nro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top