I'm using Batik and Itext to convert svg files to pdf. It works great with
one problem: the resulting files are large. I think it is due to the font
being drawn as shapes.
Is there a way to keep the svg text as text through the conversion?
I didn't use FOP since the readme states it doesn't handle transparency
which I require.
Are there any Transcoding hints?
The Netbeans project and output pdf may be downloaded at mo e . d
avisprogramming.com / s vgpdfsize.zip
Here is the test code - used batik-cvs-05-04-03 and iText (itext-paulo-153)
jars.
When the text is "Hello" the filesize is 1661.
When the text is "HelloAbcde" the filesize is 2569 which works out to about
200 bytes per character.
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.io.*;
import org.apache.batik.transcoder.*;
import org.apache.batik.transcoder.print.*;
public class Main {
/** Creates a new instance of Main */
final String svg = "<?xml version='1.0' encoding='ISO-8859-1'
standalone='no'?>" +
"<svg width='1188' height='756'
xmlns='http://www.w3.org/2000/svg'>" +
" <g transform='translate(50,50) scale(5,5)'>" +
" <rect x='0.0' y='0' width='200.0' height='100.0'
style='fill:red; stroke:black; stroke-width:.2; fill-opacity: 0.2;' />" +
" <rect x='20.0' y='20' width='100.0' height='50.0'
style='fill:red; stroke:black; stroke-width:.2; fill-opacity: 0.4;' />" +
" <rect x='40.0' y='40' width='50.0' height='10.0'
style='fill:blue; stroke:black; stroke-width:.2; fill-opacity: 0.1;' />" +
" <text x='45.0' y='45' >HelloAbcde</text>" +
" </g>" +
"</svg>";
public Main() {
com.lowagie.text.Document document = new
com.lowagie.text.Document(PageSize._11X17.rotate());
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("svgsize.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.concatCTM(1.0f, 0, 0, 1.0f , 36, 0 );
Graphics2D g2 = cb.createGraphics(1188, 756);
PrintTranscoder prm = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput( new
StringReader(svg));
prm.transcode(ti, null);
PageFormat pg = new PageFormat();
Paper pp= new Paper();
pp.setSize( 1188, 756);
pp.setImageableArea(0, 0, 1188, 756);
pg.setPaper(pp);
prm.print(g2, pg, 0);
g2.dispose();
cb.restoreState();
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Main m = new Main();
}
}
Jared Davis
Davis Programming, Inc
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]