Discussion:
converting word files to PDF using Coldfusion 7?
(too old to reply)
bdee2
2009-03-26 18:27:12 UTC
Permalink
hi i was just wonderign if there was any easy way to use coldfusion 7 to convert word files to PDF on the server.
tech603
2009-03-28 21:58:17 UTC
Permalink
This link should help.

http://www.pdfonline.com/easypdf/sdk/samples/create/convert-word-to-pdf/coldfusi
on/coldfusion_createpdf.htm

Matthew Vass
QA Analyst
***@hostmysite.com
http://www.hostmysite.com?utm_source=bb
BKBK
2009-03-29 11:54:51 UTC
Permalink
There is a
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhel
p.htm?context=ColdFusion_Documentation&file=00001585.htm. You can then use the
cfdocument tag to convert the HTML to PDF.

That's just what I've done below. This is probably not the [i]easy way[/i] you
want, but it is a start.

To run it, place the file you wish to convert, say, temp.doc, in the web root.
The result will be temp.pdf.



<!---
source:http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/htm
l/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:\CFusionMX7\wwwroot\temp.doc")>
<cfset converteddoc = application.mywordobj.activedocument>
<!--- Val(8) works with Word 2000. Use Val(10) for Word 97 --->
<cfset converteddoc.saveas("c:\CFusionMX7\wwwroot\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.doc to temp.pdf complete</p>

Loading...