cancel
Showing results for 
Search instead for 
Did you mean: 

creating pdf typed resource from InputStream

Former Member
0 Kudos

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);

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

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);

Answers (0)