I have a problem with converted PNG using Apache Batik different when there is text with a different font family like Arial. The problem occurs in an environment where Cent OS 6 works with Tomcat 7 and Java 6.
The Java code used to convert SVG to PNG is:
// Convert the SVG image to png and send back PNGTranscoder transcoder = new PNGTranscoder(); // TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgImage)); outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Transcode the given SVG transcoder.transcode(input, output); outStream.flush(); pngImage = outStream.toByteArray();
The SVG file that I am going to convert to PNG is as follows:
<svg version="1.1" x="0" y="0" id="hjtqebzv1" width="610" height="240" xmlns="http://www.w3.org/2000/svg" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <linearGradient id="LFFFFFF0" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" style="stop-color:#FFFFFF;stop-opacity:0.8"/> <stop offset="100%" style="stop-color:#FAFAFA;stop-opacity:1"/> </linearGradient> </defs> <g id="hjtqebzv-o1" transform="translate(5,5)"> <rect x="1" y="1" width="578" height="20" fill="url(#LFFFFFF0)" stroke="#5e5ca7" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/> <text x="1" y="1" width="578" height="19" > <tspan x="2" y="14" style="font-family:Arial;font-size:12px;fill:#000000;">This is a test text for testing text overlapping in the rectangle when convert the svg to PNG using SVG-Batik</tspan> </text> </g> </svg>
When I open the SVG file in Firefox, it displays correctly, as shown in the image below: 
But when I convert SVG using Apache Batik, the converted image looks different. PNG Converter Apache Batik: 
On Windows 7 running tomcat 7 and Java 7, the generated image is identical to the original SVG.
As a Cent OS server, it provides a text messed image. I feel that the Arial font is not available for the tomcat / java application and needs to be downloaded manually. If so, I prefer to have advice to load them in the usual way from the main OS location (OS font location) without any changes to the SVG file.
source share