Print to a file using reports: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m
Line 2: Line 2:


==== Using WinPDF Pro ====
==== 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.
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.  Note that each invoice in this example is printed individually.


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


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

edit

Navigation menu