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

Open PDF file

Status
Not open for further replies.

fox26apgmr

Programmer
Apr 30, 2002
21
0
0
US
Anyone know how to open a PDF file from a Foxprow program?
Thanks
 
In VFP, it would be reasonably simple if you just want to open it in Acrobat Reader (assuming it's installed). You'd
use:
Code:
declare INTEGER ShellExecute in shell32 INTEGER handle, STRING @ oper, ;
   STRING @ ifile, STRING @ iparam, STRING @ ipath, INTEGER showcmd

lcFileName = "c:\temp\document0.pdf"
=shellexecute(0,"open",lcFileName,"","c:\",1)
Since FPW can't directly call 32-bit DLL's you'll need to use CALL32. (This assumes you are running in a 32-bit OS and not Win 3.x.) The CALL32.ZIP file is on Rick Strahl's site at and includes the necessary files and some demo code.

Note: Back when I was using this, I found that while CALL32 works for many 32-bit API calls, others can fail and "hang" the program / workstation - use only when necessary and test on all potential OS platforms.

Rick
 
When you mean "open a PDF", do you mean Write to a PDF file or Read its contents into Foxpro?

If you mean to Write your report, etc. to a PDF, you might want to utilize a PDF "Printer" driver. There are a number of them available on the Web. In that way you need only select that "printer" and output your report.

If you mean to Read the PDF file contents into your Foxpro application you will have a much greater difficulty.

I guess that a 3rd possibility would be that you might want to merely display an existing PDF file from within your FP application. For that you would need to follow Rick's suggestion above.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Hi,
I am trying to open a pdf so that a user can read the content.
Does CALL32.DLL have to be copied to a specific folder? I am getting this error:
CALL32.DLL is an invalid library or path name
This is the instruction being executed:
lhcall32=regfn("Declare32","CCC","L","CALL32.DLL")
It's in PROC REG32
This is what my code looks like:
SET PROCEDURE TO CALL32
SET LIBRARY TO home()+"FOXTOOLS" ADDITIVE
CLEAR
lhcall32=reg32("SetFileAttributes","Kernel32.dll","pi")
lhsetattr=RegFP("CL","L")
=callfn(lhsetattr,"HANDBOOK.PDF",lhcall32)
Thanks, Joe
 
Joe,
First, it's easiest to keep the call32.dll in the directory where your code is run from. (Since it's a 16-bit .DLL, it can't be registered.) It would probably also work in the "windows" directory.

The code you list is not to display anything, but to set the file attribute of a file, and it's missing a parameter. It should probably read:
=callfn(lhsetattr,"HANDBOOK.PDF",file_readonly,lhcall32)
Where file_readonly is DEFINED as:
#DEFINE file_readonly 1

When you use RegFP("CL","L), you are saying that you'll be passing two parameters in - character and 'logical' (actually an INT), and expect a logical to be returned. The input parameters are always between the two required parameters in the callfn() function:
=callfn(lhsetattr, <n parameters,> lhcall32)

I think you need to understand more about API calls and look at the sample code for CALL32 a bit more.

Note: This seems to work for me.
Code:
*declare INTEGER ShellExecute in shell32 INTEGER handle, STRING @ oper, ;
   STRING @ ifile, STRING @ iparam, STRING @ ipath, INTEGER showcmd

*lcFileName = &quot;c:\temp\ca.pdf&quot;
*=shellexecute(0,&quot;open&quot;,lcFileName,&quot;&quot;,&quot;c:\&quot;,1)

SET PROCEDURE TO CALL32

SET LIBRARY TO home()+&quot;FOXTOOLS&quot; ADDITIVE

lhcall32=reg32(&quot;ShellExecute&quot;,&quot;shell32.dll&quot;,&quot;ippppi&quot;)

*** Set parameters and return type for the function
*** Return RegFn()/CallFn() function handle.
*** Note you always call Call32, using a different
*** parameter list each time, depending on the function
*** that is called.

lhShellEx=RegFP(&quot;LCCCCL&quot;,&quot;L&quot;)

lcFileName = &quot;c:\temp\CA.pdf&quot;
lnResult = callfn(lhShellEx,0,&quot;open&quot;,lcFileName,&quot;&quot;,&quot;c:\&quot;,1,lhcall32)
? lnResult
   
CLEAR ALL
SET LIBRARY TO
Rick
 
Hi Rick,
Thanks for the info and your patience. I do have the CALL32 (DLL and PRG) in the same folder as the prg I am executing. I still get the &quot;CALL32.DLL is an invalid library or path name&quot; so I fully qualified the CALL32.DLL in the CALL32.PRG.
lhcall32=regfn(&quot;Declare32&quot;,&quot;CCC&quot;,&quot;L&quot;,&quot;C:\FOXPROW\PROGRAMS\CALL32.DLL&quot;) and I seem to get past that error (lhcall32 has been set to 1) and now I get:
&quot;Dynamic library does not contain a function called Call32&quot;
executing this statement:
&quot;RETURN regfn(&quot;Call32&quot;,pcparms+&quot;L&quot;,pcrettype,&quot;C:\FOXPROW\PROGRAMS\CALL32.DLL&quot;)&quot;
Thanks again, Joe
 
Joe,
Because this is unsupported code, I can't make any guesses as to why you are having problems. (I've never changed ANY code in CALL32.PRG.) I've tried it on both Win98 SE and Win XP Pro and it seems to work just fine for me in FPW 2.6a - officially patched for a high speed CPU. What OS are you running?

Have you done a search on Call32.DLL on your system? Maybe you have something else (registered?) with this name.

Perhaps you just need to upgrade to VFP 8.0 - I know the commented out DECLARE and call on ShellExecute() work just fine there.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top