Dear All,
I am a new learner and I need your help. I am trying to design a website and one of the things I want to do is find and replace text from the template based upon user input. These will be document templates and certain words from the template will be changed as per user input but formatting of the document will remain unchanged. Let me give an example:
If the tempate has "Client Name: John Smith" and user input for name was Joseph Barker then the final document will read "Client name: Joseph Barker" and the final document can be downloaded as PDF and MS Doc file. There will be several lines in the templates and only a handful of the words need to be changed by the user. Formatting should be kept same. How can I acheive this? Which programming language should be used? Can we do this using PHP or Python or HTML/JavaScript?
Help me please..

Hi,
if you choose PHP then use variables, for example:

<p>Client Name: <?php echo "$firstname $lastname"; ?></p>

To assign the values to the variables $firstname and $lastname you can use the input submitted by a form:

<form method="post" action="document.php">

    <label for="firstname">Firstname:</label>
    <input type="text" name="firstname" />
    <br />

    <label for="lastname">lastname:</label>
    <input type="text" name="lastname" />
    <br />

    <input type="submit" name="submit" value="submit" />

</form>

And in document.php:

<?php

    $firstname = $_POST['firstname'];
    $lastname  = $_POST['lastname'];

?>

<p>Client Name: <?php echo "$firstname $lastname"; ?></p>

Basically it works like this, but you have to check if the input is valid, i.e. it is not executable code like Javascript or PHP. Then the source can change, instead of the $_POST, initialized by the method of the form (<form method="post" ...), you can get the input from the database or from the session.

The same can be done in Python if you feel more confortable with it. You can also use Javascript, and use AJAX to save the input on the server side. To generate PDF files with Javascript you can try this:

But there are also server side solutions for PHP and Python.

These links may be useful for you:

Thanks for the reply..do you know how to save as Document??

You're welcome, you could try PHPWord:

Which is a library to generate docx, odt, rtf and pdf files. But I didn't tested yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.