10 Replies Latest reply on Feb 16, 2010 1:31 PM by Dinghus

    Convert Word RTF to PDF with ColdFusion

    Dinghus Level 1

      I have thousands and thousands of rtf documents that need to be converted to pdf. Anybody like to tell me how to do this in ColdFusion 8?

        • 1. Re: Convert Word RTF to PDF with ColdFusion
          insuractive Level 3

          A conversion like the one you describe is probably best handled by batch conversion software that can make the RTF to PDF conversion.  ColdFusion probably won't be the best choice for you here - Although you can read in the contents of the RTF file using <cffile>, coldfusion won't know how to translate the RTF format into HTML formatting needed to generate a PDF via <cfdocument>.  If you absolutely had to use coldfusion to complete the project, you could look into using Java packages (maybe iText?) to perform the task, but I'm not sure if libraries exist out there that do what you are asking.  However, since there are specific software applications written specifically for this sort of thing, you can probably find inexpensive software that has the functionality that you want.

          • 2. Re: Convert Word RTF to PDF with ColdFusion
            BKBK Adobe Community Professional & MVP

            <!--- source:http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?cont ext=ColdFusion_Documentation&file=00001585.htm --->

             

             

             

            <cflock scope="Application" type="exclusive" timeout="120"

            >

             

             

            <cfif not StructKeyExists(application, "MyWordObj")

            >

             

            <!--- First try to connect to an existing Word object --->

             

             

            <cftry>

             

             

            <cfobject type=

            "com"

             

             

            action=

            "connect"

             

             

            class=

            "Word.application"

             

             

            name=

            "Application.MyWordobj"

             

             

            context="local">

             

             

            <cfcatch>

            <!--- There is no existing object, create one --->

             

             

            <cfobject type=

            "com"

             

             

            action=

            "Create"

             

             

            class=

            "Word.application"

             

             

            name=

            "Application.MyWordobj"

             

             

            context="local">

             

             

            </cfcatch>

             

             

            </cftry>

             

             

             

            <cfset Application.mywordobj.visible = False

            >

             

             

            </cfif>

             

             

            </cflock>

             

             

            <!--- Convert a Word document in temp.doc to an HTML file in temp.htm. --->

            <!--- Because this example uses a fixed filename, multiple pages might try

            to use the file simultaneously. The lock ensures that all actions from

            reading the input file through closing the output file are a single "atomic"

            operation, and the next page cannot access the file until the current page

            completes all processing.

            Use a named lock instead of the Application scope lock to reduce lock contention. --->

            <cflock

             

            name="WordObjLock" type="exclusive" timeout="120"

            >

             

             

            <cfset docs = application.mywordobj.documents()

            >

             

             

            <cfset docs.open("c:\ColdFusion8\wwwroot\RTFtoPDF\temp.rtf")

            >

             

             

            <cfset converteddoc = application.mywordobj.activedocument

            >

             

             

            <!--- Val(8) works with Word 2000. Use Val(10) for Word 97 --->

             

             

            <cfset converteddoc.saveas("c:\ColdFusion8\wwwroot\RTFtoPDF\temp.htm",val(8))

            >

             

             

            <cfset converteddoc.close()

            >

            </cflock>

            <!--- Read the HTML file --->

            <cffile

             

            action="read" file="#expandPath('temp.htm')#" variable="fileToConvert"

            >

            <!--- Convert from HTML to PDF--->

            <cfdocument

             

            overwrite="yes" filename="#expandPath('temp.pdf')#" format="PDF"><cfoutput>#fileToConvert#

            </cfoutput></cfdocument>

             

             

            <p>Conversion from temp.rtf to temp.pdf complete

            </p>

             

             

             

            • 3. Re: Convert Word RTF to PDF with ColdFusion
              Dinghus Level 1

              Thank you. My problem is that there is no Word on the server itself.

              Guess I will have to see what I can do about that.

              • 4. Re: Convert Word RTF to PDF with ColdFusion
                tooMuchTrouble Level 3

                the iText project is improvng this as we speak, cfsearching's got a good blog post on it: http://cfsearching.blogspot.com/2009/04/itext-preview-of-things-to-come-someday.html

                • 5. Re: Convert Word RTF to PDF with ColdFusion
                  BKBK Adobe Community Professional & MVP

                  Dinghus wrote:

                  Thank you. My problem is that there is no Word on the server itself.

                   

                  I don't think you require Word on the server. Just run the code and see.

                  • 6. Re: Convert Word RTF to PDF with ColdFusion
                    suaveodean

                    this works great!! thank you BKBK !

                    • 7. Re: Convert Word RTF to PDF with ColdFusion
                      BKBK Adobe Community Professional & MVP

                      OK, Suaveodean

                      • 8. Re: Convert Word RTF to PDF with ColdFusion
                        Dinghus Level 1

                        Kept meaning to get back to this one. You must have Word installed to use the Word object. The problem I'm having still is that Office has so many security issues that the security people won't install it on the new server so I have to stay with the old server. Maybe I will use this code tho to just convert it on the old server and move it to the new server.

                         

                        I got redirected to a different problem and am just now getting back to this one.

                        • 9. Re: Convert Word RTF to PDF with ColdFusion
                          Jochem van Dieten Level 4

                          But by now the answer is very different: install OpenOffice on a server with ColdFusion 9 and use the conversion capabilities of the new cfdocument tag.

                          • 10. Re: Convert Word RTF to PDF with ColdFusion
                            Dinghus Level 1

                            Yeh, that's the ticket. They just upgraded to 8 about a year ago and just getting everything running in 8 and now I'll walk in and say "Gotta go to 9. Please fork over a bunch of money for that"  And then there is the time to have it approved by the security gestapo and so on and so on.

                            At this point that is not an option.