Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的com.itextpdf.tool.xml.exceptions.RuntimeWorkerException_Java_Jsp - Fatal编程技术网

Java中的com.itextpdf.tool.xml.exceptions.RuntimeWorkerException

Java中的com.itextpdf.tool.xml.exceptions.RuntimeWorkerException,java,jsp,Java,Jsp,这是我将HTML转换为Pdf的代码,用于静态和小内容HTML,它工作正常,但用于动态和长内容HTML,它是com.itextpdf.tool.xml.exceptions.RuntimeWorkerException此例外请帮助我哪里做错了。问题是您的HTML无效 尝试使用类转换它破坏它的长html代码是什么?很可能你有无效的html…我正在从其Url重编内容当我设置为静态时它不工作,如给定示例它工作,但对于此html它不工作请检查问题是你有无效的html。尝试使用HTMLWorker类转换它。

这是我将HTML转换为Pdf的代码,用于静态和小内容HTML,它工作正常,但用于动态和长内容HTML,它是com.itextpdf.tool.xml.exceptions.RuntimeWorkerException此例外请帮助我哪里做错了。

问题是您的HTML无效


尝试使用类转换它

破坏它的长html代码是什么?很可能你有无效的html…我正在从其Url重编内容当我设置为静态时它不工作,如给定示例它工作,但对于此html它不工作请检查问题是你有无效的html。尝试使用HTMLWorker类转换它。你能不能请与我的代码整合,这样我就可以点击按钮并将其下载另存为Pdf请检查此项在你的jsp代码下面添加此项:文件f=new FileC:\\Test.Pdf;response.addHeaderContent-Disposition,附件;文件名=\Test.pdf\;InputStream InputStream=新文件InputStreamF;BufferedOutputStream输出=新建BufferedOutputStreamresponse.getOutputStream;byte by[]=新字节[32768];整数指数;如果输入流!=null{index=inputStream.readby,0,32768;}否则{index=-1;}而索引!=-1{output.writeby,0,index;index=inputStream.readby,0,32768;}output.flush;
public class GeneratePDF {
public static void main(String[] args) {
    try {
        String k = "<html><body> This is my Project </body></html>";
        OutputStream file = new FileOutputStream(new File("E:\\Test11.pdf"));
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();
        InputStream is = new ByteArrayInputStream(k.getBytes());
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
        document.close();
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}