Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to print PDF file from VFP directly?
Message
From
28/09/2004 17:47:06
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00904836
Message ID:
00946978
Views:
52
I missed the part about you wanting to kill the reader in your earlier message... Looks like you have a nice solution to me. I am not sure if it is possible to do this using the FFC class... probably, but I don't know how to request it.




>I came up with a way to handle this. It may not be elegant, but it works.
>
>
>=PrintPDF("x:\dssvfp\xfrx\test.pdf")
>
>FUNCTION PrintPDF
>   LPARAMETERS tcPDFFile
>   ** ToDo: Add Error Checking for Parameter
>
>   LOCAL lcWindowTitle, lnWindowTitleLen, lnVFPhWnd, lnStart, lnReaderHwnd
>
>   *== API Declarations
>   DECLARE INTEGER ShellExecute IN "Shell32.dll" ;
>       INTEGER hwnd, ;
>       STRING lpVerb, ;
>       STRING lpFile, ;
>       STRING lpParameters, ;
>       STRING lpDirectory, ;
>       LONG nShowCmd
>
>   DECLARE INTEGER GetForegroundWindow IN win32API
>   DECLARE INTEGER Sleep IN WIN32API INTEGER nMSecs   && 1000 ms = 1 sec
>
>   DECLARE SHORT   SetForegroundWindow IN USER32.DLL INTEGER hWnd
>   DECLARE INTEGER SetActiveWindow IN USER32 INTEGER hWnd
>   DECLARE INTEGER FindWindow IN Win32API STRING @lpClassName, STRING @lpWindowName
>   DECLARE INTEGER GetWindowText IN WIN32API INTEGER hwnd, STRING @lptstr, INTEGER cbmax
>   lcWindowTitle = SPACE(50)
>   lnWindowTitleLen = LEN(lcWindowTitle)
>
>
>   *== Get HWND of current VFP session
>   IF VERSION(5) >= 800   && VFP8 and later carry hWnd property
>      lnVFPhWnd = _vfp.hWnd
>   ELSE
>      lnVFPhWnd = GetForegroundWindow()
>   ENDIF
>
>
>   *== Print The PDF
>   = ShellExecute(0, "open", "acrord32.exe", " /p /h " + tcPDFFile, "", 0)
>
>
>   *== Wait For Acrobat TO Become Active
>   lnStart = DATETIME()
>   DO WHILE .t.
>      lnReaderHwnd = FindWindow(0, "Acrobat Reader")
>      IF lnReaderHwnd = 0
>         lnReaderHwnd = FindWindow(0, "Adobe Reader")
>      ENDIF
>
>      IF lnReaderHwnd # 0 OR DATETIME() - lnStart > 30   && 30 seconds max
>         EXIT
>      ENDIF
>
>      Sleep(100)
>   ENDDO
>
>   IF lnReaderHwnd = 0
>      ** Reader Did Not Start in 30 seconds.
>      ** Just Set Focus And Bail
>      SetForegroundWindow(lnVFPhWnd)
>      SetActiveWindow(lnVFPhWnd)
>      RETURN
>   ENDIF
>
>
>   *== Printing has begun when PDF name appears in title of Reader window
>   DO WHILE .t.
>      getwindowtext(lnReaderHwnd, @lcWindowTitle, lnWindowTitleLen)
>      IF UPPER(JUSTFNAME(tcPDFFile))  $ UPPER(lcWindowTitle)
>         EXIT
>      ENDIF
>   ENDDO
>
>   *== Printing has finished when PDF name no longer in title
>   DO WHILE .t.
>      lcWindowTitle = SPACE(50)
>      getwindowtext(lnReaderHwnd, @lcWindowTitle, lnWindowTitleLen)
>      IF ! UPPER(JUSTFNAME(tcPDFFile))  $ UPPER(lcWindowTitle)
>         EXIT
>      ENDIF
>   ENDDO
>
>
>   *== Kill Reader Process
>   IF SUBSTR(OS(1),9,1) >= "5"   && 4 = Win 98, 5= 2K & XP
>      LOCAL loWMI, loProcess
>      loWMI      = GetObject("winmgmts://./root/cimv2")
>      loProcesses   = loWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'AcroRd32.exe'")
>      For Each loProcess in loProcesses
>         loProcess.Terminate(0)
>      Next
>
>      loProcesses   = loWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Acrobat.exe'")
>      For Each loProcess in loProcesses
>         loProcess.Terminate(0)
>      Next
>   ENDIF
>
>   *== Set Focus to VFP
>   SetForegroundWindow(lnVFPhWnd)
>   SetActiveWindow(lnVFPhWnd)
>
>ENDFUNC
>
Thanks,

Stacy



Black Mountain Software, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform