Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending PDF file directly to printer
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00940669
Message ID:
01004808
Views:
629
>Nadya,
>
>Yes, if you know any other application that could print pdf files without acrobat. Any ideas?

In Russian FoxClub forum somebody (piva?) sent me a long time ago PDFFactory. But I believe it's for sending reports to PDF, not for printing PDF.

No, I think I don't know other application of the top of my head. But sounds like a nice idea. So far I'm using this code, I found here:
*  Program...........: PRINTPDF.PRG
*  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....: tcFileName
*  Major change list.:
lparameters tcPDF
if vartype(m.tcPDF)<>"C" or adir(laFile,m.tcPDF) = 0
	tcPDF = getfile("PDF","Select PDF file to print...")
endif
local llReturn
llReturn = .f.
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 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 " + tcPDF, "", 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(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(tcPDF))  $ 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)
   llReturn = .t.	
endif
return m.llReturn
>
>
>>Yuri,
>>
>>Do you think it would be possible without opening Adobe?
>>
>>>Carlos,
>>>
>>>See my notes below
>>>
>>>>DECLARE INTEGER ShellExecute ;
>>>>IN SHELL32.DLL ;
>>>>INTEGER nWinHandle,;
>>>>STRING cOperation,;
>>>>STRING cFileName,;
>>>>STRING cParameters,;
>>>>STRING cDirectory,;
>>>>INTEGER nShowWindow
>>>>? ShellExecute(0,"print", FullPath('MyFile.pdf'),"",0)
>>>
>>>One parameter is missing. Should be:
>>>? ShellExecute(0,"print", FullPath('MyFile.pdf'),"","",0)
>>>
>>>>
>>>>---------------------------------------------------------
>>>>I just read this thread
>>>>
>>>>I have some questions
>>>>
>>>>1.I changed the parameter order because it did’t work
>>>>
>>>>? ShellExecute(0,"print", “MyFile.pdf”,'',”Path”,0)
>>>>
>>>>2. It opens the Adobe Reader and don’t close it
>>>>What I can I do?
>>>
>>>Something like this:
>>>
>>>IF ShellExecute(0,"print", FullPath('MyFile.pdf'),"","",1)>32
>>>
>>>	oShell = CreateObject("WScript.Shell")
>>>	*wait for Acrobat reader
>>>	lntimeout=60
>>>	lnstarttime=SECONDS()
>>>	DO WHILE not oShell.AppActivate("Acrobat Reader") AND ;
>>>		    SECONDS()-lnstarttime<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()-lnstarttime<lntimeout
>>>		    oShell.SendKeys("^q")   && try to close Acrobat reader
>>>		    INKEY(2)
>>>		enddo
>>>	endif
>>>
>>>	oShell=.null.
>>>ELSE
>>>	?"file not found "
>>>ENDIF
>>>
>>>
>>>
>>>>
>>>>3 How can I change printer
>>>
>>>One of the ways is:
>>>oWSHNet = CREATEOBJECT('Wscript.Network')
>>>oWSHNet.SetDefaultPrinter('Windows_Printer_Name')
>>>oWSHNet =null
>>>
>>>>
>>>>TIA
>>>
>>>Good Luck
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform