一、Aspose是什么?
是一个商业.NET类库,可以使得应用程序处理大量的文件任务。支持Doc,Docx,RTF,HTML,OpenDocument,PDF,XPS,EPUB和其他格式。使用可以在不使用的情况下生成、修改、转换和打印文档。在项目中使用
可以运行在Windows,Linux和Mac OS操作系统上面
虽然aspose的jar包是收费的,但是网上能搜到很多破解版的,去掉了页眉和水印 之类的限制
在项目中的使用就是将html标签转换为了docx文档,然后在写到输出流从浏览器中下载
部分代码:
String fileName =new String(getFileName(docId).getBytes("GB2312"), "ISO_8859_1") +".docx";
Document document = null;
String filePath = ().getResource("/").getPath()+"/"+getFileName(docId)+".docx";
XWPFDocument docx = null;
try {
if (!getLicense()) {
return;
}
document = new Document();
DocumentBuilder build = new DocumentBuilder(document);
(html);
(filePath);
docx = new XWPFDocument(new FileInputStream(filePath));
} catch (Exception e) {
();
}
outputStream = ();
();
("Content-disposition", "attachment; filename="+fileName);
("application/msword");
("GB2312");
(outputStream);
-----------------------------------------------------------------------------
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = ().getResourceAsStream("");
License aposeLic = new License();
(is);
result = true;
} catch (Exception e) {
();
}
return result;
}
其中是放在src目录下的