最近在做一个功能,其中有一部分涉及到word转pdf,我是word转成html 之后 再转成pdf的,在html转换pdf的时候,html里面的长文本几十个字那种,在一个span标签里面,生成的pdf 这文字他不换行,我用css强制换行也没用,貌似itext只识别换行标签或者手动回车。 请问这个怎么解决一下 文字换行问题呢?
File f = new File(targetHtml);
org.jsoup.nodes.Document doc = Jsoup.parse(f, "UTF-8");
doc.select("meta").removeAttr("name");
doc.select("meta").attr("content", "text/html; charset=UTF-8");
doc.select("meta").attr("http-equiv", "Content-Type");
doc.select("meta").html(" ");
doc.select("img").html(" ");
doc.select("style").attr("mce_bogus", "1");
doc.select("style").html(".divcss5{word-wrap:break-word} ");
doc.select("body").attr("style", "font-family:'SimSun'");
doc.select("span").attr("style", "font-family:'SimSun'");
doc.select("div").attr("style", "width:30%;");
doc.select("div").attr("class", "divcss5");
doc.select("br").append(" ");
doc.select("a").append(" ");
doc.select("html").before("<?xml version='1.0' encoding='UTF-8'>");
/*
* Jsoup只是解析,不能保存修改,所以要在这里保存修改。
*/
FileOutputStream fos = new FileOutputStream(f, false);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
osw.write(doc.html());
System.out.println(doc.html());
osw.close();