Reputation: 30895
How can I programmatically convert RTF documents to PDF?
Upvotes: 23
Views: 41415
Reputation: 7094
LibreOffice can convert RTF documents to PDF via command line.
Here are the instructions to install it on CentOS.
And this is an example to initiate conversion from PHP code:
<?php shell_exec('libreoffice4.2 --headless --invisible --norestore --convert-to pdf test.rtf'); ?>
Upvotes: 1
Reputation: 999
Four years late to the party here, but I use Ted in my web application. I generate RTF programmatically, then use the rtf2pdf.sh
script included in the package to generate the PDF. I tried OOo and unoconv previously, but Ted proved faster and more reliable in my application.
Upvotes: 3
Reputation: 66661
You have a number of options depending on:
Here are some options:
EDIT
Here is an older post that has some commonality with your question.
EDIT 2
I see from your comments that you are on Linux and open to either C++ or Java. Definitely use option 2.
JODConverter
(Java): the library takes care of spawning OpenOffice
in headless mode and talking Uno
to it on your behalf. You provide JODConverter
with an input and output file name as well as the input and output types (e.g. rtf and pdf), and when it returns to you the output file is ready.JODConverter
does (see the JODConverter
source code for how to do this.)
/opt/openoffice.org3/program/soffice.bin \
-accept=socket,host=127.0.0.1,port=8100;urp; \
-headless -nocrashreport -nodefault \
-nolockcheck -nologo -norestore
I am successfully using JODConverter
from a Java app to convert miscellaneous document types (some documents dynamically generated from templates) to pdf
.
Upvotes: 15
Reputation: 2670
PrimoPDF. It acts as a virtual printer, so you just print to it, and out pops a PDF.
Upvotes: 0
Reputation: 308031
OpenOffice.org can be run in server mode (i.e. without any GUI), can read RTF files and can output PDF files.
Upvotes: 18
Reputation: 15806
PDFCreator for windows is the easiest for single documents.
It's also possible to automate PDF creation for large sets of documents by converting them to XML and using XSLT and XSL-FO. There are lots of tutorials for this out there.
For a specific language, such as python, libraries exist to output to PDF fairly trivially.
The only advantage of XML over other simpler solutions is extensibility. You could also programmatically output your document in RTF, HTML, TXT, or just about any other text format.
Upvotes: 2
Reputation: 9489
Use PDFCreator, a free pdf printer. Just print to pdf. You can control this through COM. Example code is in the COM folder of the install directory.
Upvotes: 2