therob1 Posted December 29, 2010 Share Posted December 29, 2010 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/ Share on other sites More sharing options...
trq Posted December 29, 2010 Share Posted December 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152517 Share on other sites More sharing options...
therob1 Posted December 29, 2010 Author Share Posted December 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152536 Share on other sites More sharing options...
trq Posted December 29, 2010 Share Posted December 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152542 Share on other sites More sharing options...
therob1 Posted December 29, 2010 Author Share Posted December 29, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152572 Share on other sites More sharing options...
BlueSkyIS Posted December 29, 2010 Share Posted December 29, 2010 i would create your templates in whatever application you want, then print/export them to PDF for use by your document system. FPDI does a great job of managing/manipulating multi-page PDFs http://www.setasign.de/products/pdf-php-solutions/fpdi/ Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152587 Share on other sites More sharing options...
trq Posted December 29, 2010 Share Posted December 29, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152775 Share on other sites More sharing options...
therob1 Posted December 30, 2010 Author Share Posted December 30, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152908 Share on other sites More sharing options...
theverychap Posted December 30, 2010 Share Posted December 30, 2010 Set the datatype of the table colum to BLOB - you will then be able to store whatever you like Also, CKEditor is a fantastic editor! Quote Link to comment https://forums.phpfreaks.com/topic/222896-working-with-documents-and-is-php-really-the-best-choice/#findComment-1152927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.