Right now I have a document that's almost like a template that has bold, indention, header and I would like to be able to take the contents of that document and replace certain strings with what the user inputs in forms that I have set up. I have it working where it makes a new one and replaces the words with just a plain text document with no special formatting. Is there a way to do this with keeping all of the formatting? Anyway it needs to be done is cool, but I've been using mostly PHP and the code I have so far to do it is PHP.
Here's what the code looks like that works with no formatting.
<?php
session_start();
$file = tempnam(sys_get_temp_dir(), 'TMP_');
file_put_contents($file, file_get_contents("freewillben1.docx"));
//replaces string in document with data
$fh = fopen($file, 'a') or die("can't open file");
$placeholders = array('Fff', 'Mmm','Lll');
$namevals =
array($_SESSION["fName"],$_SESSION["mInitial"],$_SESSION["lName"]);
$path_to_file = 'freewillben1.docx';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace($placeholders,$namevals,$file_contents);
file_put_contents($file,$file_contents);
fclose($fh);
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
$type = filetype($file);
// Get a date and timestamp
$today = date("F j, Y, g:i a");
$time = time();
// Send file headers
header("Content-type: application/vnd.openxmlformats-
officedocument.wordprocessingml.document");
header("Content-Disposition: attachment; filename=yourwill.docx");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);
?>