首页 > 其他 > 详细

让Flying saucer支持font定义

时间:2016-11-25 23:20:02      阅读:302      评论:0      收藏:0      [点我收藏+]

在wangEditor里给某段字体加上颜色后,在生成的PDF里无法体现出来,只好打开flying saucer的源码debug,发现XhtmlNamespaceHandler类中没有对font元素的处理,于是依样画瓢:


public String getNonCssStyling(Element e) {

    if (e.getNodeName().equals("table")) {

        return applyTableStyles(e);            

    } else if (e.getNodeName().equals("td") || e.getNodeName().equals("th")) {

        return applyTableCellStyles(e);

    } else if (e.getNodeName().equals("tr")) {

        return applyTableRowStyles(e);

    } else if (e.getNodeName().equals("img")) {

        return applyImgStyles(e);

    } else if (e.getNodeName().equals("p") || e.getNodeName().equals("div")) {

        return applyBlockAlign(e);

    }else if(e.getNodeName().equalsIgnoreCase("font")){

        return applyFontStyle(e);

    }

    return "";

}


然后加上下面的方法:


private String applyFontStyle(Element e) {

        StringBuffer style = new StringBuffer();

        String s;

        s = getAttribute(e, "color");

        if (s != null) {

            s = s.toLowerCase().trim();

            style.append("color: ");

            style.append(s);

            style.append(";");

        }

        s = getAttribute(e, "size");

        if (s != null) {

            s = s.toLowerCase().trim();

            if(!s.endsWith("px")){

                s = s + "px";

            }

            style.append("font-size: ");

            style.append(s);

            style.append(";");

        }

        return style.toString();

    }


让Flying saucer支持font定义

原文:http://www.cnblogs.com/xiuquan/p/6103167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!