C#下通过OpenOffice转换PDF出错

参照niuhea的《通过OpenOffice转换PDF》,用C#编写如下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.artofsolving.jodconverter;
using com.artofsolving.jodconverter.openoffice.connection;
using com.artofsolving.jodconverter.openoffice.converter;
using java.io;
using System.Text;
namespace wordtopdf
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            File xlsf = new File("C://test.pdf");
            File targetF = new File("C://test.pdf");       
        // 获得文件格式  
        DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();  
        DocumentFormat pdfFormat = formatReg.getFormatByFileExtension("pdf");  
        DocumentFormat docFormat = formatReg.getFormatByFileExtension("doc");  
        // stream 流的形式  
        InputStream inputStream = new FileInputStream(xlsf);
        OutputStream outputStream = new FileOutputStream(targetF);  
       OpenOfficeConnection connection = new SocketOpenOfficeConnection("172.24.157.236",8100);

       connection.connect();       
       DocumentConverter converter = new OpenOfficeDocumentConverter(connection);   
      converter.convert(inputStream, docFormat, outputStream, pdfFormat);        
     connection.disconnect();


        }
    }
}  

编译运行后提示converter.convert(inputStream, docFormat, outputStream, pdfFormat);这句出错。
错误提示:
异常详细信息: com.sun.star.lang.IllegalArgumentException: URL seems to be an unsupported one.

如果不采用流进行转换,直接转换文件converter.convert(xlsf,targetF)则一切正常。

请教问题出在哪?怎么解决?

出错时堆栈跟踪:
[IllegalArgumentException: URL seems to be an unsupported one.]
$Proxy5.loadComponentFromURL(String , String , Int32 , PropertyValue[] ) +328
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadDocument(String , Map ) +45
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(String , Map , String , Map ) +34

[OpenOfficeException: conversion failed: could not load input document]
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(String , Map , String , Map ) +401
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(File inputFile, DocumentFormat inputFormat, File outputFile, DocumentFormat outputFormat) +210
com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(File inputFile, DocumentFormat inputFormat, File outputFile, DocumentFormat outputFormat) +149
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat) +414
com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat) +95
wordtopdf._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\wordtopdf\wordtopdf\Default.aspx.cs:34
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问