我想用的servelt 我使用的飛碟,用來從網站的網址 PDF生成的URL PDF和我的代碼是不產生從HTTP網站的網址PDF
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package abc;
import com.lowagie.text.DocumentException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class TestPdf {
public static void main(String args[]) throws MalformedURLException
{
String File_To_Convert = "test.htm";
//String url = new File(File_To_Convert).toURI().toURL().toString();
URL testurl=new URL("http://www.ipillion.com/");
String url=testurl.toString();
System.out.println(""+url);
String HTML_TO_PDF = "d:\\ConvertedFile.pdf";
OutputStream os;
try {
os = new FileOutputStream(HTML_TO_PDF);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}catch(Exception e)
{
e.printStackTrace();
}
}}
我一直在使用不同的網站試過,但每次它拋出異常 爲如
run:
http://www.ipillion.com/
ERROR: 'The element type "SCRIPT" must be terminated by the matching end-tag "</SCRIPT>".'
org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 71; The element type "SCRIPT" must be terminated by the matching end-tag "</SCRIPT>".
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 abc.TestPdf.main(TestPdf.java:33)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 71; The element type "SCRIPT" must be terminated by the matching end-tag "</SCRIPT>".
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:723)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:317)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
... 5 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 71; The element type "SCRIPT" must be terminated by the matching end-tag "</SCRIPT>".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:640)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:711)
... 7 more
BUILD SUCCESSFUL (total time: 9 seconds)
那麼需要做什麼? – user1047873 2012-01-08 15:44:52