|
From: Joshua O'M. <jos...@gm...> - 2012-05-15 18:42:17
|
This was answered on the JUNG web forum by searching for "headless": http://sourceforge.net/projects/jung/forums/forum/252062/topic/1407188 On Tue, May 15, 2012 at 6:44 AM, Ryan Ames <rya...@ma...>wrote: > Hi, > > I'm trying to use JUNG and iText (http://itextpdf.com/) to export a JUNG > network to a PDF file. > > I've searched online but not been able to find exactly what I'm looking > for. My application doesn't use a GUI and so I never display the graph to > then capture the screen, as I have seen in several examples. > > What I want to do is draw the graph on a graphics2d object that can then > be used to output to a PDF. However my current code (below) just creates a > blank PDF document. > > Any useful code snippets or advice would be much appreciated. > > Regards > > Ryan > > My current code is: > > public void write() throws IOException, DocumentException { > > // Open the PDF file for writing - and create a graphics object > this.document = new Document(); > this.writer = PdfWriter.getInstance(this.document, new FileOutputStream( > this.fileName)); > document.open(); > PdfContentByte contentByte = writer.getDirectContent(); > PdfTemplate template = contentByte.createTemplate(WIDTH, HEIGHT); > Graphics2D graphics2d = template.createGraphics(WIDTH, HEIGHT, > new DefaultFontMapper()); > > // Apply a layout to the graph > Layout<Vertex, Edge> layout = new CircleLayout<Vertex, Edge>(this.network > ); > layout.setSize(new Dimension(WIDTH, HEIGHT)); > > // Draw on the graphics 2D object > VisualizationImageServer<Vertex, Edge> visualise = new VisualizationImageServer<Vertex, > Edge>(layout); > visualise.setDoubleBuffered(false); > visualise.paintComponents(graphics2d); > > graphics2d.dispose(); > contentByte.addTemplate(template, 0, 0); > > this.document.close(); > > } > > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Jung-support mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/jung-support > > -- jos...@gm.../~jmadden Joshua O'Madadhain: Information Scientist, Musician, Philosopher-At-Tall It's that moment of dawning comprehension that I live for. -- Bill Watterson My opinions are too rational and insightful to be those of any organization. |