I want to predefine the pdf's file name

If you are a VFP developer and have any questions about using our products from VFP here is the place to post them.
Post Reply
mganem
Posts: 1
Joined: Mon Jun 13 2005

I want to predefine the pdf's file name

Post by mganem » Mon Jun 13 2005

I'm use VFP7 ENG SP1, and i have amyuni converter 2.50b

what are the correct sentences for include in my prg ?

i'm used this code...

*-----------------------------
* Program.....: PrintToPDF.prg
*
* Parameters..: tcReportName - the name of the VFP report to be run
* tcFileName - the name of the PDF file to be created
*
* Returns.....: Logical
*
#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 overwrite
#DEFINE pdf_DisableCompression 8 && disable page content compression
#DEFINE pdf_EmbedFonts 16 && embed fonts used in the input document
#DEFINE pdf_BroadcastMessages 32 && enable broadcasting of PDF events

lParameters tcReportName, tcFileName
* The tcReportName paremeter is required.
if vartype( tcReportName) <> "C"
ASSERT .F. MESSAGE "Parameter tcReportName is missing or invalid"
RETURN .F.
endif
* The tcFileName parameter is optional and defaults to tcReportName if omitted.
if vartype( tcFileName) <> "C"
tcFileName = ALLTRIM( tcReportName) + ".PDF"
endif
* Append a .PDF extension if it's not already there.
if UPPER( SUBSTR( tcFileName, LEN( ALLTRIM( tcFileName)) - 3)) <> ".PDF"
tcFileName = tcFileName + ".PDF"
endif

* Create an instance of the Amyuni PDF Compatible Printer Driver control.
oPDFPrinter = CREATEOBJECT( "CDINTF.CDINTF")
if vartype( oPDFPrinter) <> "O"
RETURN .F.
endif

* Define memvars.
private pnErrorCount
pnErrorCount = 0
local lcOldError, lcPrinterName
lcOldError = on("error")
lcPrinterName = set("Printer", 3) && Save the current VFP printer name.

* Set up our error handler, which will display LASTERRORMSG() from the PDF driver.
on error do ErrHand

* Initiate driver with name "PDF Compatible Printer Driver".
* ("PDF Compatible Printer Driver" will now appear in the list of printers.)
oPDFPrinter.PDFDriverInit( "PDF Compatible Printer Driver")

*!* Set the destination file name.
* If path is included, use it (user may want file in a diffent folder)
if tcfilename=justfname(tcfilename)
oPDFPrinter.DefaultFileName = SYS(5) + ADDBS( SYS(2003)) + tcFileName
else
* leave the path as the user set it...
oPDFPrinter.DefaultFileName = tcFileName
endif

*!* set resolution to 1200 for the best quality
oPDFPrinter.resolution = 1200

*!* update driver info with resolution info
oPDFPrinter.SetDefaultConfig()

* Note: Message broadcasting should be enabled in order to insert bookmarks from VFP.
* But see the notes in the AddBookmark function below!
oPDFPrinter.FileNameOptions = pdf_NoPrompt + pdf_UseFileName + pdf_BroadcastMessages

* Save the current Windows default printer so we can restore it later.
oPDFPrinter.SetDefaultPrinter()

* Set the VFP printer name to the PDF printer, and print the report.
set printer to name "PDF Compatible Printer Driver"
REPORT FORM (tcReportName) NOEJECT NOCONSOLE TO PRINTER

* Restore the Windows default printer.
oPDFPrinter.RestoreDefaultPrinter()

* Restore the previous error handler.
on error &lcOldError

* Restore the VFP printer name to the previous name.
set printer to name "&lcPrinterName"

* Uninstall the printer driver we installed with PDFDriverInit()
oPDFPrinter.DriverEnd()

RETURN pnErrorCount = 0


* Adds a bookmark to the report at the current print location.
FUNCTION AddBookmark
PARAMETERS PageNo
*!* THIS WILL NOT WORK unless we have the actual device context (hDC)
*!* to pass as the first parameter to SetBookmark. Use the FLL interface
*!* if we need to insert bookmarks.
oPDFPrinter.SetBookmark( 0, "Test" + STR(PageNo))
RETURN ""

* error handling: displays last error message
PROCEDURE ErrHand
*!*? "Error message: " + LASTERRORMSG() && This syntax is only for the FLL.
? "Error message: " + oPDFPrinter.GetLastErrorMsg() && This syntax is for the DLL.
pnErrorCount = pnErrorCount + 1
RETURN

------------------------------------------------------------------------------------
Regards.

GMD

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Mon Jun 13 2005

Hello,

I read your code and didn't really get what is your question.

If you wish please take a look at our model VFP sample application at: http://www.amyuni.com/en/support/technotes.html

Post Reply