Hi,

we have the same problem as Urmo Rae (see, “Strange behaviour when rendering 
SVG texts under java program vs jruby” from 19 Jan 2016 ).

We are using FOP to render XSL-FO, with some instream SVG graphics into PDF.
All worked very well with FOP 1.0 and Batik 1.7.

Since we have updated to FOP 2.0 (and now 2.1) and Batik 1.8, we get boxes 
around every single character when the text is in the SVG Part of the document.

But the problem only occurs when executed from a servlet on tomcat 6. 
When FOP is called standalone from the command line on the same machine, the 
PDF looks fine.

Please have a look to the attached example.

Thanks a lot
Fred


Attachment: example.xml
Description: XML document

Attachment: example.xslt
Description: Binary data

Attachment: from_servlet.pdf
Description: Adobe PDF document

package servlets;

import java.io.File;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;

public class SimpleFopTest extends HttpServlet{
	private static final long serialVersionUID = -9095843288238294076L;
	
	HttpServletRequest request;
	HttpServletResponse response;
	
	
	private TransformerFactory tFactory = TransformerFactory.newInstance();

	public void doGet(HttpServletRequest request,
	                   HttpServletResponse response) throws ServletException {

		
		String realPath=request.getSession().getServletContext().getRealPath("/");
		String xsltPath=realPath+"/dokumente/xslt/example.xslt";
		String xmlPath=realPath+"/dokumente/xslt/example.xml";

		System.out.println("xslt="+xsltPath);
		System.out.println("xml="+xmlPath);
		
		try {
	        response.setContentType("application/pdf");
	        FopFactory fopFactory = FopFactory.newInstance(new File("./").toURI());
	        ByteArrayOutputStream out = new ByteArrayOutputStream();
	        
	        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, response.getOutputStream());
	        Source xsltSrc = new StreamSource(new File(xsltPath));
	        Transformer transformer = tFactory.newTransformer(xsltSrc);
	        Result res = new SAXResult(fop.getDefaultHandler());

	      //Setup input
	      Source src = new StreamSource(new File(xmlPath));

	      //Start the transformation and rendering process
	      transformer.transform(src, res);

	      //Prepare response
	      response.setContentType("application/pdf");
	      response.setContentLength(out.size());

	      //Send content to Browser
	      response.getOutputStream().write(out.toByteArray());
	      response.getOutputStream().flush();
	    } catch (Exception ex) {
	        throw new ServletException(ex);
	    }
	}
}

Attachment: standalone.pdf
Description: Adobe PDF document

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org

Reply via email to