# HG changeset patch # User Ingo Weinzierl # Date 1267623855 0 # Node ID e5f1e868ee3e69d82b65a5ea0f8e3a4b12c9d4c3 # Parent a94ed2755480fcc26095112d7d0dd2678e7cf57f Implementedr histogram pdf export. gnv-artifacts/trunk@726 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Mar 03 13:44:15 2010 +0000 @@ -1,3 +1,21 @@ +2010-03-03 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Trigger pdf creation for histograms when an 'out' call arrives with output + mode 'histogram' and export mode 'pdf'. + + * src/main/java/de/intevation/gnv/exports/ChartExportHelper.java: + Implemented a method to export histograms as multipage pdf file. + + * doc/conf/products/timeseries/conf_mesh.xml, + doc/conf/products/horizontalprofile/conf_mesh.xml, + doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml, + doc/conf/products/horizontalprofile/conf_mesh_cross.xml, + doc/conf/products/verticalprofile/conf_mesh.xml, + doc/conf/products/verticalprofile/conf_timeseriespoint.xml, + doc/conf/products/verticalprofile/conf_instantaneouspoint.xml: Added pdf + support for histogram charts. + 2010-03-02 Ingo Weinzierl * src/main/java/de/intevation/gnv/state/OutputStateBase.java: Added an xpath diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Wed Mar 03 13:44:15 2010 +0000 @@ -240,9 +240,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Wed Mar 03 13:44:15 2010 +0000 @@ -241,9 +241,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml Wed Mar 03 13:44:15 2010 +0000 @@ -207,9 +207,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Wed Mar 03 13:44:15 2010 +0000 @@ -229,9 +229,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Wed Mar 03 13:44:15 2010 +0000 @@ -212,9 +212,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Wed Mar 03 13:44:15 2010 +0000 @@ -110,9 +110,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Wed Mar 03 13:44:15 2010 +0000 @@ -245,9 +245,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Wed Mar 03 13:44:15 2010 +0000 @@ -183,9 +183,7 @@ - diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Wed Mar 03 13:44:15 2010 +0000 @@ -218,5 +218,79 @@ document.close(); } } + + + public static void exportHistogramsAsPDF( + OutputStream out, + Chart[] histograms, + String pageFormat, + boolean landscape, + float marginLeft, + float marginRight, + float marginTop, + float marginBottom + ) { + log.info("export histogram as pdf."); + + if (pageFormat == null) + pageFormat = DEFAULT_PAGE_SIZE; + + Rectangle page = PageSize.getRectangle(pageFormat); + int pageWidth = + (int) (page.getRight(marginRight) - page.getLeft(marginLeft)); + int pageHeight = + (int) (page.getTop(marginTop) - page.getBottom(marginBottom)); + + Document document = null; + if (landscape) { + document = new Document(page.rotate()); + log.debug("Create landscape pdf."); + } + else + document = new Document(page); + + try { + PdfWriter writer = PdfWriter.getInstance(document, out); + + document.addCreationDate(); + document.open(); + + PdfContentByte content = writer.getDirectContent(); + + int width = 0; + int height = 0; + if (landscape) { + width = pageHeight; + height = pageWidth; + } + else { + width = pageWidth; + height = pageHeight; + } + + int size = histograms.length; + for (int i = 0; i < size; i++) { + if (i > 0) { + document.newPage(); + } + + JFreeChart chart = histograms[i].generateChart(); + PdfTemplate template = content.createTemplate(width, height); + Graphics2D graphics = template.createGraphics(width, height); + Rectangle2D area = new Rectangle2D.Double( + 0.0D, 0.0D,width,height); + + chart.draw(graphics, area); + graphics.dispose(); + content.addTemplate(template, marginLeft, marginBottom); + } + } + catch (DocumentException de) { + log.error("Error while exporting chart to pdf.", de); + } + finally { + document.close(); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r a94ed2755480 -r e5f1e868ee3e gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Mar 02 14:48:32 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Wed Mar 03 13:44:15 2010 +0000 @@ -374,7 +374,13 @@ ); } else if (mode.equalsIgnoreCase("pdf")) { - log.info("not implemented yet."); + ChartExportHelper.exportHistogramsAsPDF( + outputStream, + histograms, + "A4", + PDF_FORMAT_LANDSCAPE, + 50F, 50F, 50F, 50F + ); } else if (mode.equalsIgnoreCase("svg")) { ChartExportHelper.exportHistogramsAsSVG(