Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate creating a PDF file 2

Status
Not open for further replies.

grads

Programmer
Feb 2, 2001
11
0
0
US
I have the following code to create a PDF file from a frx.

SET PRINTER TO NAME 'Acrobat PDFWriter'
lcDefaultDir = SYS(5) + SYS(2003)
SET DEFAULT TO SYS(2003)
REPORT FORM nameofreport.frx TO PRINTER NOCONSOLE
SET DEFAULT TO (lcDefaultDir)
SET PRINTER TO DEFAULT

My question is how do I avoid the "Save PDF File as" prompt window to appear. In addition, the pdf file defaults to what my report name is. Is there a way to name the file whatever I want.

Thanks
 
The method is to create a registry entry containing the filename of the PDF file to create. It uses REGISTRY.PRG, which, depending on your version, should be in the SAMPLES\CLASSES subdirectory of VFP.

Here's the two-function library I created to deal with this: (Note: I'm sure I picked up most of the code from somewhere else, possibly from one of Rick Strahl's articles on the subject).
Code:
**********************************************************************
*
*  PDFLIB.PRG - PDF Printer functions 
*
*
#define REGFILE "K:\VFP\Lib\registry.prg"              && Registry functions

*====================================================================
FUNCTION  InitPDFName(cRegKeyVal, aPrts)    && Initialize Adobe PDF filename
* Parameters:   (required) cRegKeyVal - Filename to post to registry
*                               (optional) aPrts - Array of installed printers
* Note:                 Uses REGISTRY.PRG
* Returns:      nResult         - Numeric error# from SetRegKey() - 0=Success
*====================================================================
local n

* See if PDFWRiter is a defined printer; exit if not
if vartype(aPrts) == "C"
  if ascan(aPrts,PDFWRITER) = 0
    return 0
  endif
endif

IF !FILE(REGFILE)
        MESSAGEBOX("INITPDFNAME: The required file "+REGFILE+" could not be found.")
        RETURN
ENDIF
if type("cRegKeyVal") <>"C"
        MESSAGEBOX("INITPDFNAME: The required filename parameter is missing")
        RETURN
ENDIF

return  SetRegValue(cRegKeyVal, ;
                                        "Software\Adobe\Acrobat PDFWriter" , ;
                                        "PDFFileName")


*====================================================================
FUNCTION  SetRegValue(cRegKeyVal, cRegFolder, cRegKeyName)    && Assign a registry key value
* Parameters:   (required) cRegKeyVal   - Key value to post
*                               (optional) cRegFolder   - Folder containing key
*                               (optional) cRegKeyName  - Key name
* Notes:                1. Uses REGISTRY.PRG
*                               2. Customized for setting PDF filename, but will set any key
* Returns:      nResult         - Numeric error# from SetRegKey() - 0=Success
*====================================================================

#DEFINE HKEY_CURRENT_USER           -2147483647  && BITSET(0,31)+1
LOCAL oReg,nErrNum
IF !FILE(REGFILE)
        MESSAGEBOX("SETREGVALUE: The required file "+REGFILE+" could not be found.")
        RETURN
ENDIF
if type("cRegKeyVal") <>"C"
        MESSAGEBOX("SETREGVALUE: The required key value parameter is missing")
        RETURN
ENDIF
* Parameters
cRegFolder  = iif(type("cRegFolder") =="C",cRegFolder ,"Software\Adobe\Acrobat PDFWriter")
cRegKeyName = iif(type("cRegKeyName")=="C",cRegKeyName,"PDFFileName")
oReg = NewObject("FoxReg",REGFILE)      && Create registry object
return oReg.SetRegKey(  cRegKeyName     , ;
                                                cRegKeyVal                              , ;
                                                cRegFolder                              , ;
                                                HKEY_CURRENT_USER)
right before your REPORT FORM, add the following line:
Code:
IF INITPDFNAME(Your_PDF_FileName) = 0

The registry entry is cleared by PDFWriter after the report is complete.

Warning: If a registry entry exists (for example if you call INITPDFNAME() but then do not call REPORT FORM) the entry will be detected the next time you print, and you won't be asked for a filename even if you wanted to be asked!


Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top