通过java swing将html转换为java中的html到word doc并没有太大帮助,所以寻找开源库
通过查看标题,您只需要从HTML页面获取RTF。因此,您可以使用PD4ML库。首先将此添加到您的pom
<dependency>
<groupId>com.pd4ml</groupId>
<artifactId>pd4ml</artifactId>
<version>4.0.2</version>
</dependency>
例
public class Converter {
protected Dimension format = PD4Constants.A4;
protected boolean landscapeValue = false;
protected int topValue = 10;
protected int leftValue = 10;
protected int rightValue = 10;
protected int bottomValue = 10;
protected String unitsValue = "mm";
protected String proxyHost = "";
protected int proxyPort = 0;
protected int userSpaceWidth = 780;
private void runConverter(String urlstring, File output) throws IOException {
if (urlstring.length() > 0) {
if (!urlstring.startsWith("http://") && !urlstring.startsWith("file:")) {
urlstring = "http://" + urlstring;
}
java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
if (proxyHost != null && proxyHost.length() != 0 && proxyPort != 0) {
System.getProperties().setProperty("proxySet", "true");
System.getProperties().setProperty("proxyHost", proxyHost);
System.getProperties().setProperty("proxyPort", "" + proxyPort);
}
PD4ML pd4ml = new PD4ML();
try {
pd4ml.setPageSize(landscapeValue ? pd4ml.changePageOrientation(format) : format);
} catch (Exception e) {
e.printStackTrace();
}
if (unitsValue.equals("mm")) {
pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
} else {
pd4ml.setPageInsets(new Insets(topValue, leftValue, bottomValue, rightValue));
}
pd4ml.setHtmlWidth(userSpaceWidth);
pd4ml.render(urlstring, fos);
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。