Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any way to speed this up?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01122411
Message ID:
01122427
Vues:
25
It takes 17 seconds on my system to print PDF. The Adobe window shows up for some period of time.

Yuri's code didn't work at all. I closed Adobe window myself, then it showed 67 seconds.

Here are two versions I've tried:
***********************************************************************************************
*  Program...........: PRINTPDF
*  Author............: Yuri Rubinov
*  Project...........: Visual Collections
*  Created...........: 04/14/2005  12:55:23
*  Copyright.........: (c) Jzanus LTD, 2005
*) Description.......: This function prints PDF passed as parameter and kills Adobe afterwards
*  Calling Samples...:
*  Parameter List....: tcPDF
*  Major change list.:
function PrintPDF
lparameters tcPDF
wait window "System Printing PDF File......" nowait
if vartype(m.tcPDF)<>"C" or adir(laFile, m.tcPDF) = 0
	tcPDF = getfile("PDF","Select PDF file to print...")
endif
ltStartTime = datetime()
declare integer ShellExecute in "Shell32.dll" ;
		integer hwnd, ;
		string lpVerb, ;
		string lpFile, ;
		string lpParameters, ;
		string lpDirectory, ;
		long nShowCmd

if ShellExecute(0,"print", m.tcPDF,"","",1)>32

	oShell = createobject("WScript.Shell")

*wait for Acrobat reader
	local lnTimeOut, lnStartTime
	lnTimeOut=60
	lnStartTime=seconds()
	do while not oShell.AppActivate("Acrobat Reader") and ;
			seconds()-m.lnStartTime < m.lnTimeOut
		inkey(2)
	enddo

	if oShell.AppActivate("Acrobat Reader")
*While printing Acrobat reader cannot be closed; so repeat
*                attempts to close it.
		lnStartTime=seconds()
		do while oShell.AppActivate("Acrobat Reader") and ;
				seconds()- m.lnStartTime < m.lnTimeOut
			oShell.SendKeys("^q")   && try to close Acrobat reader
			inkey(2)
		enddo
	endif

	oShell=.null.
else
*?"file not found "
* Some problems occurred, we may find out with GetLastError
endif

=messagebox(datetime() - m.ltStartTime)

return
***********************************************************************************************
*  Program...........: PRINTPDF1
*  Author............: John St. Andria thread #033100
*  Project...........: Visual Collections
*  Created...........: 04/14/2005  12:55:23
*  Copyright.........: (c) Jzanus LTD, 2005
*) Description.......: This function prints PDF passed as parameter and kills Adobe afterwards
*  Calling Samples...:
*  Parameter List....: tcPDF
*  Major change list.:
function PRINTPDF1
lparameters tcPDF

wait window "System Printing PDF File......" nowait
if vartype(m.tcPDF)<>"C" or adir(laFile, m.tcPDF) = 0
	tcPDF = getfile("PDF","Select PDF file to print...")
endif
local llReturn
ltStartTime = datetime()
llReturn = .t.

if not empty(m.tcPDF)
	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 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(m.lcWindowTitle)

*== Get HWND of current VFP session
	if version(5) >= 800   && VFP8 and later carry hWnd property
		lnVFPhWnd = _vfp.hwnd
	else
		declare integer GetForegroundWindow in win32API
		lnVFPhWnd = GetForegroundWindow()
	endif

*== Print The PDF
	= ShellExecute(0, "open", "acrord32.exe", " /p /h " + m.tcPDF, "", 0)

*== Wait For Acrobat to Become Active
	lnStart = datetime()
	do while .t.
		lnReaderHwnd = FindWindow(0, "Acrobat Reader")
		if m.lnReaderHwnd = 0
			lnReaderHwnd = FindWindow(0, "Adobe Reader")
		endif
		if m.lnReaderHwnd # 0 or datetime() - m.lnStart > 30   && 30 seconds max
			exit
		endif
		MMSleep(100) && 1000 ms = 1 sec
	enddo

	if m.lnReaderHwnd = 0
** Reader Did Not Start in 30 seconds.
** Just Set Focus And Bail
		SetForegroundWindow(m.lnVFPhWnd)
		SetActiveWindow(m.lnVFPhWnd)
		return .f.
	endif

*== Printing has begun when PDF name appears in title of Reader window
	do while .t.
		GetWindowText(lnReaderHwnd, @lcWindowTitle, lnWindowTitleLen)
		if upper(justfname(tcPDF))  $ 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(m.tcPDF))  $ upper(m.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(m.lnVFPhWnd)
	SetActiveWindow(m.lnVFPhWnd)
	llReturn = .t.
endif

=messagebox(datetime() - m.ltStartTime)

return m.llReturn
What are your results with them?

Thanks.

>Naomi,
>
>Apparently I have always the task of reminding you to use the coverage profiler <g>
>
>Anyways, is it always slow or just the first time? The reason I ask is that the first time you run it, the WMI Service needs to start and that is time consuming
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform