Jump to content

working with documents and is php really the best choice?


therob1

Recommended Posts

Hi,

 

I've been looking around the net and various forums and found that the code below does appear to work and do what I need at a basic level, but I was wondering if there was a quick and easy way to improve this code OR another alternative that would give me similar/better results.

 

I effectively have certain word documents that I want to use as templates for part of a project. So if i were to write a letter I could pull from the DB usual name/address, but also other intelligent information that might be dependant on different DB fields so it could generate different options, ie if they had children it would produce a different sentence??

 

Obviously my ideal solution would be that the php coding wouldnt need to be touched, but would allow for 'coded options' within the document to be added/removed without causing any issues, maybe some kind of generic coding so at least some content can be re-used for multiple documents ?

 

However, I did have two initial thoughts on how to do some of this - maybe? (be gentle im still a learner!)

 

1, create an array of somekind and use generic terms for a set range, say 'bookmark1','bookmark2', etc so a user could just tag the original word document knowing they only had to add a new number to the end if they needed to add something new ?

2,read the document contents out -DO STUFF TO IT- load it back into a doc/save. with this method I will have to admit ive not done before so would welcome any extra detailed input or advisory suggestions, ie. ensuring it goes back into the correct format, say there was an image/logo or complicated series or bulleted paragraghs or tables ??

 

I have initially choosen MS word as many people out there are familiar with this product and is widely used. However, if it means I am able to create something easily and better within some other format or package that will give me what I want but also be compatible with word then im more than happy to go with any suggestions (ie templates initially created within openoffice and merely saved into .DOC format?)

 

<?php
//1. Instanciate Word
$word = new COM("word.application") or die("Unable to instantiate Word");
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = "C:/t.doc";
//3. open the template document
$word->Documents->Open($template_file);
//4. get the current date MM/DD/YYYY
$current_date = date("m/d/Y");
//5. get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname = "mytester";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
//6. now substitute the bookmark with actual value
$range->Text = $current_date;
//7. save the template as a new document (c:/reminder_new.doc)
$new_file = "c:/reminder_new.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
//$word->Release();
$word = null;
?>

Link to comment
Share on other sites

Proprietary formats in general suck. There never easy to read from or write to because they are a closed format. Working with COM however your working directly with them, of course COM is just another proprietary interface that (again) is a nightmare to work with because it is so closed.

 

What exactly do you plan on doing with these documents when they are completed? Do people need to download and keep them? Print them? What?

Link to comment
Share on other sites

Im creating a mini-system for a friend who has his own business, so im wanting to create/store 'clients' and 'cases' for each client. Every time a letter/document gets drafted I want it to generate/store a copy within the history of each case.

 

so I would guess i want to generate the document first copy it into the 'case history location' then load on screen the word document thats just been stored so the user could check/amend/print the letter to send out - either as fax,email attachment,printer

 

does that make more sense ?

 

one thing i might be thinking about longer term would be to have the option to convert/send out via PDF as its more universal and probably more tamper proof than a DOC file  - HOWEVER, it would be a nice to have in the future, but worth mentioning incase you have any further thoughts or ideas for this?

Link to comment
Share on other sites

The system you describe doesn't really sound like it would need 'documents' at all. Whats wrong with storing your content in a database? You can easily print it, turn it into a pdf and attach it to emails, just send it as emails, whatever.

Link to comment
Share on other sites

he would need to send letters out as some clients are not allowed to accept instructions electronically, and some others are not internet savvy.

 

he has a bank (maybe around 100 ) of standard letters/documents that he manually has to customise each time he needs to send out a letter, what im trying to do is help him with the efficiency and also try to make it so he can do certain revisions without any input from a developer.

 

so a typical example would be a "letter to client" thanking them and pulling through usual mail merge style name/address then changing certain words/sentences within the body of the letter to make them more intelligent/dynamic

 

ive previously seen some systems where you just keep the bulk of the document and put in 'tags' around where you want the content to change, such as "%TAG% WORDS TO CHANGE %TAG%" I dont know if/what these types of systems are called.

 

however, I would be interested to know how I could build something that wouldnt be dependant on a word processor package but was able to allow me to create my own document templates and code up parts the way I wanted. How would this typically be achieved, maybe a large textarea that would also allow for user to make final amendments then a button to generate into PDF ?

Link to comment
Share on other sites

he would need to send letters out as some clients are not allowed to accept instructions electronically, and some others are not internet savvy.

 

As I said....

 

Whats wrong with storing your content in a database? You can easily print it,
Link to comment
Share on other sites

nothing wrong with storing the content into a db, but im then going to need to create some kind of interface and toolbar (such as tiny mce) to allow for format/editing. What would you suggest is going to be the best method of doing this and how would i store the text + images within the same DB field?

 

I would also need provide some kind of import facility for existing documents, im guessing cut and paste could be workable, but not ideal

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.