I've a scenario wherein I've to convert multiple documents into a single pdf. A collection contains the respective xmls of the documents and I've to loop through them. in the loop, the obtained xml is converted to intermediate xsl-fo and then using fo processor; to a pdf file. I'm using byteArrayOutputStream for the final conversion.
After the loop ends, I'm writing the output to response using the 'write' method of byteArrayOutputStream. Now the problem is that the output pdf contains only one document which was present last in the collection.
Is there any way wherein all the documents can be converted into single pdf or is it like xsl-fo doesn't have the capability to take in multiple files and convert to single pdf?
PS: I can't use SAXON or iText or any commercial library.
Let me see if I have this clear: you have a first step where you (in some unspecified way) process a collection of XML documents and merge them (somehow). Then you take this merged collection and process it with XSL-FO.
Is that correct?
Because if it is, and if your problem is that you are only seeing data from one of the documents in the collection, then I don't see how you could possibly consider asking a question about the second step. It's obvious that the merging is at fault.
But if it isn't, then a clearer description of the process would certainly be helpful.
Thanks for the reponse. I'll explain the situation a little more elaborately.
There are multiple xmls. each xml corresponds to a single document. All the xmls are stored in a list. FOllowing is what happens in the code
loop through the list
select the xml from the list
using xslt convert it to xsl-fo format
feed as input the converted xml to fo processor
// the result of fo processing is present in the byteArrayOutputStream
'write' the stream's content to response
With the above code, all the conversions are lost except for the one which was performed last. So when I perform the 'write' operation, only the last document is present in the resulting pdf. My guess is that since I'm passing the same byteArrayOutputStream object in every conversion, the fo processor is wiping the stream off clean and then is putting the new conversion.
I've tried merging the xmls and putting them in the fo processor, but received a malformed xml error.
So, is there any way wherein multiple xmls can be converted to a single pdf. Also, does fop have this capability or is there any other approach?
Do let me know in case the above information is not helpful.
Aha. So you're making a PDF, then making another PDF, and doing something which you hope will result in a PDF which is a combination of the two. That is unlikely to work. And certainly the way you're doing it doesn't work.
But you said you tried to combine the XML documents and that just produced malformed XML. So why don't you just fix that? I'm tempted to guess (why do I have to guess, by the way?) that your method of combining them consisted simply of concatenating them, which of course doesn't result in something with a single root element.
Thank you everyone for the help!!! The xml files were not being merged properly and as Paul said, it was because of multiple root elements. Now I'm able to generate the pdf with all the selected documents.
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay: