recently, I am doing a function, which involves converting word to pdf,. I am word to html and then to pdf. When html converts pdf, there are dozens of words of long text in html. In a span tag, the generated pdf text does not wrap, and it is useless for me to use css to force line breaks. It seems that itext only recognizes line breaks or manually enter. Excuse me, how to solve the problem of text wrapping?
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();