jQuery in Action, 2nd edition*
The moose likes I/O and Streams and the fly likes error while using Rtfwriter by iText version 2.1.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "error while using Rtfwriter by iText version 2.1.3" Watch "error while using Rtfwriter by iText version 2.1.3" New topic
Author

error while using Rtfwriter by iText version 2.1.3

srikanth Thandra
Ranch Hand

Joined: Mar 04, 2009
Posts: 42
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();
}

}


Thanx in advance,
Srikanth
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42612
    
  65
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.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: error while using Rtfwriter by iText version 2.1.3