Re: generating png and pdf files

2011-04-14 Thread Jeremias Maerki
Hi Joris,
you obviously already have the code that paints against a Graphics2D
object. You use SVGGraphics2D to produce SVG.

For PNG and PDF you could, of course, use Batik's transcoders to convert
the SVG to PNG and PDF:
http://xmlgraphics.apache.org/batik/using/transcoder.html
But that would be inefficient because it requires two steps.

To create a PNG directly, create a BufferedImage and request a
Graphics2D from it:

Graphics2D g2d = (Graphics2D)bufImage.getGraphics();
// Print to the SVG Graphics2D object
graphComponent.getGraphControl().print(g2d);

Then use ImageIO to write the BufferedImage to a PNG file. See here for
ideas:
http://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png

For PDF you can try the org.apache.fop.svg.PDFDocumentGraphics2D from
Apache FOP. Here's a usage example:
http://markmail.org/message/6s6us2hf34h2q3mv
PDFDocumentGraphics2D is also used by the PDFTranscoder for Batik to
create PDF from SVG.

HTH

On 13.04.2011 19:39:50 Joris Kinable wrote:
 Dear,
 
 I have a mxGraphComponent which basically is a
 javax.swing.JScrollPane. Objective is to print this mxGraphComponent
 to a file in the following 3 formats: SVG, PDF, PNG. The images in the
 .SVG and .PDF files should be scalable i.e. vectorized. The following
 code works great for printing the .SVG file:
 
 private void batikTest(mxGraphComponent graphComponent){
   // Get a DOMImplementation
 DOMImplementation domImpl =
 GenericDOMImplementation.getDOMImplementation();
 
 // Create an instance of org.w3c.dom.Document
 Document document = domImpl.createDocument(null, svg, null);
 
 // Create an instance of the SVG Generator
 SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
 
 // Print to the SVG Graphics2D object
 graphComponent.getGraphControl().print(svgGenerator);
 
 boolean useCSS = false;
 
 Writer out;
   try {
   out=new FileWriter(new 
 File(OUTPUTDIR+fileName+_batik.SVG));
   svgGenerator.stream(out, useCSS);
   } catch (Exception e) {
   e.printStackTrace();
   }
   System.out.println(Batik svg printed);
 }
 
 Is there a convenient way to generate the .PDF and .PNG files too
 using this code? I can't really find how to do that within the code.
 There is a description on how to externally convert the generated .SVG
 file to a pdf (http://xmlgraphics.apache.org/batik/tools/rasterizer.html)
  but I would like to do this within the code, without having to call
 an external tool.
 
 Thnx,
 
 Joris



Jeremias Maerki


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



Re: CleanerThread never terminates, causes leaks in webapp

2011-04-14 Thread Martin Jacobson
I am running a webapp (under both Tomcat 6  7) that exhibits the same
behaviour:

14-Apr-2011 10:32:54 org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/mapmosaic] appears to have started a
thread named [Batik CleanerThread] but has failed to stop it. This is
very likely to create a memory leak.

Under normal development conditions, the app is re-deployed many times
per day, and causes an OutOfMemoryError eventually. Even if in
production, the memory leak is so slow as to be negligeable, it would
be far better to provide a hook so I can terminate it when the webapp
closes.

Martin

On 12 April 2011 21:30, tiwaris tiwa...@gmail.com wrote:
 I also have encountered this issue. This happens rarely. When I quit my java
 app, it sill has not released the shell (the process is still running). I
 then used jvisualvm to monitor all the running threads in my application and
 noticed that Batik CleanerThread was still running.

 I incorporated the patch. Will have to see if the issue reappears.


 --
 View this message in context: 
 http://batik.2283329.n4.nabble.com/CleanerThread-never-terminates-causes-leaks-in-webapp-tp2978944p3445621.html
 Sent from the Batik - Users mailing list archive at Nabble.com.

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





-- 
From my MacBook Pro

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