简单粗暴,java pdf转word,word转图片,无水印,无大小限制

网上java word转pdf比较少,要么就是要一大把积分让你下载,不借助外部软件就是这个最简单,还有一个 Spire.Doc free版(class被加密,转pdf限制3页)
把word转为pdf分为几步?

第一步,下载jar包,引入 ,jar包下载地址:https://www.lanzous.com/i7zk9kb
第二部,贴上我下面这段代码

//引入  import java.io.*;
//引入  import com.aspose.words.*; 
public static void wordToPdf(String docPath,String savePath){

		try {
			String s = "<License>"
						+ "<Data>"
							+ "<Products>"
								+ "<Product>Aspose.Total for Java</Product>"
								+ "<Product>Aspose.Words for Java</Product>"
							+ "</Products>"
							+ "<EditionType>Enterprise</EditionType>"
							+ "<SubscriptionExpiry>20991231</SubscriptionExpiry>"
							+ "<LicenseExpiry>20991231</LicenseExpiry>"
							+ "<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>"
						+ "</Data>"
					+ "<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>"
					+ "</License>";
			ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
			License license = new License();
			license.setLicense(is);
			com.aspose.words.Document document = new com.aspose.words.Document(docPath);
			document.save(new FileOutputStream(new File(savePath)),SaveFormat.PDF);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) throws Exception{
		wordToPdf("C:\\Users\\Administrator\\Desktop\\aaa.docx","C:\\Users\\Administrator\\Desktop\\ddd.pdf");
	}

把word转图片分为几步?
第一步,下载jar包,引入 ,jar包下载地址:https://www.lanzous.com/i7zk9kb
第二部,贴上我下面这段代码

/**
	 *  文档转图片
	 * @param inPath 传入文档地址
	 * @param outDir 输出的图片文件夹地址
	 */
	public static void doc2Img(String inPath, String outDir){
		try {
			String s = "<License>"
					+ "<Data>"
					+ "<Products>"
					+ "<Product>Aspose.Total for Java</Product>"
					+ "<Product>Aspose.Words for Java</Product>"
					+ "</Products>"
					+ "<EditionType>Enterprise</EditionType>"
					+ "<SubscriptionExpiry>20991231</SubscriptionExpiry>"
					+ "<LicenseExpiry>20991231</LicenseExpiry>"
					+ "<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>"
					+ "</Data>"
					+ "<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>"
					+ "</License>";
			ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
			License license = new License();
			license.setLicense(is);
			com.aspose.words.Document doc = new com.aspose.words.Document(inPath);
			// 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换
			ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
			int pageCount = doc.getPageCount();
			for (int i = 0; i < pageCount; i++) {
				File file = new File(outDir+"/"+i+".JPEG");
				FileOutputStream os = new FileOutputStream(file);
				options.setPageIndex(i);
				doc.save(os, options);
				os.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

注:仅支持个人学习,商业用途请选择正版

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值