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

jsp 转PDF 问题 求解释

开发包 iText-2.0.8.jar ;core-renderer.jar;


import java.io.File;  
import java.io.FileOutputStream;  
import java.io.OutputStream;  

import org.xhtmlrenderer.pdf.ITextFontResolver;  
import org.xhtmlrenderer.pdf.ITextRenderer;  

import com.lowagie.text.pdf.BaseFont;  

 
public class Test {  
public static void main(String[] args) throws Exception {  
String inputFile = "test.html";  
  String url = new File(inputFile).toURI().toURL().toString();  
  String outputFile = "firstdoc.pdf";  
  OutputStream os = new FileOutputStream(outputFile);  
  ITextRenderer renderer = new ITextRenderer();  
  System.out.print(url);
  renderer.setDocument(url);  

  // 解决中文支持问题  
  ITextFontResolver fontResolver = renderer.getFontResolver();  
  fontResolver.addFont("C:/Windows/Fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  

  // 解决图片的相对路径问题  
  renderer.getSharedContext().setBaseURL("file:///D:/Documents and Settings/Administrator/Workspaces/train/hblqoa/WebRoot/image/");  
    
  renderer.layout();  
  renderer.createPDF(os);  
    
  os.close();  
}  
}  
 报错 能输出url ,url地址是对的,但是在set url的时候报错


url:file:///D:/apache-tomcat-6.0.20/apache-tomcat-6.0.20/webapps/testoa/SendDocument/selectSendDocument.html
错误:“White spaces are required between publicId and systemId.”
org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
at com.leadway.oa.util.Test.test2(Test.java:93)
at com.leadway.oa.util.Test.main(Test.java:42)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:720)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
... 6 more
Caused by: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:637)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
... 8 more

这是什么问题啊
 
 
--------------------编程问答-------------------- 刚才报错是先前的,我现在改了一下,现在报错是
url:file:/D:/Documents%20and%20Settings/Administrator/Workspaces/train/hblqoa/test.html
错误java.io.IOException: C:/Windows/Fonts/arialuni.ttf not found as file or resource.
at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFont.process(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFontUnicode.<init>(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:164)
at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:157)
at com.leadway.oa.util.Test.test2(Test.java:91)
at com.leadway.oa.util.Test.main(Test.java:43)


这是 C:/Windows/Fonts/arialuni.ttf  什么东东啊 --------------------编程问答-------------------- 应该是设置字体的吧。。。      --------------------编程问答-------------------- --------------------编程问答-------------------- .ttf什么文件啊 不能识别 --------------------编程问答-------------------- 白空格被要求publicId和systemId之间
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,