Leemi
Tue May 10 16:28:34 CDT 2005
Hi AP:
1. Get the PDF995 driver form
http://site4.pdf995.com/download.html.
2. Make sure Windows Scripting Host is installed
3. Run code below.
Note: The PDF995 driver displays a web site advertisement when you complete
printing. You can turn this off by buying a key from the maker of PDF995.
*-----------------------------------
*
* CREATED: 02/19/2004
*
* ABSTRACT: Demo showing how to print a Fox report to a PDF
* via the PDF995 driver
* (
http://site4.pdf995.com/download.html).
* You need to download and install the Pdf995 Printer Driver and the
* "Free Converter" from the site above in order to run this code.
* Once that is done, save this to a .PRG and run it. It will create
* it's own table, report, etc. for demo purposes.
*
* When finished, you will get a messagebox saying "COMPLETE!" and
* there will be a file named "MYPDF.PDF" in the same DIR as this .PRG.
*-----------------------------------
DECLARE INTEGER Sleep IN Win32API INTEGER
DECLARE INTEGER FindWindow IN WIN32API STRING, STRING
DECLARE SetWindowPos IN WIN32API ;
LONG HWND, ;
LONG hwndafter, ;
LONG x, ;
LONG Y, ;
LONG cx, ;
LONG cy, ;
LONG flags
CLOSE DATA ALL
LOCAL i AS INTEGER, ;
lcThisDir AS STRING, ;
lcPDFFileName AS STRING
i = 0
lcThisDir = ADDBS(JUSTPATH(SYS(16)))
lcPDFFileName = lcThisDir + [MYPDF.PDF]
CD (lcThisDir)
ERASE *.PDF
*-- Create a temp table to report off of.
CREATE CURSOR TEST (cID c(10), FNAME c(30), LNAME c(30))
FOR i = 1 TO 10
INSERT INTO TEST VALUES ;
(SYS(2015), [F] + TRANS(i), [L] + TRANS(i))
ENDFOR
*-- Create a dummy report
CREATE REPORT MyReport FROM TEST
*-- Run the report after setting the printer to
*-- PDF driver.
SET PRINTER TO NAME PDF995
REPORT FORM MyReport TO PRINTER NOCONSOLE
*-- Call the help procedure that
*-- processes the saving via the PDF995 dialog.
SetPDF_FileName(lcPDFFileName)
*-- Clean up and bail
CLOSE DATA ALL
ERASE MyReport.*
CLEAR DLLS
RELEASE ALL
MESSAGEBOX([Complete!])
*~~~~~~~~~~~
FUNCTION SetPDF_FileName(lpFileName AS STRING)
#DEFINE HWND_TOPMOST -1
#DEFINE SWP_HIDEWINDOW 80
LOCAL lnPDFWinHand AS LONG, ;
loWSH AS wscript.SHELL
lnPDFWinHand = 0
*-- Create an instance of the wscript.shell
*-- object. We use this to fill in the file name
*-- on the PDF995 "Save As" dialog via the SendKeys()
*-- method of the object. Poor-mans automation. <g>
loWSH = NEWO([wscript.shell])
*-- Get a handle to the PDF995 "Save As" dialog
DO WHILE lnPDFWinHand = 0
lnPDFWinHand = FindWindow(0, [PdF995 Save As])
DOEVENTS
ENDDO
*-- Once we have a handle, move it off screen
*-- and hide it ASAP via the SetWindowPos API.
*-- Not necessary, but looks cleaner. You DO need to set
*-- that dialog to the foreground window. That's taken
*-- care of by passing the hwnd_topmost param to
*-- SetWindowPos.
*-- NOTE: You need error trapping here to prevent this next call
*-- if we DIDN'T get a handle to the "Save As" dialog
*-- for some reason.
SetWindowPos(lnPDFWinHand, HWND_TOPMOST, ;
-500, -500, 0, 0, SWP_HIDEWINDOW)
*-- The textbox on the "Save As" dialog that accepts the
*-- file name has focus when this dialog opens, so we just
*-- fill it with the file name via SendKeys().
loWSH.SendKeys(lpFileName)
*-- Sleep for 1/2 a second to make sure it went in fine.
Sleep(500)
*-- Click the "Save" button on the "Save As" dialog
*-- via SendKeys()
loWSH.SendKeys([%s])
*-- Release our scripting object and bail
RELEASE loWSH
RETURN
I hope this helps.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell
*-- VFP9 HAS ARRIVED!! --*
Read about all the new features of VFP9 here:
http://msdn.microsoft.com/vfoxpro/
*--Purchase VFP 9.0 here:
http://www.microsoft.com/PRODUCTS/info/product.aspx?view=22&pcid=54787e64-52
69-4500-8bf2-3f06689f4ab3&type=ovr
Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retired Sept. 30th, 2003
> os: windows xp pro sp2
> vfp: 6 sp5
>
> hi,
>
> how is the best and fast way to do PDF reports and free? :D
>
> TIA,
>
> AP