posted 15 years ago
Lets say if we have a document that has 4 pages. we are getting the Inputstream for every page. In the given code below , it gets the stream in loop for every page, but it is not writing it to the file more than once. I mean its writing only one page(1rst page). Is there anyway we can get 4 stream and write it to a image file? This coule be a great help if any one can give me working sample code.
ContentElementList docContentList = doc.get_ContentElements();
Iterator iter = docContentList.iterator();
while (iter.hasNext() )
{
ContentTransfer ct = (ContentTransfer) iter.next();
File f=new File("textfile1.txt");
FileOutputStream fop=new FileOutputStream(f);
// Print element sequence number and content type of the element
System.out.println("\nElement Sequence number: " +
ct.get_ElementSequenceNumber().intValue() + "\n" +
"Content type: " + ct.get_ContentType() + "\n");
// Get and print the content of the element
int docLen = ct.get_ContentSize().intValue();
byte[] buf = new byte[docLen];
InputStream stream = ct.accessContentStream(); //Everytime different contents are coming here, mean diff page everytime.
try
{
stream.read(buf, 0, docLen);
fop.write(buf); // here it writes only once.
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
fop.flush();
fop.close();