You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Tonny Kohar <to...@kiyut.com> on 2015/05/26 06:48:21 UTC

Re: Pretty Printing/saving a nicely formatted Document

Hi,

Here is how you use PrettyPrinter. You are not invoked PrettyPrinter
directly, instead use SVGTrancoder which utilize Pretty Printer.

Here is sample code

Transcoder transcoder = new SVGTranscoder();
TranscoderInput in = new TranscoderInput(doc);
TranscoderOutput out = new TranscoderOutput(writer);
//transcoder.setTranscodingHints(hints); set this if you want transcoder
hint like tab, etc
transcoder.transcode(in, out);

Hope it helps you

Regards
Tonny Kohar

On Tue, 2004-05-25 at 22:45, ah49@drexel.edu wrote:
> I save an SVG file and i would like for it to be formatted nicely... Here is my code some code is left out to make things simple ... i wasnt sure how to add a PrettyPrinter as the code i have commented out throws an exception...
> 
>     public static void saveXMLDocAsSVG(Document document) throws org.apache.batik.transcoder.TranscoderException{
>         
>         input = new TranscoderInput(svgCanvas.getSVGDocument());
>         
>         ////////////
>         File f = JFileChooser to pick what to save it as.
>         ////        
>                 try 
>                 {
>                     writer = new PrintWriter(new FileOutputStream(f));
>                 }
>                 catch(FileNotFoundException e) {
>                     e.getMessage();
>                 }
>                 catch(IOException e) {
>                     e.getMessage();
>                 }
>                 
>                 try {
>                     /*org.apache.batik.transcoder.svg2svg.PrettyPrinter newpp = new org.apache.batik.transcoder.svg2svg.PrettyPrinter();
>                     newpp.print(input.getReader(), writer);
>                     newpp.setTabulationWidth(5);
>                     */
>                      DOMUtilities.writeDocument( svgCanvas.getSVGDocument(), writer);
>                 }
>                 catch(IOException e) {
>                     e.getMessage();
>                 }
>                 
>                 writer.flush();
>                 writer.close();
>         
>     }//end save
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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