3 Replies Latest reply on Mar 30, 2011 1:07 PM by Reed Powell

    Working with RTF documents - Need Opinions

    dujsu Level 1



      Ive been assigned to a project that must dynamically generate documents (in this case RTF), the content of the document differs based on choices made within the application. These documents have a specifically formatted letter head and closing signature, but the content in between is what differs. Some privileged users will need to be able to edit these documents and then save their changes.


      We are not allowed to use OpenOffice on our servers at the moment (not sure if it matters) but need to eliminate it as a possibility. Is there a way to grab the modified RTF (object) and shove it into a database (or somewhere else the Sun doesn't shine)?


      All suggestions are appreciated. Thanks ahead of time.

        • 1. Re: Working with RTF documents - Need Opinions
          Reed Powell Level 3

          Back in the old days before CF could easily create documents I had to do this sort of thing.  What ended up working best was a sort of poor-man's mail-merge approach.  Generate the RTF templates with formatting, layouts, headers, etc.  At the spots where content needs to be inserted, just type in something like "placeholder1", "placeholder2", etc.  Then in your CF script that generates the actual document use CFFILE to read in the template to a CF var, and do a replace() to replace each of the "placehoder" instances with the appropriate dynamic data.  Note that you will not be able to format that data being inserted (since the formatting is done in rtf), so if you are trying to populate lists, tables, etc., then it's going to take a lot more work.  That would mean experimenting with using Word (or whatever) to create sample rtf strings for lists, tables, etc., to see what they need to look like, and then in your CF code that replace()s the "placeholders" you would include not just the dynamic values, but also the associated rtf syntax elements to get the look and feel you want.  The same holds true for handling things like line breaks and paragraph breaks.


          There used to be a CF function running around for creating sheets of labels for printers.  What it did was to create an RTF document that you would then open in Word to do the actual printing.  If you can find it laying around it might provide some insight into creating entire RTF documents from within CF.



          • 2. Re: Working with RTF documents - Need Opinions
            dujsu Level 1



            Thank you for the reply. What you mentioned is how I have envisioned generating the RTF initially, the only difference would be the placeholders will most likely be wrapped in brackets ie. [placeholderX]. So we are on the same thought track up to this point.


            After the document is created though I was hoping to create a way for the user to view the RTF that was generated, allow them to edit it, and then save the changes. This is the most important piece as far as this project goes.


            Thanks again for your suggestions.

            • 3. Re: Working with RTF documents - Need Opinions
              Reed Powell Level 3

              Getting the document back to the user is the easy part - just create the RTF document in your CF script and save it to the server, then use the CFCONTENT and CFHEADER tags to get it back to the user.  Not sure what the mime type is for rtf but that's what Google is for.  There are plenty of posting on this forum that explain how to use these tags to get Word, Excel, etc., back to the user.  There is some dependency on the browser as to whether it is opened automatically by the browser in Word, or whether the user will get the "Run or Save" dialog box.