Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert Word RTF to PDF with ColdFusion

Contributor ,
Apr 20, 2009 Apr 20, 2009

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?

TOPICS
Advanced techniques
6.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 23, 2009 Apr 23, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2009 Apr 25, 2009

<!--- source:http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 25, 2009 Apr 25, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2009 Apr 25, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2009 Sep 16, 2009

this works great!! thank you BKBK !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2009 Sep 16, 2009

OK, Suaveodean

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 16, 2010 Feb 16, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 16, 2010 Feb 16, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 16, 2010 Feb 16, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 25, 2009 Apr 25, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources