?
Solved

Converting RTF stored in a Database to PDF using CFDOCUMENT in Coldfusion

Posted on 2011-10-11
11
Medium Priority
?
872 Views
Last Modified: 2012-05-12
We have a database field that stores raw RTF information.  I would like to display the RTF on the screen in PDF format using <cfdocument> (actually write it to a PDF file, but if the display is right that part is automatic).  An acceptable answer would be converting the RTF to html and then having the cfdocument display it as a PDF.  I searched the knowledge base here and there doesn't seem to be exactly what we are looking for.  In a nutshell we have this:

{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fnil\fcharset0 Microsoft Sans Serif;}}  \viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\b\f0\fs22 This is a test \par  \pard\ltrpar\fi-360\li720\sa200\sl276\slmult1\b0\f1\'b7\tab\b\f0 Guy \b0 went to the \ul store\ulnone\b\par  \b0\f1\'b7\tab\b\f0 She\b0  went with him\b\par  \b0\f1\'b7\tab\f0 We all win\b\par  \pard\ltrpar\f2\fs17\par  }  

And want to display it using CFDOCUMENT as this:

This is a test
•      Guy went to the store
•      She went with him
•      We all win
 
I tried setting the mimetype to RTF, but we still get the RTF codes displayed.

Thanks!
0
Comment
Question by:dfins
  • 6
  • 3
  • 2
11 Comments
 
LVL 13

Accepted Solution

by:
srikanthmadishetti earned 2000 total points
ID: 36951114
0
 
LVL 1

Author Comment

by:dfins
ID: 36951245
We are not working with MS Word or Word files.  The RTF content is stored in a database and will be returned using a stored procedure.
0
 
LVL 13

Expert Comment

by:srikanthmadishetti
ID: 36951387
@dfins

Write the content to a rtf file after reading from database using cffile and then
 use the path of file in this statement
<cfset docs.open("c:\ColdFusion8\wwwroot\RTFtoPDF\temp.rtf")
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 1

Author Comment

by:dfins
ID: 36951442
We do not want to use files.  If that is the only solution, then we will have to figure something else out.  But I would like to leave this open to see if there is a direct route to the question I asked.  Thanks for the help.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36951635
> doesn't seem to be exactly what we are looking for

How so? Can you elaborate on any restrictions or things you're trying to avoid?

Also what's your CF version?
0
 
LVL 1

Author Comment

by:dfins
ID: 36951666
Well, this will be run in rapid succession, there would hopefully be no need to deal with temp files.  Is the description above not clear enough?  Let me know if you need more information.  Basically a stored procedure grabs RTF raw data and I would like to pass that to cfdocument if possible.

We already knew we could read and change files, we just want to create a PDF from the RTF data stored in the DB as our question asks.

We are using CF9.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36951966
(no points...)

No it was clear. I just wasn't sure if "temp files" was your main objection.

> Basically a stored procedure grabs RTF raw data and I would like to pass that
> to cfdocument if possible.

Honestly there isn't a great answer to this one.  As you probably figured out , it's not possible - even with CF9.  It only supports word => pdf and it's not fast.  

> An acceptable answer would be converting the RTF to html and then
> having the cfdocument display it as a PDF

Using a library to convert rtf to html then feed it into cfdocument isn't hard. But the quality varies greatly... which may be a deal breaker.  If you have lots of special formatting, you may be better off skipping cfdocument altogether and using 3rd party tool that converts rtf directly to pdf.  I can't recommend anything on personal experience, but there's several tools mentioned in the archives.

0
 
LVL 1

Author Comment

by:dfins
ID: 36951992
I was afraid of that, but thank you so much for your help.  I'm not sure how to award points anyway, so I will accept the earlier solution which may work for someone else searching for the answer.
0
 
LVL 1

Author Closing Comment

by:dfins
ID: 36952005
This will work for someone else converting files.  The information back and forth might help someone.  Only selected partially because there is no real answer, CF just does not have that option at this time.
0
 
LVL 1

Author Comment

by:dfins
ID: 36952038
I did not realize the username had changed!  I apologize.  Thanks for your help again though.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36952113
(not about points...)

> Only selected partially because there is no real answer,
> CF just does not have that option at this time.

Just FYI, in terms of EE, that is a valid answer.  Unfortunately, sometimes the right answer is - "you can't" ;-) I too am disappointed CF doesn't support it though.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question