0

I have a zest(1.5.0) graphViewer which is quite large as a result scrollbar appears in the composite. Now when I am trying to export this graph as a png I am getting only the visible portion of the graph.Region beyond the scrollbars is not available in the image.

Image image = new Image(PlatformUI.getWorkbench().getDisplay(), composite.getBounds().width, composite.getBounds().height); ImageLoader loader = new ImageLoader();

            GC gc = new GC(image);
            composite.print(gc);

            gc.dispose();

            loader.data = new ImageData[]{image.getImageData()};
            loader.save("c:/raja/graph.png", SWT.IMAGE_PNG);

If I use graphViewer object it gives nodes collapsed on the top left corner

GC gc = new GC(viewer.getGraphControl());
Rectangle bounds = viewer.getGraphControl().getBounds();
Image image = new Image(viewer.getGraphControl().getDisplay(), bounds);

**<Rest same as above code>**

I need to get a single image with complete graph in it.Is there a way to achieve this. I think animation could be causing the clustering of nodes in second approach.Is there a way to turn it off (I tried setting nodeStyle to ZestStyle.No_Animation_Layout but it did not help the cause).

Raja
  • 118
  • 11

1 Answers1

0

Printing/drawing into the image is no different from printing/drawing on the display. You need to actually draw everything, what should be displayed. We had similar requirement for printing Ghantt Chart. You can download the source code and check how printing is supported there.

The idea is that you need to control drawable area and draw all the objects one by one there and then start drawing next page. I'd say it is not the easiest task, as it usually requires lots of calculations to support different printing settings.

In your case I don't know if you have control over the source code to support such functionality, so may be it would be possible to emulate it by programmatically scrolling your graph and drawing it at the same time, using composite.print(gc). However, this might introduce bad user experience.

There are also some frameworks, like PaperClips to make your printing little bit easier. There are also some swing libraries, which could be integrated into your Eclipse RCP. Also, please see this SO question for more details.

Hope that this could give you some ideas.

Community
  • 1
  • 1
Alex K.
  • 3,294
  • 4
  • 29
  • 41
  • My requirement is just to export the content of the composite mainly the graph how it is present on the screen to a pdf. Printing is currently out of scope for me. – Raja Nov 10 '14 at 11:21
  • @Raja, it doesn't matter where you export your contents, anyway you need to draw those somehwere. For exporting into PDF I used to create images out of drawable area and then create pdf document with those images. But implementation can, of course, be different. – Alex K. Nov 10 '14 at 11:46
  • Check out `GanttComposite.drawChartOntoGC`. – Alex K. Nov 10 '14 at 16:55