通过国内国外,官网不断查找,终于找到适合java的开发的方式,不管国内国外,全是C++和vb .net的资料,为了让自己以后不会忘记,迭代更新一下Aspose的多样性操作。
普通的:
File file = new File("C:\\Users\\a\\Downloads\\test.doc");
Document doc = new Document(file .getPath());
doc.save("C:\\Users\\a\\Downloads\\test.pdf", SaveFormat.PDF);
宽度自适应:
如果word是横向的内容,普通的方法,文件宽度不够,会导致转换出来的pdf被截取掉,需要增加一下宽度的自适应。
Document doc = new Document(wordFile.getPath());
NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
for (Table table : (Iterable<Table>) tables) {
double tableWidth = 0;
double tableHeight = 0;
Section section = (Section) table.getAncestor(NodeType.SECTION);
for (Row row : table.getRows()) {
double rowWidth = 0;