java xmlworker pdf_java-使用itext的XML worker

import java.io.FileOutputStream;

import java.io.StringReader;

import com.itextpdf.text.Document;

import com.itextpdf.text.PageSize;

import com.itextpdf.text.pdf.PdfWriter;

import com.itextpdf.tool.xml.XMLWorkerHelper;

public class HtmlToPDF2 {

// itextpdf-5.4.1.jar http://sourceforge.net/projects/itext/files/iText/

// xmlworker-5.4.1.jar http://sourceforge.net/projects/xmlworker/files/

public static void main(String[] args ) {

try {

Document document = new Document(PageSize.LETTER);

PdfWriter pdfWriter = PdfWriter.getInstance

(document, new FileOutputStream("C:/Users/Jason/Desktop/testpdf.pdf"));

document.open();

document.addAuthor("Real Gagnon");

document.addCreator("Real's HowTo");

document.addSubject("Thanks for your support");

document.addCreationDate();

document.addTitle("Please read this");

XMLWorkerHelper worker = XMLWorkerHelper.getInstance();

String str = "

"+

"Real's HowTo" +

"

Show your support

" +

"

It DOES cost a lot to produce this site - in ISP storage and transfer fees, " +

"in personal hardware and software costs to set up test environments, and above all," +

"the huge amounts of time it takes for one person to design and write the actual content.

" +

"

If you feel that effort has been useful to you, perhaps you will consider giving something back?

" +

"

Donate using PayPal? to real@rgagnon.com.

" +

"

Contributions via PayPal are accepted in any amount

" +

"

Java HowTo

"

Javascript HowTo" +

"

Powerbuilder HowTo" +

"";

worker.parseXHtml(pdfWriter, document, new StringReader(str));

document.close();

System.out.println("Done.");

}

catch (Exception e) {

e.printStackTrace();

}

}

}

这是我在网上找到的示例代码.当我尝试执行它时,出现此错误:

Exception in thread "main" java.lang.NoSuchMethodError: com.itextpdf.text.Paragraph.trim()Z

at com.itextpdf.tool.xml.html.AbstractTagProcessor.currentContentToParagraph(AbstractTagProcessor.java:257)

at com.itextpdf.tool.xml.html.Header.end(Header.java:93)

at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:189)

at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:206)

at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:141)

at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:395)

at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)

at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:235)

at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:213)

at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:175)

at xml.HtmlToPDF2.main(HtmlToPDF2.java:41)

我正在使用itextpdf-5.1.2.jar和xmlworker-5.4.3.jar.请帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值