• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert multiple xmls to pdf using xsl-fo

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tushar Nigamm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
loop again
'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.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect the problem is = if you are doing multiple calls to the xsl-fo processor you are creating multiple complete documents, NOT concatenating.

You need a single merged fo document to produce a single merged pdf document.

Bill

 
Tushar Nigamm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic