VFPDosPrint Quick Guide

(for more detailed help, see file dosprinten.chm included in the release package)


The fastest way to start using VFPDosPrint is using format files. All you will need is:
  • A format file that contains the report design
  • A data set to be used to generate the report

Let's say we have a Customer table with the following columns:
  • CustID
  • CustName
  • CustAddress
  • CustPhone
  • CustBalance

Now, we need to create a format file to generate a simple listing report. Create a text file with the following text. Once done, save the file with the name 'CUSTOMERS.FMT':

# CUSTOMERS.FMT
# Basic customer report
#
<config>
StartConfString=$C10$$COFF$    // 10 CPI not condensed (80 cols)
PaperLenght=60
TopMargin=2
LeftMargin=5                 
</config>

<macros>
COMPNAME='XYZ Bookstore'
COMPADDRESS='Caracas, Venezuela'
XCID=CustID
XCustBal=TRANSFORM(CustBalance,'9,999,999.99')
</macros>

<format>
#...+....[....+....[....+....1....+....1....+....1....+....1....+....1....+....1
he: [COMPNAME                         ]                                CUSTOMER LIST
he: %COMPADDRESS%
he: 
he: ID      FULL NAME               ADDRESS               PHONE #            BALANCE
he: ======= ======================= ===================== ============= ============
de: [XCID ] [PROPER(CustName)     ] [CustAddress        ] [CustPhone  ] [XCustBal  ]
fo: 
fo: 
fo: [datetime           ]                                                   %pageno%
</format>


Before proceed with the next step, lets take a closer look of this format file. First, note that everything is contained in sections wich starts with < > and ends with </ >. Each section has a defined purpose inside the format:

<config>: configures page size and margins, as well as specific printer configurations.
<macros>: define report-level variables (called Macros), that are used in other sections across the format.
<format>: define the layout of the report.

Everything enclosed with '' or '% %' delimiters are expandible expressions. This expressions will be evaluated and the result inserted in the text in the same position of the expanded expression. Finally, any line starting with # will be considered as a comment and will not be sent to the final report, as well as any empty line or text that is not enclosed inside a section.

Now, we are ready to generate our text report. All we need now is a data set and an instance of DOSPrint class:

*-- Generating customer report
*
SELECT 0
USE CUSTOMERS
GO TOP

LOCAL oDP
SET PROCEDURE TO vdp ADDITIVE
oDP=CREATEOBJECT("VFPDosPrint")
oDP.PrintFormat="CUSTOMERS.FMT"
oDP.Run()

At this time, we have our report generated and ready to be printed. Yes, is THAT easy. You can either send the report to a defined printer or save it to a file:

oDP.Print( GETPRINTER() )     && Send report to a selected printer
oDP.PrintToFile( GETFILE() )   && Save report to a disk file

This is a basic example of what can be done using VFPDosPrint. Please, read carefully the help file included in the release package to learn how you can use VFPDosPrint to generate really complex text-based reports or even structured files like HTML or XML!.

IMPORTANT NOTE ABOUT THE HELP FILE

VFPDosPrint is the open source version of a commercial product called DP or DOSPrint. Although I changed all references to DP in the source code to VFPDosPrint and remove the licensing restrictions, the help files are still the original ones and, therefore, they refers to DP and not VFPDosPrint. This will be fixed in the near future, so I apologize for the confusion in the mean time. Victor Espina.

Last edited Jul 22 at 2:24 AM by vespina, version 3

Comments

No comments yet.