Print to a file using reports: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m New page: 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...
 
m Added to Tutorials category
 
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
How can I print directly to a file such as PDF or Postscript?
How can I print directly to a file such as PDF or Postscript?
==== Using capabilities of your report engine ====
Some report engines that are often used with Visual DataFlex have native support for generating the report as a file using the PDF format.
Examples are:
#Crystal Reports can save a report to a PDF file
#VPE has this capability
#List&Label includes a PDF engine


==== 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 the actual sending of the mails.
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
<source lang="vdf">
        boolean bExists bMailed
function JumpStartReport string sInvoice boolean bEmail string sEmailAddress returns boolean
        integer iToPrinter iRepObj iHr iMn iRetval
    boolean bExists bMailed
        string  sVal sDateTime sHr sMn sSetupFile sPath sFilename
    integer iToPrinter iRepObj iHr iMn iRetval
        string  sKey sSubKey sOldRegRoot sOldRegBranch sCurrentDevice sMessage
    string  sVal sDateTime sHr sMn sSetupFile sPath sFilename
        handle  hoMapiSession
    string  sKey sSubKey sOldRegRoot sOldRegBranch sCurrentDevice sMessage
        dWord  dWWSecurityOptions  dWWFileOptions dRetVal
    handle  hoMapiSession
        date    dToday
    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
        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 Moshenek" + CR_LF)                                                            to sMessage
    // gotta have it
            move (sMessage + "Credit Manager, Duffie Graphics, Inc." + CR_LF)                                                    to sMessage
    move oMapiSession to hoMapiSession
            move (sMessage + "800-446-9130" + CR_LF)                                                           to sMessage
    //showln hoMapiSession
            move (sMessage + "bmosh@duffiegraphics.com" + CR_LF + CR_LF)                                                          to sMessage
    if (NOT(hoMapiSession > 0)) begin
            move (sMessage + "Thank you for choosing Duffie Graphics & DgiLine!")                                                 to sMessage
        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
</source>
 
====Using VB.net====
Not VDF code, but a VB.net code sample that you can use to model against (or use it by wrapping it in a small .net binary)
 
http://groups.google.com/group/microsoft.public.dotnet.framework.drawing/browse_thread/thread/66e5f32dd0fc1757
 
====Using Acrobat====
Acrobat Reader is the original product for reading PDF documents.
The product for creating PDF documents is distiller.
 
If you want to use the Reader component to print an existing document, then beware that it has been reported that the activeX control doesn't get properly released from memory. Last version that did this properly was version 4.
Unfortunately newer versions are getting more bloated with each release.
 
====Using xpdf====
Over at http://www.glyphandcog.com you can find the xpdfprint component.
The xpdf engine is one of the more common ways of rendering your PDF documents on unix/linux environment.
This is a stable component for print and for 'overlaying' text on print time (so without ammending the PDF)
 
====Using List&Label====
 
List and Label can be used as your Report Engine in VDF, see also www.combit.net
 
L&L includes a royalty free designer that you can distribute with your app and which is able to write to a variety of file formats including PDF, Excel and HTML as well as printing directly to your printer (of course)
 
====Using PDFCreator====
You may also want to take a look at [http://sourceforge.net/projects/pdfcreator/ PDFCreator] -- a freeware PDF printer app that works great, and although I haven't done so, I believe it could be incorporated for use from a vdf program
 
====AloahaPDF Studio====
AloahaPDF Studio can be used for amending protected PDF's. Also for signing PDF's
 
====PDFSplitMerge====
PDFSplitMerge from Guangming Software can be used for splitting and merging of PDF documents.
 
====CutePDF====
Starting with a PDF that has form fields, for example created with Adobe Live Cycle Designer.


            get  DFGetCurrentDevice of iRepObj to sCurrentDevice
You can do the following with a VDF14 program:
            send DFSetDevice        of iRepObj    "Win2PDF"
1. Create an XML file (or stream) with the data for the form
            //
2. Imports the data into the PDF form shell producing a new filled and flattened PDF form (uses CutePDF SDK u$250 per server)
            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 ("Duffie Graphics 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


CutePDF can also be used to export data to XML or XFDF or FDF


====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]
[http://www.sture.dk/wasp/threadreport.asp?ThreadId=42434 Print to a PDF document]
[http://www.planetpdf.com Lot's of PDF information]
[http://www.win2pdf.com Win2PDF]
[http://www.activepdf.com ActivePDF]
[http://www.dynamicpdf.com DynamicPDF]
[http://www.cutepdf.com/ CutePDF]
[[Category:How To]]
[[Category:Tutorials]]

Latest revision as of 11:46, 25 March 2020

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

Using capabilities of your report engine

Some report engines that are often used with Visual DataFlex have native support for generating the report as a file using the PDF format. Examples are:

  1. Crystal Reports can save a report to a PDF file
  2. VPE has this capability
  3. List&Label includes a PDF engine

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

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
        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

Using VB.net

Not VDF code, but a VB.net code sample that you can use to model against (or use it by wrapping it in a small .net binary)

http://groups.google.com/group/microsoft.public.dotnet.framework.drawing/browse_thread/thread/66e5f32dd0fc1757

Using Acrobat

Acrobat Reader is the original product for reading PDF documents. The product for creating PDF documents is distiller.

If you want to use the Reader component to print an existing document, then beware that it has been reported that the activeX control doesn't get properly released from memory. Last version that did this properly was version 4. Unfortunately newer versions are getting more bloated with each release.

Using xpdf

Over at http://www.glyphandcog.com you can find the xpdfprint component. The xpdf engine is one of the more common ways of rendering your PDF documents on unix/linux environment. This is a stable component for print and for 'overlaying' text on print time (so without ammending the PDF)

Using List&Label

List and Label can be used as your Report Engine in VDF, see also www.combit.net

L&L includes a royalty free designer that you can distribute with your app and which is able to write to a variety of file formats including PDF, Excel and HTML as well as printing directly to your printer (of course)

Using PDFCreator

You may also want to take a look at PDFCreator -- a freeware PDF printer app that works great, and although I haven't done so, I believe it could be incorporated for use from a vdf program

AloahaPDF Studio

AloahaPDF Studio can be used for amending protected PDF's. Also for signing PDF's

PDFSplitMerge

PDFSplitMerge from Guangming Software can be used for splitting and merging of PDF documents.

CutePDF

Starting with a PDF that has form fields, for example created with Adobe Live Cycle Designer.

You can do the following with a VDF14 program: 1. Create an XML file (or stream) with the data for the form 2. Imports the data into the PDF form shell producing a new filled and flattened PDF form (uses CutePDF SDK u$250 per server)

CutePDF can also be used to export data to XML or XFDF or FDF

External Links

OT: Print to a File

Print to a PDF document

Lot's of PDF information

Win2PDF

ActivePDF

DynamicPDF

CutePDF