2016-05-04 39 views
0

我正在從docx轉換爲pdf格式。我成功地完成了變量替換並且有一個WordprocessingMLPackage模板。無法找到此輸出格式的FOEventHandler或Renderer

我已經嘗試了兩種認同。轉換爲pdf和更新方法的舊版本的脫機版本。兩者都沒有給出這個異常錯誤

Don't know how to handle "application/pdf" as an output format. Neither an FOEventHandler, nor a Renderer could be found for this output format. Error: UnsupportedOpertaionException

我已經盡了一切努力。這件事在我的本地機器上運行,但現在在我的工作場所。我想我有所有必需的罐子。你能指導我採取什麼行動嗎?

代碼: 方法1:

Docx4J.toPDF(template, new FileOutputStream("newPdf.pdf")); 

方法2:

public static void createPDF(WordprocessingMLPackage template, String outputPath) { 
     try { 

      // 2) Prepare Pdf settings 
      PdfSettings pdfSettings = new PdfSettings(); 

      // 3) Convert WordprocessingMLPackage to Pdf 
      OutputStream out = new FileOutputStream(new File(
        outputPath)); 
      PdfConversion converter = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
        template); 
      converter.output(out, pdfSettings); 

     } catch (Throwable e) { 
      e.printStackTrace(); 
     } 
    } 

兩者都給予同樣的錯誤。任何幫助表示讚賞!

+0

這可能會有用...我錯過了Meta-INF文件夾。實際上,由於某些原因,我無法將第三方docx4j導入到我的項目中,所以這種拙劣的方法是將類文件放入build-> private-> classes-> library中。這可能是一個問題嗎?如果是,請告訴在哪裏放置這個META-INF –

+0

你的classpath上有什麼FOP jar? – JasonPlutext

+0

我有fop-1.1.jar –

回答

0

我的問題已解決。問題是所需的fop-1.1.jar在我的eclipse類路徑中,但它不在本地服務器類路徑中。我將它們添加到那裏,它的功能就像一個魅力。