iText 라이브러리를 사용하여 JUNG 네트워크를 PDF로 출력하려고합니다.iText를 사용하여 JUNG 시각화를 PDF로 출력
많은 솔루션은 화면을 캡처하고이를 EPS와 같은 형식으로 출력하기 위해 라이브러리를 사용하기 전에 프레임에 그래프를 표시합니다. 그러나, 내 응용 프로그램은 자동으로 많은 네트워크를 구축하고 파일에 저장하기 전에 화면에 각 네트워크를 표시하는 출력 그래서 좋은 해결책은 아닙니다.
일부 검색을 수행했는데 정확히 무엇을하고 있는지 알지 못했습니다. 그래프를 PNG로 출력하는 것이 간단하지만 (PNG의 품질은 내 요구에 맞지 않습니다. here 참조)
현재 코드는 JFreeChart에서 PDF로 차트를 작성한 것입니다 (here 참조). Graph2D 객체를 얻으려고하고 있는데, 그래프를 그린 다음 PDF로 출력 할 수 있습니다. 이 코드는 visualise.getGraphics()에서 반환 된 그래픽 객체가 null이므로 null 포인터 예외를 생성합니다.
모든 조언, 코드 스 니펫 또는 온라인 예가 제공됩니다.
public void write() throws IOException, DocumentException {
// Open the PDF file for writing
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, new Dimension(WIDTH, HEIGHT));
visualise.setPreferredSize(new Dimension(WIDTH + 50, HEIGHT + 50));
visualise.setDoubleBuffered(false);
Graphics2D graphics2d = (Graphics2D) visualise.getGraphics();
visualise.paintComponents(graphics2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
this.document.close();
}