Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

creating pdf typed resource from InputStream

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

Former Member
replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question