xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Terry Lurie" <terry.lu...@ADGISTICS.com>
Subject Batik 1.6 , PDFTranscoder and flowRoot
Date Wed, 17 Aug 2005 11:32:11 GMT
Using the new Batik 1.6 , flowRoot elements do not transcode to PDF correctly.
Using a simple main wrapper [below] and a simple input file [further below] the output pdf
will be different from the squiggle rendering. The file batik-1.6/samples/tests/spec12/text/flowRegionBreak.svg
also highlights the problem.
It seems that the text baseline gets set to the top of the PDF and that the wrapping no longer
works. That is, flowLine does not cause a new line. You will be able to see the descending
part of the 'j' at the top left of the generated pdf.
I code java all day, and so I could fix this if I had a few pointers/ time from my boss. If
advice is forthcoming, I could probably get him to agree to letting me fix it on company time
[and release patches of course].
A simple wrapper around the methods. Pass the input file as the first argument, pass the output
file as the second. All batik 1.6 jars needed on classpath as well as log4j (sorry)
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Reader;
import java.io.StringWriter;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.util.DOMUtilities;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.PDFTranscoder;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.w3c.dom.svg.SVGDocument;
public class PdfTranscode {
 static Logger LOG = Logger.getLogger(PdfTranscode.class);
 public static void main(String[] args) {
   FileInputStream fileInputStream = new FileInputStream(args[0]); //input file arg 0
   FileOutputStream fileOutputStream = new FileOutputStream(args[1]); //output file arg 1
   Reader domReader = DOMUtilities.createXMLDocumentReader(fileInputStream);
   SAXSVGDocumentFactory SAX_DOCUMENT_FACTORY = new SAXSVGDocumentFactory("org.apache.xerces.parsers.SAXParser");
   SVGDocument w3cDocument = SAX_DOCUMENT_FACTORY.createSVGDocument(null , domReader);
   PDFTranscoder pdfTranscoder = new PDFTranscoder();
   TranscoderInput tInput = new TranscoderInput(w3cDocument);
//   TranscoderOutput tOutput = new TranscoderOutput(System.out);
   TranscoderOutput tOutput = new TranscoderOutput(fileOutputStream);
  catch(Throwable e){
   String errorText="There was some sort of exception";

sample input:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xml="http://www.w3.org/XML/1998/namespace"
width="742.6771734" height="969.4488284" version="1.2" xml:space="preserve">
<g >
<rect x="38.5590578" y="461.57122261" width="287" height="30" fill="rgb(51,82,143)" />
<flowRoot font-size="8" xml:space="preserve">
 <flowRegion >
  <rect x="38.5590578" y="461.57122261" width="287" height="30"/>
 <flowDiv >
  <flowPara><flowSpan  font-family="ADG0020" font-size="20" fill="rgb(0,0,0)" >j</flowSpan></flowPara>

View raw message