Skip to content

TechXcel.com - provides technical excellence...

Narrow screen resolution Wide screen resolution Increase font size Decrease font size Default font size default color orange color green color
You are here: Home arrow PHP arrow Printable Document Generation with PHP
Printable Document Generation with PHP PDF Print E-mail
(7 votes)
Written by Chetankumar Akarte   
Tuesday, 13 March 2007
Article Index
Printable Document Generation with PHP
Advantages of RFT Format
1. Generate Template
2. Open template in PHP
3. Modifying contents
4. Save Document
Download Source Code

Modifying contents



Here we just replace all the placeholders in our template file and generate our modified output file as ‘output.rtf’. for that purpose we are using function modifier($vars, $doc_file).This function takes two parameters the first, $vars, is an array of key/value pairs representing the placeholder and value for that placeholder. The second parameter, $doc_file, represents the template file to populate.

(Code 1:- test.php)

<?php
$vars = array('date' => date("F d, Y"),
'place' => 'Nagpur',
'name' => 'Flint Hancock',
'language' => 'PHP',
'grade' => 'A', );
$new_rtf = modifier($vars, "certificate.rtf");
$fr = fopen('output.rtf', 'w') ;
fwrite($fr, $new_rtf);
fclose($fr);

function modifier($vars, $rftfile) {

$xchange = array ('\\' => "\\\\",
'{' => "\{",
'}' => "\}");

$document = file_get_contents($rftfile);
if(!$document) {
return false;
}

foreach($vars as $key=>$value) {
$search = "%%".strtoupper($key)."%%";

foreach($xchange as $orig => $replace) {
$value = str_replace($orig, $replace, $value);
}
$document = str_replace($search, $value, $document);
}
return $document;
}
?>
<h2>sucessfully Generated File</h2>




Last Updated ( Tuesday, 04 September 2007 )
 

Who's Online

User Login

PayPal Donation

Enter Amount:

Syndicate

TechXcel's Friends

Tutorials Garden
Wicolorz
pixel2life

Text Link Add

Statistics

Members: 276
News: 60
Web Links: 6
Visitors: 348450

Google Seach

Google AdSense

TechXcel Referrals

TechXcel's Sponcer...