我很无聊因为我试图用XHTMLWorker将html文本转换为pdf而且它失败了!
这是我的代码:
File tempDocPdf;
com.itextpdf.text.Document docItext;
// crée un pdf vide
docItext = new com.itextpdf.text.Document(PageSize.A4);
// crée le fichier en mémoire
tempDocPdf = new File("c:/temp/",docDTO.getNomDocument() + ".pdf");
docDTO.setNomPdf(docDTO.getNomDocument() + ".pdf");
PdfWriter writer = PdfWriter.getInstance(docItext, new FileOutputStream(tempDocPdf));
docItext.addTitle(docDTO.getNomDocument());
// permet de spécifier si les contrôles de navigation sont affichés
writer.setViewerPreferences(PdfWriter.HideWindowUI);
// ouverture du document pdf (pret à enregistrer des données)
docItext.open();
StringReader str = new StringReader("<b>Test XmlWorker</b>");
System.out.println("test 0");
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
System.out.println("test 10");
worker.parseXHtml(writer, docItext, str);
System.out.println("test 20");
// crée le pdf
docItext.close();
System.out.println("test 30");
//enregistrer dans le document:
buildDocNotes(tempDocPdf);
//suppression du fichier temporaire
tempDocPdf.delete();
我有这个例外:
DETAIL : java.security.AccessControlException: Access denied (java.lang.RuntimePermission getenv.windir)
at java.security.AccessController.throwACE(AccessController.java:100)
at java.security.AccessController.checkPermission(AccessController.java:174)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:544)
at java.lang.System.getenv(System.java:322)
at com.itextpdf.text.FontFactoryImp.registerDirectories(FontFactoryImp.java:573)
at com.itextpdf.tool.xml.XMLWorkerFontProvider.<init>(XMLWorkerFontProvider.java:71)
at com.itextpdf.tool.xml.XMLWorkerFontProvider.<init>(XMLWorkerFontProvider.java:62)
at com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext.<init>(HtmlPipelineContext.java:111)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:166)
at com.pasquier.DAO.sauvLocal.PdfSauvLocalDAO.creerPdf(PdfSauvLocalDAO.java:219)
at com.pasquier.DAO.sauvLocal.PdfSauvLocalDAO.detacher(PdfSauvLocalDAO.java:73)
at com.pasquier.launcher.sauvLocal.SauvLocalProvider.recupInfosPdfSauvLocale(SauvLocalProvider.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at lotus.domino.axis.providers.java.RPCProvider.invokeMethod(Unknown Source)
at lotus.domino.axis.providers.java.RPCProvider.processMessage(Unknown Source)
at lotus.domino.axis.providers.java.JavaProvider.invoke(Unknown Source)
at lotus.domino.axis.strategies.InvocationStrategy.visit(Unknown Source)
at lotus.domino.axis.SimpleChain.doVisiting(Unknown Source)
at lotus.domino.axis.SimpleChain.invoke(Unknown Source)
at lotus.domino.axis.handlers.soap.SOAPService.invoke(Unknown Source)
at lotus.domino.axis.server.AxisServer.invoke(Unknown Source)
at lotus.domino.ws.AxisHandler.doPost(Unknown Source)
at lotus.domino.ws.AxisHandler.invoke(Unknown Source)
at lotus.domino.WebServiceHelper.runHandler(Unknown Source)
at lotus.domino.WebServiceHelper.Run(Unknown Source)
at lotus.domino.WebServiceBase.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
我尝试开始解决方案: 问题在于环境变量windir 所以我尝试授予访问此变量的权限,这是一个想法吗?
答案 0 :(得分:0)
我发现:我在java.policy中为服务器添加了grant权限 见http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllFlatWeb/d628323139e3020685257920004a5ccb?OpenDocument
grant {
permission java.security.AllPermission;
};