Print to a file using reports

From DataFlex Wiki
Jump to navigationJump to search

How can I print directly to a file such as PDF or Postscript?

Using WinPDF Pro

The example below uses WinPDF Pro printer driver for the PDF generation, Winprint (or at least the report object in VDF) for the reporting and MAPI for sending the mails directly.

Pardon the jumbled looking code, but with Win2PDF pro you can do the following:

   function JumpStartReport string sInvoice boolean bEmail string sEmailAddress returns boolean
       boolean bExists bMailed
       integer iToPrinter iRepObj iHr iMn iRetval
       string  sVal sDateTime sHr sMn sSetupFile sPath sFilename
       string  sKey sSubKey sOldRegRoot sOldRegBranch sCurrentDevice sMessage
       handle  hoMapiSession
       dWord   dWWSecurityOptions  dWWFileOptions dRetVal
       date    dToday
       //
       get Report_Object_Id To iRepObj
       //
       set pSelStart1 of iRepObj To sInvoice
       set pSelStop1  of iRepObj To sInvoice
       //
       if (bEmail) ;
           set OutPut_Device_Mode to PRINT_TO_PRINTER_NO_DIALOG
       else        ;
           set OutPut_Device_Mode to PRINT_TO_PRINTER
       //
       if (bEmail) begin
           move ("Please find attached your invoice" * sInvoice + ".")                                                           to sMessage
           move (sMessage + CR_LF + CR_LF)                                                            to sMessage
           move (sMessage + ;
               "If payment has been submitted, please keep this invoice as a record of payment.")                                to sMessage
           move (sMessage + CR_LF + CR_LF)                                                            to sMessage
           move (sMessage + ;
               "If you have any question regarding this email or other billing inquiries, please contact me by phone or email.") to sMessage
           move (sMessage + CR_LF + CR_LF)                                                            to sMessage
           move (sMessage + "Thank you,")                                                            to sMessage
           move (sMessage + CR_LF + CR_LF)                                                            to sMessage
           move (sMessage + "Barbara Bambenek" + CR_LF)                                                            to sMessage
           move (sMessage + "Credit Manager, Daffie Duck, Inc." + CR_LF)                                                     to sMessage
           move (sMessage + "555-436-9130" + CR_LF)                                                            to sMessage
           move (sMessage + "bdoe@duffieDaffie.com" + CR_LF + CR_LF)                                                          to sMessage
           move (sMessage + "Thank you for choosing Daffie Duck products!")                                                 to sMessage
           get  DFGetCurrentDevice of iRepObj to sCurrentDevice
           send DFSetDevice        of iRepObj    "Win2PDF"
           //
           get psHome of (phoWorkspace(ghoApplication))          to sPath
           move (sPath + "Documents\")                           to sPath
           move ("Invoice_" + sInvoice + ".pdf")                 to sFilename
           Get_Registry_Root                                     to sOldRegRoot sOldRegBranch
           move "Dane Prairie Systems"                           to sKey
           move "Win2PDF"                                        to sSubKey
           Set_Registry_Root                                     to HKEY_LOCAL_MACHINE "SOFTWARE"
           Set_Foreign_Profile_String sKey sSubKey "PDFFileName" to (sPath + sFilename)
           Set_Foreign_Profile_String sKey sSubKey "PDFTitle"    to ("Invoice " + sInvoice)
           Set_Foreign_Profile_String sKey sSubKey "PDFAuthor"   to "Calendar Invoicing"
           Set_Foreign_Profile_String sKey sSubKey "PDFSubject"  to ("Calendar Invoice")
           Set_Registry_Root                                     to sOldRegRoot sOldRegBranch
           //Get CheckFileExists sFileName to bExists
           //If (bExists) Set pbOrgCopyPrinted to TRUE
       end // if (bEmail) begin
       //
       send Run_Report to iRepObj
       //
       if (NOT(bEmail)) procedure_return
       // restore the print device
       send DFSetDevice of iRepObj sCurrentDevice
       // gotta have it
       move oMapiSession to hoMapiSession
       //showln hoMapiSession
       if (NOT(hoMapiSession > 0)) begin
           send Stop_Box "Unable to email invoice."
           procedure_return
       end
       send DoInit          of hoMapiSession
       set psMessageSubject of hoMapiSession to ("Daffie Duck Invoice" * sInvoice)
       set psMessageText    of hoMapiSession to sMessage
       send DoAddReceiver   of hoMapiSession MAPI_TO (trim(sEmailAddress)) "" "" 0
       send DoAddAttachment of hoMapiSession (sPath + sFilename) sFilename
       get Logon            of hoMapiSession "" "" 0 to iRetval
       //showln iRetval
       get SendMail         of hoMapiSession (MAPI_NEW_SESSION IOR MAPI_LOGON_UI) TRUE to iRetval
       //
       showln (sInvoice * trim(sEmailAddress) * string(iRetval))
       move (iRetval = 0) to bMailed
       //
       get Logoff           of hoMapiSession to iRetval
       //
       function_return bMailed
   end_function // JumpStartReport

External Links

OT: Print to a File