xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Braumüller, Hans <H.Braumuel...@hanseorga.de>
Subject !newbie generating pdf from xml-source as stream
Date Tue, 07 Sep 2004 14:57:34 GMT
Hello,

i am trying to generate pdf on fly from dynamic xml-source adapting the official fopservlet.java
example to display it on the IE6 Browser. I am also beginning with java.

Here goes my code, where sXSL is the Url to my stylesheet:

<snip>
	InputSource xslSource = new InputSource(new URL(sXSL).openStream());
    	InputSource xmlSource = new InputSource (new StringReader(sReturnString));
	XSLTInputHandler input = new XSLTInputHandler(xslSource, xmlSource); 
	//StreamSource xmlSource = new StreamSource(new StringReader(sReturnString));
      renderXML(input, c_response);
</snip>

where renderXML is slightly different from the original 
<snip>
public void renderXML(XSLTInputHandler input,
                          HttpServletResponse response) throws ServletException {
        try {
           log("renderXML");
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            response.setContentType("application/pdf");
            response.setHeader(	"Content-disposition","inline; filename=test.pdf" );

            Driver driver = new Driver();
            driver.setLogger(logPDF);
            driver.setRenderer(Driver.RENDER_PDF);
            driver.setOutputStream(out);
            driver.render(input.getParser(), input.getInputSource());

            byte[] content = out.toByteArray();
            response.setContentLength(content.length);
            response.getOutputStream().write(content);
            response.getOutputStream().flush();
        } catch (Exception ex) {
            throw new ServletException(ex);
        }
    }
</snip>
What is wrong ?

if have also tried do it with the transformer object:
<snip>
public void generatePdf(String xml, String xslPfad, OutputStream pdfOutput) throws Exception
{         
	      try{
			      
			c_response.setContentType("application/pdf");
            	c_response.setHeader(	"Content-disposition","inline; filename=test.pdf" );
			Source streamSource = new StreamSource(new URL(xslPfad).openStream());						 
			Source saxSource = new SAXSource(new InputSource(new StringReader(xml)));			
			Driver driver = new Driver();	      	      	      	      	     
			Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
			MessageHandler.setScreenLogger(logger);
			driver.setLogger(logger);
			//driver.setLogger(getLogger());
			driver.setRenderer(Driver.RENDER_PDF);     	      			      
			driver.setOutputStream(pdfOutput);			      
			TransformerFactory tf = TransformerFactory.newInstance();
			Transformer transformer = tf.newTransformer(streamSource);
			Result result = new SAXResult(driver.getContentHandler());
			transformer.transform(saxSource, result);
			      
	      }
	      catch (Exception e) { }
	      finally{ 	      
	      		//pdfOutput.close(); 
	      }		
  }	
</snip>
calling this with:
<snip>
 	OutputStream out = new ByteArrayOutputStream();     
       try {
     		generatePdf(sReturnString, sXSL, out);
     		}
    	catch (Exception e) { }
</snip>

Thanks for your help,

Hans Braumüller
    	      


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Mime
View raw message