troubleshooting Question

Problem printing .pdf from Foxpro

Avatar of Howard Katz
Howard KatzFlag for United States of America asked on
FoxProWeb Components
6 Comments1 Solution994 ViewsLast Modified:
Hello Experts,
I need to simply print a .pdf file on a user-selected printer from a VFP9 app. The user doesnt want to view the file, and it gets erased after its printed.  Here is the code I wrote.  It works when I step through the debugger, but otherwise it doesnt.  Even putting in delays doesnt help.  Without the debugger the printer queue says Spooling after the PrintAll() call for the entire time of the Sleep() delay.  Then it briefly flashes Printing, and then the document is deleted from the queue.  It only prints part of the first page and stops.  Also, the program hangs.    In the debugger everything works OK.  

Here is the code:

PROCEDURE PrintPDF
LPARAMETERS tcFileName, tcPrinter
LOCAL loform1, lcOldPrinter

DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
     STRING pszPrinter
DECLARE Sleep IN Win32API INTEGER nMilliseconds

** If no file, get out
IF !FILE(tcFileName)
      RETURN
ENDIF
WAIT WINDOW 'printing' NOWAIT
lcOldPrinter = SET("PRINTER",2)

** Set the default windows printer
SetDefaultPrinter(tcPrinter)
 
loform1=Newobject("form")
WAIT WINDOW 'adding AcroPDF object ...' nowait
loform1.AddObject("olecontrol2","AcroPDF1")
*=Sleep(3000)
WAIT WINDOW 'loading file ...' nowait
loform1.olecontrol2.loadfile(tcFileName)
=Sleep(3000)
WAIT WINDOW 'printing ...' nowait
loform1.olecontrol2.printall()
=Sleep(20000)

loform1.RemoveObject("olecontrol2")
loform1.Release()
ERASE (tcFileName)

** Now reset the printer
SetDefaultPrinter(lcOldPrinter)

RETURN

Define Class AcroPDF1 As OleControl
    OleClass = "AcroPDF.PDF.1"
    Height = 0
    Width = 0
ENDDEFINE
ASKER CERTIFIED SOLUTION
CarlWarner

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros