Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to print PDF file from VFP directly?
Message
De
28/09/2004 16:51:35
 
 
À
28/09/2004 16:39:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00904836
Message ID:
00946934
Vues:
61
Very cool. You'll have to store the actual title just in case so you can reference the window though because in my case, all of the pdf forms we create and print programmatically have a custom window title in Adobe Reader that is different than the form name...


>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
>
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform