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

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程