我正在尝试从 HTML 内容创建 PDF。为此,我使用itextpdf-5.3.0.jar,这是一个基于 Java(使用 Struts 2)的 Web 项目。我收到以下错误,我不知道如何解决。请帮我。
<%@page import="com.sun.org.apache.bcel.internal.generic.ArrayType"%>
<%@page import="com.sun.xml.internal.ws.api.message.Message"%>
<%@page import="com.sun.xml.internal.fastinfoset.util.StringArray"%>
<%@
page import="javax.servlet.*,
javax.servlet.http.*,
java.io.*,
java.util.*,
com.itextpdf.awt.*,
com.itextpdf.text.*,com.itextpdf.text.pdf.*,com.itextpdf.text.html.simpleparser.HTMLWorker,
com.itextpdf.tool.xml.XMLWorkerHelper,
com.itextpdf.tool.xml.XMLWorker,
com.itextpdf.tool.xml.XMLWorkerHelper,
com.itextpdf.tool.xml.html.Tags,
com.itextpdf.tool.xml.parser.XMLParser
,com.itextpdf.tool.xml.pipeline.css.CSSResolver
,com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline
,com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline
,com.itextpdf.tool.xml.pipeline.html.AbstractImageProvider
,com.itextpdf.tool.xml.pipeline.html.HtmlPipeline
,com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext
,com.itextpdf.tool.xml.pipeline.html.LinkProvider"
%>
<SCRIPT type="text/javascript">
alert("Welcome 2 allTest.jsp");
</script>
<%
response.setContentType("application/pdf");
Document document = new Document(PageSize.A4, 40, 40, 30, 30);
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ByteArrayOutputStream ms=new ByteArrayOutputStream();
PdfWriter pdfWriter = PdfWriter.getInstance(document,response.getOutputStream());
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
String pdfCon = request.getParameter("pdfCon");
String [] tokens = pdfCon.split("---");
for(int i=0; i < (tokens.length); i++) {
try{
htmlWorker.parse(new StringReader(tokens[i]));
}catch(Exception e)
{
System.out.println("Exception: "+e);
}
document.newPage();
}
document.close();
}
%>
我收到了这个错误:
ExceptionConverter: java.net.ConnectException: Connection refused: connect
ExceptionConverter: com.itextpdf.text.DocumentException: java.lang.ClassCastException: com.itextpdf.text.html.simpleparser.TableWrapper cannot
be cast to com.itextpdf.text.Meta