LPARAMETERS m.ReportName, m.Limiter * * Creates a PDF document from a VFP report. * * Requires: * Windows NT & 2000 - AcfPDF.dll, AcfPDFUI.dll, PDFMon.dll, ; * PDFIntf.dll, AcfPDF.txt, CDIntf.dll * Windows 95 & 98 - AcfPDF.drv, PDFIntf.dll, CDIntf.dll *---------------------------------------------------------------- IF PARAMETERS() < 1 OR NOT FILE(FORCEEXT(m.ReportName, "FRX")) MESSAGEBOX("Report " + m.ReportName + " does not exist") RETURN .F. ENDIF IF PARAMETERS() < 2 m.Limiter = "" ENDIF LOCAL oPDF, ; m.OldPrinter, ; m.ErrorMsg, ; m.CleanUp LOCAL ARRAY m.PrinterNames(1) * Some constants for the PDF writer *---------------------------------- #DEFINE PDF_NOPROMPT 1 && do not prompt for file name #DEFINE PDF_USEFILENAME 2 && use file name set by SetDefaultFileName else use document name #DEFINE PDF_CONCATENATE 4 && concatenate files, do not override #DEFINE PDF_DISABLECOMPRESSION 8 && disable page content compression #DEFINE PDF_EMBEDFONTS 16 && embed fonts used in the input document m.CleanUp = .F. * Setup the PDF Writer *--------------------- oPDF = CREATEOBJECT("CDINTF.CDINTF") && This is the PDF writer (ActiveX version - CDIntf.dll) * This is probably overkill for most people. * We had an issue with user rights and had to pre-install * the PDF Writer print queue under NT and 2000. *-------------------------------------------------------- IF APRINTERS(m.PrinterNames) > 0 AND ; ASCAN(m.PrinterNames, "PDF Writer", 1) > 0 oPDF.DriverInit("PDF Writer") && Initialize the PDF Writer printer ELSE IF OS() = "Windows NT 4.00" OR ; OS() = "Windows 5.00" MESSAGEBOX("The PDF Writer print queue is not properly installed.", 48, "JFAST Message") RETURN .F. ELSE oPDF.PDFDriverInit("PDF Writer") && Creates a printer called PDF Writer m.CleanUp = .T. ENDIF ENDIF oPDF.Resolution = 600 && Sets the PDF resolution to 600 DPI oPDF.Orientation = 2 && Sets the PDF orientation to landscape (just to initialize it) oPDF.SetDefaultConfig && Saves the current configuration * If the file already exists at this point * assume that this new report is to be concatenated * with the existing pdf file. Note: This WILL NOT * work in the demo version. (Unless they've fixed * that in the last couple of months). *-------------------------------------------------- IF FILE(ThisForm.PDFFile) oPDF.FileNameOptions = ; PDF_NOPROMPT + ; PDF_USEFILENAME + ; PDF_EMBEDFONTS + ; PDF_CONCATENATE ELSE oPDF.FileNameOptions = ; PDF_NOPROMPT + ; PDF_USEFILENAME + ; PDF_EMBEDFONTS ENDIF oPDF.DefaultFileName = ThisForm.PDFFile && Sets the output file name * Print *------ *m.OldPrinter = SET('PRINTER',3) && Save the old priter settings - see Note below SET PRINTER TO NAME "PDF Writer" && Set the current printer REPORT FORM (m.ReportName) ; &Limiter. ; NOEJECT ; NOCONSOLE ; TO PRINTER && Print the report (duh) *--------------------------------------------- * Note: This doesn't work... kinda. * It does change it back so other reports will * print to m.OldPrinter. But... if you use * PROMPT in the REPORT FORM command it will * crash in VFP 6.0 SP3. * * SET PRINTER TO NAME (m.OldPrinter) *--------------------------------------------- SET PRINTER TO DEFAULT && Reset printer to the default * Set the file name to something else * This prevents the users from printing from * another windows app to the PDF Writer print * queue and overwriting your PDF doc. *-------------------------------------------- oPDF.DefaultFileName = "gibberish.pdf" IF m.CleanUp oPDF.DriverEnd ENDIF RETURN .T.Hope this helps.