Specifications

header( “Content-type: application/msword” );
header( “Content-Disposition: inline, filename=cert.rtf”);
The first header tells the browser that we are sending a Microsoft Word file (not strictly true,
but the most likely helper application for opening the RTF file).
The second header tells the browser to automatically display the contents of the file, and that
its suggested filename is cert.rtf. This is the default filename the user will see if he tries to save
the file from within his browser.
After the headers are sent, we open and read our template RTF file into the $output variable,
and use the str_replace() function to replace our placeholders with the actual data that we
want to appear in the file. The line
$output = str_replace( “<<Name>>”, $name, $output );
will replace any occurrences of the placeholder <<Name>> with the contents of the variable
$name.
Having made our substitutions, its just a matter of echoing the output to the browser.
A sample result from this script is shown in Figure 30.5.
Generating Personalized Documents in Portable Document Format (PDF)
C
HAPTER 30
30
GENERATING
PERSONALIZED
DOCUMENTS IN
PDF
761
FIGURE 30.5
rtf.php generates a certificate from an RTF template.
36 7842 CH30 3/6/01 3:40 PM Page 761