• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error while using Rtfwriter by iText version 2.1.3

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}

}

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic