yztszrj 2015-03-25 14:02
浏览 2771

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择