现在在做一个东西。上传PDF,然后实现一个功能,将PDF的内容取出来,再生成一个PDF。
现在已经将内容保存在oracle中,使用BLOB类型保存。已经保存好了。
我在debug下将取得的2进制的数据转为了string,打印出来类容是很乱的,各种乱码(如果是DOC的话,类容无乱码)
现在我应该怎么做才能将这些内容再次转为PDF并且保存下来呢?下面是我的代码,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' beforexComponentLoader = (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.javaimport 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。。搞半天也有没弄出来..其指导。起指点、、最后求包养~~~
现在已经将内容保存在oracle中,使用BLOB类型保存。已经保存好了。
我在debug下将取得的2进制的数据转为了string,打印出来类容是很乱的,各种乱码(如果是DOC的话,类容无乱码)
现在我应该怎么做才能将这些内容再次转为PDF并且保存下来呢?下面是我的代码,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' beforexComponentLoader = (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.javaimport 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。。搞半天也有没弄出来..其指导。起指点、、最后求包养~~~
XInputStream xInputStream = xSimpleFileAccess.openFileRead("file:///c:/test.docx");
PropertyValue[] loadProps = new PropertyValue[2];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "InputStream";
loadProps[0].Value = xInputStream;
loadProps[1] = new PropertyValue();
loadProps[1].Name = "FilterName";
loadProps[1].Value = "Microsoft Word 2007 XML";
XComponent xComponent = xComponentLoader.loadComponentFromURL("private:stream",
"_blank", 0, loadProps);
请问你img什么? 图片吗?
我倒是不知道Openoffice的SDK可以用private:stream打开一个图片的流
PDF中有图片的,也有文字。。对于你说的这个:
我倒是不知道Openoffice的SDK可以用private:stream打开一个图片的流我也不是很懂的。。才接触不久的。。图片的话 应该如何呢?
请问你img什么? 图片吗?
我倒是不知道Openoffice的SDK可以用private:stream打开一个图片的流PDF中确实有图片private:stream这个能不能打开我也不是很清楚,才接触。各种照搬,现在出问题了。却找不到办法。能指点1 2 吗?
你想把图片存成什么格式??Openoffice我知道的就能打开word excel ppt pdf之类和他自己一套的文件。