Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
PdfWriter writer=  PdfWriter.getInstance(document, new leOutputStream(
HtmlParser.parse(document,"a.htm");

} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}

解决方案 »

  1.   

    mxm_1123,您能仔细的说一下么?我现在用ITEXT
    PdfWriter writer = PdfWriter.getInstance(document,
    new FileOutputStream("c:/Actions.pdf"));
    document.open();
    Paragraph paragraph = new Paragraph("Hello World ");
    document.close();
    这样只是把HelLo World这句话转成PDF了,怎么才能把一张HTML的页面导进来呢?
    或者用其他办法也可以,只要能把一个已有的HTML页面导进PDF就可以
      

  2.   

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {
    PdfWriter writer= PdfWriter.getInstance(document, new leOutputStream(
    HtmlParser.parse(document,"a.htm");
    /*
    读取本程序目录下的a.htm文件,可以换成网站的文件位置,如http://localhost:8080/a.htm*/
    } catch (DocumentException de) {
    System.err.println(de.getMessage());
    } catch (IOException ioe) {
    System.err.println(ioe.getMessage());
    }
    下面给你a.htm的文件内容,你可以试一下,可以的:
    <?xml version="1.0" encoding="GB2312"?>
    <html>
    <head>
    <title>
    Jsp3
    </title>
    </head>
    <body>
    <table border="1">
    <tr>
    <td>ProductName</td>
    <td>week1<br/>
            (20021104-20021108)</td>
    <td>week2<br/>
            (20021111-20021115)</td>
    <td>week3<br/>
            (20021118-20021122)</td>
    <td>week4<br/>
            (20021125-20021129)</td>
    <td>total</td>
    </tr>
    <tr>
    <td>one</td>
    <td>49.0</td>
    <td>40.0</td>
    <td>37.0</td>
    <td>26.0</td>
    <td>152.0</td>
    </tr>
    <tr>
    <td>two</td>
    <td>4.0</td>
    <td>7.0</td>
    <td>12.0</td>
    <td>4.0</td>
    <td>27.0</td>
    </tr>
    <tr>
    <td>three</td>
    <td>4.0</td>
    <td>2.0</td>
    <td/>
    <td> </td>
    <td>6.0</td>
    </tr>
    <tr>
    <td>four</td>
    <td>5.0</td>
    <td> </td>
    <td/>
    <td> </td>
    <td>5.0</td>
    </tr>
    <tr>
    <td>total</td>
    <td>435.0</td>
    <td>457.0</td>
    <td>460.0</td>
    <td>425.0</td>
    <td>1777.0</td>
    </tr>
    </table>
    </body>
    </html>
    但是要求html的格式要符合一定的范围,否则会报错,我也懂的不是太多,只能帮到这里了,
    而且这种转换好象对中文不支持,你可自己研究一下HtmlParser.parse
      

  3.   

    leOutputStream 
    好像没这个类啊~
      

  4.   

    手误,是:
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {
    PdfWriter writer=  PdfWriter.getInstance(document,
    new FileOutputStream("test.pdf"));
    HtmlParser.parse(document,"a.htm");
    /*
    读取本程序目录下的a.htm文件,可以换成网站的文件位置,如http://localhost:8080/a.htm*/
    } catch (DocumentException de) {
    System.err.println(de.getMessage());
    } catch (IOException ioe) {
    System.err.println(ioe.getMessage());
    }
      

  5.   

    终于搞掂了~谢谢你了mxm_1123
    非常感谢、
    那个中文的问题应该下个包就可以了
      

  6.   

    为什么我不行的呢!!!
     <script language=javascript>
    Document document   =   new   Document(PageSize.A4,   50,   50,   50,   50); 
    try   { 
    PdfWriter   writer=     PdfWriter.getInstance(document, new   FileOutputStream( "test.pdf ")); 
    HtmlParser.parse(document, "http://192.168.100.254/GT2/A.HTML"); 
    /* 
    读取本程序目录下的a.htm文件,可以换成网站的文件位置,如http://localhost:8080/a.htm */ 
    }   catch   (DocumentException   de)   { 
    System.err.println(de.getMessage()); 
    }   catch   (IOException   ioe)   { 
    System.err.println(ioe.getMessage()); 
    }
    </script>
      

  7.   

    line:2
    char:10
    error:Expected""
      

  8.   

    您把源码发到我邮箱里  我试试 [email protected]