
- 30,738
- 21
- 105
- 131

- 29,839
- 85
- 272
- 514
-
What's your context? Are you trying to do this on the desktop (the PDFCreator options below are good ones there)? Are you trying to do this as part of a web app? Something else? Please edit your question to let us know. – acrosman Feb 25 '09 at 15:55
-
Are you on Windows or some other platform? Are you looking for a java solution, for a C/C++ solution, or is this indifferent? Will this be a server application (e.g. a web server) or a desktop application (multiple users will download and install it?) – vladr Feb 25 '09 at 16:03
-
server side on linux c++ or java – user63898 Feb 26 '09 at 08:11
-
Then there is no question about it: use OpenOffice + JODConverter, or OpenOffice with a direct C++ UNO interface (it's headless, does not require a DISPLAY.) I am using OpenOffice3 on Ubuntu - see my latest edit below. – vladr Feb 26 '09 at 18:52
-
See my answer [here](https://stackoverflow.com/a/58466239/4160283). – Digger Oct 19 '19 at 17:31
8 Answers
OpenOffice.org can be run in server mode (i.e. without any GUI), can read RTF files and can output PDF files.

- 302,674
- 57
- 556
- 614
-
This is cross-platform, but unsuitable for desktop applications. Very suitable for running behind a web-server, though. – vladr Feb 25 '09 at 16:02
-
That's true. Since I dabble mostly in server-side Java "cross-platform" is a lot more important for me than "suitable for a desktop app" ;-) – Joachim Sauer Feb 25 '09 at 16:24
-
1Would anyone update this post to give some guidelines on server-side setup/guidelines ? – BuZz Apr 29 '13 at 11:54
-
1Second this; finding information on how to do it on the LibreOffice wiki is proving problematic. – Vector Gorgoth Oct 16 '13 at 20:45
-
2Today I just tried Open-Office conversion using C# and let me tell you, this works "good" but not perfect. meaning, some alignments gets messed in the process and for commercial this won't do, unless you're looking to do this with very simple docs, don't waste your time on it. – Stavm May 11 '15 at 12:06
-
LibreOffice has some extremely nasty issues with how it parses RTFs. Most of them have existed for years (or were fixed and then reintroduced), and nobody at the .org seems to really consider it a priority. Would suggest avoiding that particular solution if possible. – Vector Gorgoth Oct 27 '16 at 16:29
You have a number of options depending on:
- the platform(s) your application will be running on
- whether your application will be a server application (e.g. a web service that you set up once and then it runs), or a widely-available desktop application (e.g. something that must be easily downloadable and installable by many people)
- whether you are willing to put little or more programming effort into getting the solution to work
- whether you are flexible as to the programming language you will use
Here are some options:
- PDFCreator + COM
- Windows only
- suitable for both desktop and server applications
- medium programming effort
- any language that allows you to speak COM
- OpenOffice ( + JODConverter - optional )
- Cross-platform (Windows, Linux, etc.)
- suitable for server applications, as OpenOffice is a 100MB+ download
- low programming effort
- Java (if using JODConverter), or any language that can interface with OpenOffice's UNO
- IText + Apache POI
- Cross-platform (Windows, Linux, etc.)
- suitable for both desktop and server applications
- high programming effort
- Java
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 spawningOpenOffice
in headless mode and talkingUno
to it on your behalf. You provideJODConverter
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.- C++: you can fork+exec one (or more, for load balancing) OpenOffice instances in headless mode (soffice will listen for UNO requests on a socket e.g. port 8100.) From your application use Uno/CPP to instruct OpenOffice to perform the conversion the same way
JODConverter
does (see theJODConverter
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
.
-
how to i combine iText with poi to convert existent rtf ( with text allready inside with design ) – user63898 Feb 26 '09 at 08:14
-
You may want to ask a new question specific to combining the two. As I said, programming effort is high. I know that it has been done, see chsrinivas123's post on http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Q_23023116.html. – vladr Feb 26 '09 at 18:39
-
iText does not support RTF directly, it is first required to convert your document to HTML\XHTML, which basically means, another layer that will most likely not show exactly as the original RTF, just tried it, wasn't satisfied, still looking. – Stavm May 11 '15 at 12:08
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.

- 1,009
- 1
- 9
- 8
-
1I see that Ted has no option for hiding the hidden text of RTF file, in the converted PDF file. – shasi kanth Apr 02 '14 at 12:32
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.

- 9,316
- 5
- 48
- 67
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.

- 15,480
- 6
- 37
- 47
-
This will, of course, only work on Windows. Unfortunately it has not yet been made clear what platform the solution is required for. – vladr Feb 25 '09 at 21:35
-
naturally. Although the XSLT solution will work for just about any platform. – Jon W Feb 25 '09 at 21:35
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'); ?>

- 6,987
- 24
- 106
- 158
-
Out of all the options I checked this option about 2 months ago, and it is probably the worst for me, it totally misinterpreted the RTF structure and I can't say i recommend it to do even small and simple docs. let alone commercial use. do not fall for the 'command line' option, you'll get better results with Open Office although it requires more code on your part. – Stavm May 11 '15 at 12:12
PrimoPDF. It acts as a virtual printer, so you just print to it, and out pops a PDF.

- 2,620
- 1
- 22
- 24