Hi,

I am trying to create document using iText. I am using Eclipse IDE. I've imported the jar files (itextpdf-5.2.1.jar and itext-xtra-5.2.1.jar).

However RtfWriter2 is not being recognised as a class.

        Document doc = new Document();
        RtfWriter2 writer = new RtfWriter2();
        RtfWriter2.getInstance(doc,new FileOutputStream("testRTFdocument.rtf"));

Can someone help me in figuring out what I am missing. I am very new to iText.

Dani AI

Generated

RtfWriter2 is not part of the itextpdf 5.x core. iText split RTF/toolbox code out when it moved from the old com.lowagie packages to the newer com.itextpdf packages, so the RTF writer you are looking for lives in the older iText/itext-rtf artifacts rather than in itextpdf-5.x. (kb.itextpdf.com)

RtfWriter2 is provided by the iText RTF package (package name com.lowagie.text.rtf). If you want to keep using that API, add the itext-rtf artifact (the 2.x family) to your classpath or your build (Maven example shown below). Import the RTF class from its package, for example import com.lowagie.text.rtf.RtfWriter2;. (javadoc.io)

<!-- Maven dependency to get the RTF module (2.x series) -->
<dependency>
  <groupId>com.lowagie</groupId>
  <artifactId>itext-rtf</artifactId>
  <version>2.1.7</version>
</dependency>

Troubleshooting checklist for IDEs like Eclipse:

  • Ensure only the RTF-support jar (itext-rtf / iText 2.x) containing com.lowagie.text.rtf.RtfWriter2 is on the build path (no shadowing by other itext jars).
  • Avoid mixing iText 2.x (com.lowagie) and iText 5+ (com.itextpdf) jars in the same project — package/name changes cause compile/runtime confusion. Use mvn dependency:tree or check Project → Properties → Java Build Path to find duplicates. Also check your import statement. (kb.itextpdf.com)

Notes and alternatives: iText 2.x RTF support is legacy (not actively maintained) and iText 5+ changed license and packaging, so for new projects consider other approaches — Java’s built-in RTFEditorKit for simple RTF needs, or use headless LibreOffice for conversions if you need higher-fidelity RTF output or conversions from HTML/DOCX. (docs.oracle.com)

This explains why ’s import question was relevant and why ’s experiment of adding the older iText/RTF artifact resolved the “class not found” symptom; the long‑term recommendation is to pick a maintained toolchain for new work.

Recommended Answers

All 2 Replies

Why do you think it is a class? Is it in a package that needs to be imported?

iText2.0.1.jar file needs to added to the build path. It works now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.