Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error while using Rtfwriter by iText version 2.1.3

 
srikanth Thandra
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,

I am working on a requirement of generating a RTF document using iText API. When i am using iText1.4.8 jar file there is no exception and RTF file is successfully generated.
But I got the following below exception when I am using iText 2.1.3 and iText-rtf-2.1.7 jar files. (because after iText-1.4.8.jar version, support of rtf is moved.)
Exception in thread "main" java.lang.NoSuchMethodError:
com.lowagie.text.Paragraph.getSpacingBefore()F
at com.lowagie.text.rtf.text.RtfParagraph.<init>(Unknown Source)
at com.lowagie.text.rtf.RtfMapper.mapElement(Unknown Source)
at com.lowagie.text.rtf.RtfWriter2.add(Unknown Source)
at com.lowagie.text.Document.add(Unknown Source)
at RTFHelloWorld.main(RTFHelloWorld.java:41)

I observed that RTF file is getting generated but with no content.

Can any body help me resolving the above issue?

the sample code is below

public class RTFHelloWorld {

static String outFile = "RtfHelloWorld1.rtf";
static String resultsPath = "results/rtf/intro/";
static String resourcePath = "resources/rtf/intro/";

/**
* @param args
*/
public static void main(String[] args) {
// create a document
Document document = new Document();

try {
// create a RTF Writer
RtfWriter2.getInstance(document, new FileOutputStream(resultsPath +outFile));

// Open the document for processing
document.open();

// add some text
document.add(new Paragraph("Hello World")); // the error is coming at this point when i am adding paragraph element to document.

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}

// close the document
document.close();
}

}

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, iText 2 still has support for RTF (as evidenced by the fact that the com.lowagie.text.rtf.text.RtfParagraph class still exists). That method was likely made obsolete and removed at some point.

Note that the release history (http://itextpdf.com/history.php) mentions big changes in RTF handling between iText 2.0 and iText 2.1. So you could try using iText 2.0.8 instead of 2.1.7 to see if that makes a difference.

Note: You should UseCodeTags when posting code of any length. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so. Also be sure to post any import statements - if those are missing, people are very unlikely to try and run that code for themselves.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That method was likely made obsolete and removed at some point.

I think it's the other way around. iText-rtf-2.1.7 is throwing the exception because it's missing the method in iText-2.1.4.

Srikanth, iText-2.1.7 is available as well. The two probably work best if they have the same version. Does the error disappear when you upgrade iText to 2.1.7? See http://sourceforge.net/projects/itext/files/ for all files, then check the 2.1.7 branch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic