Bootstrap

POI实现Word文件转PDF

需求:采用spire.doc生成word文件后,需要加一个预览PDF的功能,可以直接采用POI对docx文件进行转换处理

	public static void main(String[] args) throws Exception {
		String in = "D:\\testpdf.docx";
		FileInputStream inputStream = new FileInputStream(in);
		XWPFDocument document = new XWPFDocument(inputStream);
		
		String out = "D:\\out.pdf";
		FileOutputStream outputStream = new FileOutputStream(out);
		PdfOptions pdfOptions = PdfOptions.create();
		PdfConverter.getInstance().convert(document, outputStream, pdfOptions);
		
	}

 

;