前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >aspose-words java word 转pdf

aspose-words java word 转pdf

作者头像
崔笑颜
发布2020-06-08 16:07:41
4.9K4
发布2020-06-08 16:07:41
举报

和谐版jar包 加激活 去除水印 转换从此无限制 就算是在服务器上也不需要安装其他工具 目前最好 使用 方便快捷 jar包下载地址 链接: https://pan.baidu.com/s/1tlbueAQq5bxPNgncS7GgoA 提取码: p35p

代码语言:javascript
复制
	/**
	 * word to pdf
	 * @param inPath  word 全路径
	 * @param outPath 生成的pdf 全路径
	 * @author an
	 * @throws Exception
	 */
	public static String docPdf(String inPath, String outPath)   {

		if (!isWordLicense()) {
			return null;
		}

		try {
			String path = outPath.substring(0, outPath.lastIndexOf(File.separator));
			File file = null;
			file = new File(path);
			if (!file.exists()) {//创建文件夹
				file.mkdirs();
			}
			file = new File(outPath);// 新建一个空白pdf文档
			FileOutputStream os = new FileOutputStream(file);
			Document doc = new Document(inPath); // Address是将要被转化的word文档
			doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
		} catch (Exception e) {
			e.printStackTrace();
		}
		// EPUB, XPS, SWF 相互转换
		return outPath;
	}


	/**
	 * @Description: 验证aspose.word组件是否授权:无授权的文件有水印和试用标记
	 */
	public static boolean isWordLicense() {
		boolean result = false;
		try {
			// InputStream inputStream = new
			// FileInputStream("D:\\Workspaces\\TestFilters\\lib\\license.xml");
			// 避免文件遗漏
			String licensexml = "<License>\n" + "<Data>\n" + "<Products>\n"
					+ "<Product>Aspose.Total for Java</Product>\n" + "<Product>Aspose.Words for Java</Product>\n"
					+ "</Products>\n" + "<EditionType>Enterprise</EditionType>\n"
					+ "<SubscriptionExpiry>20991231</SubscriptionExpiry>\n"
					+ "<LicenseExpiry>20991231</LicenseExpiry>\n"
					+ "<SerialNumber>23dcc79f-44ec-4a23-be3a-03c1632404e9</SerialNumber>\n" + "</Data>\n"
					+ "<Signature>\n"
					+ "sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=\n"
					+ "</Signature>\n" + "</License>";
			InputStream inputStream = new ByteArrayInputStream(licensexml.getBytes());
			com.aspose.words.License license = new com.aspose.words.License();
			license.setLicense(inputStream);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

// outputStream转inputStream
	public static ByteArrayInputStream parse(OutputStream out) throws Exception {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		baos = (ByteArrayOutputStream) out;
		ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
		return swapStream;
	}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档