on 2011 May 18 11:07 PM
Hi,
I red mail attachment (.pdf typed) into InputStream.
I tryed to create pdf typed resource from InputStream.
But it does not act as pdf document (wdContext.currentContextElement().setResource(res))
My aim is to parse pdf (adobe form) into fields.
Regards.
public void ReadFile( java.lang.String filename, java.io.InputStream input )
{
//@@begin ReadFile()
try {
BufferedInputStream bis1 = new BufferedInputStream(input);
BufferedInputStream bis2 = new BufferedInputStream(input);
int aByte;
int size = 0;
while ((aByte = bis1.read()) != -1) {
size++;
}
bis1.close();
byte[] b = new byte[size];
bis2.read(b, 0, size);
bis2.close();
IWDResource res =
WDResourceFactory.createCachedResource(
b,
filename,
WDWebResourceType.PDF);
wdContext.currentContextElement().setResource(res);
i think you cannot read the stream twice.
try following code, hope it works for you.
BufferedInputStream stream = new BufferedInputStream(input);;
byte[] bytes = new byte[102400];
int length = 0;
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
while ((length = stream.read(bytes)) != -1) {
tmpOut.write(bytes, 0, length);
}
IWDResource res =
WDResourceFactory.createCachedResource(
tmpOut.toByteArray(),
filename,
WDWebResourceType.PDF);
wdContext.currentContextElement().setResource(res);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
65 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.