public class Doc2PdfUtil {
private static Logger logger = LoggerFactory.getLogger(Doc2PdfUtil.class);
/**
* doc转pdf
* @param docPath doc文件路径,包含.doc
* @param pdfPath pdf文件路径,包含.pdf
* @return
*/
public static File doc2Pdf(String docPath, String pdfPath){
File pdfFile = new File(pdfPath);
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(pdfFile), SaveFormat.PDF);
} catch (Exception e) {
logger.info("****aspose doc转pdf异常");
e.printStackTrace();
}
return pdfFile;
}
public static void main(String[] args) {
File file = doc2Pdf("F:\\app\\请求URL加密.doc", "F:\\app\\请求URL加密.pdf");
System.out.println(file.getName());
}
}
1.我为什么会出现这个问题?
我是在上面的代码的主函数测试这个工具类,而这个方法需要读取本地电脑硬盘里的数据,然后就报了标题的这个错。
2.这个错大概的意思就是
警告:无法打开/创建prefs根节点软件\\javasoft \\prefs根节点0x800000002 (这里是百度翻译),但是里面的关键字就是说无法打开,那就代表着权限不够。
3.解决方案
Step1:搜索并运行regedit.exe
Step2: 进入HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft,右击JavaSoft目录,选择新建->项(key),命名为Prefs
Step3: 重新编译即可。