当前位置:编程学习 > JAVA >>

请教iText生成word问题

使用iText生成word,struts2框架,使用iText-2.1.7.jar和iText-rtf-2.1.7.jar
import java.io.*;
import java.awt.Color;
import com.lowagie.text.*;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.headerfooter.*;
import com.lowagie.text.rtf.field.*;
import com.lowagie.text.rtf.table.*;
import com.lowagie.text.rtf.style.RtfFont;

public class RtfClass {
    public static String rtf()
    {
        com.lowagie.text.Document document = new com.lowagie.text.Document();
        try {System.out.println("try1");
            RtfWriter2.getInstance(document, new
FileOutputStream("C:\rhDocs\testRTFdocument.rtf"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        document.open();
        try {System.out.println("try2");
            document.add(new Paragraph("Hello World!"));
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        document.close();
        return "ok";
    }

}
错误如下:
java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width()F
    at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(Unknown Source)
    at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(Unknown Source)
    at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(Unknown Source)
    at com.lowagie.text.rtf.RtfWriter2.setPageSize(Unknown Source)
    at com.lowagie.text.Document.open(Unknown Source)
    at utilities.RtfClass.rtf(RtfClass.java:23)
--------------------编程问答-------------------- RtfClass.java:23是什么?
是不是itext版本的问题。。。 --------------------编程问答-------------------- 在main函数里执行没问题,放到项目里就出问题了,itext版本应该没问题
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,