毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

html生成PDF显示不全

更新时间:2014-11-13:  来源:毕业论文

java代码


StringBuffer buf = new StringBuffer();
    buf.append("<?xml   version='1.0'   encoding='gb2312'?> <html>");
    // put in some style
    buf.append("<head><style language='text/css'>");
    buf.append("body{font:12px/1.8 '宋体';position:relative;}"
+" html,body{height:100%;overflow-y:hidden;margin:0;padding:0;}"
+" .strt-wrap{width:100000px;margin:10px;cursor:move;}"
+" .strt-part{text-align:center;float:left;position:relative;}"
+" .strt-part .line-v{position:relative;height:40px;width:100%;}"
+" .strt-part .line-v span{display:block;background:#ccc;position:absolute;top:0;font-size:0;line-height:1px;width:1px;height:40px;left:50%;}"
+" .strt-name{display:inline-block;padding:0 5px;height:24px;line-height:24px;border:1px solid #ccc;margin:0 10px;border-radius:3px;background:#f8f8f8;}"
+" .strt-part .line-h{height:1px;display:block;background:#ccc;position:absolute;top:0;font-size:0;}"
+" .strt-part .line-h-l{width:50%;left:0;}"
+" .strt-part .line-h-c{width:100%;left:0;}"
+" .strt-part .line-h-r{width:50%;right:0;}"
+" .strt-block{float:left;}</style></head>");
   
    // generate the body
    buf.append("<body>");
    buf.append(str);
//    for(int i=99; i>0; i--) {
//        buf.append("<h3>"+i+" 哈哈bottles of beer on the wall, "
//                + i + " bottles of beer!</h3>");
//        buf.append("<p>Take one down and pass it around, "
//                + (i-1) + " bottles of beer on the wall</p>\n");
//    }
//    buf.append("<h2>No asdesa阿斯顿 of beer on the wall, no more bottles of beer. ");
//    buf.append("Go to the store and buy some more, 99 bottles of beer on the wall.</h2>");
    buf.append("</body>");
    buf.append("</html>");
    System.out.println("htmlString"+buf.toString());
    // parse the markup into an xml Document
    DocumentBuilder builder = null;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    Document doc = null;
try {
doc = builder.parse(new StringBufferInputStream(buf.toString()));
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(doc, null);

    String outputFile = "e://100bottles.pdf";
    OutputStream os = null;
try {
os = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    renderer.layout();
    try {
renderer.createPDF(os);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

html,body{height:100%;overflow-y:hidden;

看到没?超过100%被隐藏了。 去掉那些css就可以了。

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。