日期:2014-05-19  浏览次数:20670 次

请教一些java操作 openoffice的问题。急急急
现在在做一个东西。上传PDF,然后实现一个功能,将PDF的内容取出来,再生成一个PDF。
现在已经将内容保存在oracle中,使用BLOB类型保存。已经保存好了。
我在debug下将取得的2进制的数据转为了string,打印出来类容是很乱的,各种乱码(如果是DOC的话,类容无乱码)
现在我应该怎么做才能将这些内容再次转为PDF并且保存下来呢?

下面是我的代码,
Java code

OOByteInputStream ooois = new OOByteInputStream(img.getImageData());
System.out.println("image data ----" + new String(img.getImageData()));//img.getImageData是能够取得保存在数据库中的值的
com.sun.star.beans.PropertyValue xValues[] =  new com.sun.star.beans.PropertyValue[2];

xValues[0] = new PropertyValue();
xValues[0].Name = "InputStream";
xValues[0].Value = ooois;
xValues[1] = new PropertyValue();
xValues[1].Name = "Hidden";
xValues[1].Value = new Boolean(true);      // was boolean 'true' before

xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
xComponent  = xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, xValues);
com.sun.star.text.XTextDocument aTextDocument = (com.sun.star.text.XTextDocument)
                    UnoRuntime.queryInterface( com.sun.star.text.XTextDocument.class, xComponent);




OOByteInputStream.java
Java code

import java.io.ByteArrayInputStream;
import java.io.IOException;

import com.sun.star.io.*;


public class OOByteInputStream extends ByteArrayInputStream implements XInputStream,XSeekable 
{ 
   public OOByteInputStream(byte[] buf) 
   { 
      super(buf); 
   } 
   public void seek(long p1) throws IllegalArgumentException, com.sun.star.io.IOException 
   { 
      pos=(int)p1; 
   } 
   public long getPosition() throws com.sun.star.io.IOException 
   { 
      return pos; 
   } 
   public long getLength() throws com.sun.star.io.IOException 
   { 
      return count; 
   } 
   public int readBytes(byte[][] p1, int p2) throws NotConnectedException, BufferSizeExceededException, com.sun.star.io.IOException 
   { 
      try 
      { 
         byte[] b=new byte[p2]; 
         int res=super.read(b); 
         if(res>0) 
         { 
            if(res<p2) 
            { 
               byte[] b2=new byte[res]; 
               System.arraycopy(b,0,b2,0,res); 
               b=b2; 
            } 
         } 
         else 
         { 
            b=new byte[0]; 
            res=0; 
         } 
         p1[0]=b; 
         return res; 
      } 
      catch (IOException e) {throw new com.sun.star.io.IOException(e.getMessage(),this);} 
   } 
   public int readSomeBytes(byte[][] p1, int p2) throws NotConnectedException, BufferSizeExceededException, com.sun.star.io.IOException 
   { 
      return readBytes(p1,p2); 
   } 
   public void skipBytes(int p1) throws NotConnectedException, BufferSizeExceededException, com.sun.star.io.IOException 
   { 
      skip(p1); 
   } 
   public int available() 
   { 
      return super.available(); 
   } 
   public void closeInput() throws NotConnectedException, com.sun.star.io.IOException 
   { 
      try 
      { 
         close(); 
      } 
      catch (IOException e) {throw new com.sun.star.io.IOException(e.getMessage(),this);} 
   } 
}





其中xComponent最后是Null。。搞半天也有没弄出来..其指导。起指点、、最后求包养~~~

------解决方案--------------------
Java code

XInputStream xInputStream = xSimpleFileAccess.openFileRead("file:///c:/test.docx");
PropertyValue[] loadProps = new PropertyValue[2];
loadProps[0] = new Proper