<

Go Premium for a chance to win a PS4. Enter to Win

x

Generate dynamic RTF (Rich Text Format) documents easily

Published on
11,174 Points
4,974 Views
2 Endorsements
Last Modified:
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access.

In this tutorial I will show you how to make RTFs with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html

Create your document
First you need to make an RTF template, it is how the document will look like. I have created a file which lists the first name, last name, telephone, email and address in a table.

 Create an RTF file
As you can see the dynamic part will contain WhizBase code.  I have putted $wbf[fname], $wbf[lname], $wbf[email], $wbf[tel] and $wbf[address] in the cells I want to show dynamic data.

These placeholders will be replaced dynamically with data.

Now just save the document as RTF file. You go to "Save As" and save the file as "form.rtf".



Create you database file

The database can be in any format, I will use Microsoft Access because it is the easiest for me. You can use MySQL, Oracle, MS SQL or even Microsoft Excel.

I will create a database file with one table "contacts", it will contain these 6 fields:

 Create an Access DB
ID – autonumaber and primary key
Fname – text
Lname – text
Email – text
Tel – text
Address – memo

Open in new window


Now save this file as "form.mdb"
I have inserted some records in this table.

Create WhizBase file
Finally we need a file which will be our webpage which takes the ID and gives us the RTF document. So we need to implement an input form for ID, and when submit is clicked then start downloading the new generated file.

First let's rename the file "form.rtf" to "form.ic", "ic" is the extension for included files in WhizBase by the function $wbrinc.

Now create an HTML file with this code:
<html><body><form action='form.wbsp' method='post'>Insert ID: <input type='text' name='wbf_id' /><input type='submit' value='Export file' /></form></body></html>

Open in new window


This is a very basic HTML form file, the only thing you must not forget is the name of the text field, it will be wbf_id, which I have already explained in previous tutorials. Save this file as "default.wbsp".

Now we create another WhizBase file where we query the DB and include the RTF template file.

[FormFields]
WB_BaseName=form.mdb
WB_Command=Q
WB_RcdSet=contacts
WB_ShowLogo=F
wb_contenttype=application/msword
<!--WB_BeginTemplate-->
$wbrinc[form.ic]

Open in new window


As you can see nothing new, we are simply querying the DB and including the template which have the placeholders which will be replaced with data. The only important and new thing is the line:
wb_contenttype=application/msword

Open in new window


Here we say to the browser that this documents type is not HTML so do not render it, we say it is MS WORD  application type, so any popular browser will just download it to your computer.

And you have now a ready script to make RTF reports easily.

For more information please visit my member profile at http://www.experts-exchange.com/M_5123186.html
Or visit the WhizBase official site at www.whizbase.com

NurAzije is a PHP and WhizBase programmer, who at the time of article publication has been working in partnership with WhizBase company on several projects and very recently as an employee.
2
Comment
Author:NurAzije
0 Comments

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Join & Write a Comment

Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month