=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java' --- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java 2010-09-03 09:19:46 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java 2011-11-17 14:53:18 +0000 @@ -48,19 +48,19 @@ { if ( width == null || width < 10 ) { - width = 500; + width = 1190; } if ( height == null || height < 10 ) { - height = 500; + height = 880; } PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ) ); t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) ); - t.addTranscodingHint( JPEGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE ); + t.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE ); TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) ); @@ -69,17 +69,17 @@ t.transcode( input, output ); } - public static void convertToJPEG( StringBuffer buffer, OutputStream out, Integer width, Integer height ) + public static void convertToJPG( StringBuffer buffer, OutputStream out, Integer width, Integer height ) throws TranscoderException, IOException { if ( width == null || width < 10 ) { - width = 500; + width = 1190; } if ( height == null || height < 10 ) { - height = 500; + height = 880; } JPEGTranscoder t = new JPEGTranscoder(); @@ -94,4 +94,16 @@ t.transcode( input, output ); } + + public static void convertToPDF( StringBuffer buffer, OutputStream out, Integer width, Integer height ) + throws TranscoderException, IOException + { + PDFTranscoder p = new PDFTranscoder(); + + TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) ); + + TranscoderOutput output = new TranscoderOutput( out ); + + p.transcode( input, output ); + } === modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java' --- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java 2011-11-16 19:23:27 +0000 +++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java 2011-11-17 14:53:18 +0000 @@ -51,6 +51,10 @@ private static final Log log = LogFactory.getLog( ExportImageAction.class ); private static final String SVGDOCUMENT = "SVGDOCUMENT"; + + private static final String TYPE_PNG = "png"; + + private static final String TYPE_PDF = "pdf"; // ------------------------------------------------------------------------- // Output & input @@ -83,6 +87,13 @@ { this.height = height; } + + private String type; + + public void setType( String type ) + { + this.type = type; + } private SVGDocument svgDocument; @@ -90,27 +101,33 @@ protected String execute( HttpServletResponse response, OutputStream out ) throws Exception { - if ( title == null || svg == null || width == null || height == null ) + if ( title == null || svg == null || width == null || height == null || type == null ) { - log.info( "Export map from session" ); + log.info( "Invalid parameter -> Export map from session" ); svgDocument = (SVGDocument) SessionUtils.getSessionVar( SVGDOCUMENT ); } else { - log.info( "Export map from request" ); - svgDocument = new SVGDocument(); - svgDocument.setTitle( this.title ); - svgDocument.setSvg( this.svg ); - svgDocument.setWidth( this.width ); - svgDocument.setHeight( this.height ); + svgDocument.setTitle( title ); + svgDocument.setSvg( svg ); + svgDocument.setWidth( width ); + svgDocument.setHeight( height ); SessionUtils.setSessionVar( SVGDOCUMENT, svgDocument ); } - SVGUtils.convertToPNG( svgDocument.getSVGForImage(), out, this.width, this.height ); + if ( type.equals( TYPE_PNG ) ) + { + SVGUtils.convertToPNG( svgDocument.getSVGForImage(), out, width, height ); + } + + else if ( type.equals( TYPE_PDF )) + { + SVGUtils.convertToPDF( svgDocument.getSVGForImage(), out ); + } return SUCCESS; } @@ -118,13 +135,13 @@ @Override protected String getContentType() { - return ContextUtils.CONTENT_TYPE_PNG; + return type.equals( TYPE_PDF ) ? ContextUtils.CONTENT_TYPE_PDF : ContextUtils.CONTENT_TYPE_PNG; } @Override protected String getFilename() { - return "dhis2_dv_" + CodecUtils.filenameEncode( this.title ) + ".png"; + return "dhis2_dv_" + CodecUtils.filenameEncode( title ) + "." + CodecUtils.filenameEncode( type ); } @Override === modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java' --- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java 2011-11-16 13:24:53 +0000 +++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java 2011-11-17 14:53:18 +0000 @@ -35,11 +35,11 @@ import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; -import org.apache.batik.transcoder.image.JPEGTranscoder; import org.apache.batik.transcoder.image.PNGTranscoder; +import org.apache.fop.svg.PDFTranscoder; /** - * @author Tran Thanh Tri + * @author Jan Henrik Overland */ public class SVGUtils { @@ -48,19 +48,32 @@ { if ( width == null || width < 10 ) { - width = 500; + width = 1190; } if ( height == null || height < 10 ) { - height = 500; + height = 880; } PNGTranscoder t = new PNGTranscoder(); - +/* t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ) ); t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) ); - t.addTranscodingHint( JPEGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE ); +*/ + t.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE ); + + TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) ); + + TranscoderOutput output = new TranscoderOutput( out ); + + t.transcode( input, output ); + } + + public static void convertToPDF( StringBuffer buffer, OutputStream out ) + throws TranscoderException, IOException + { + PDFTranscoder t = new PDFTranscoder(); TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) ); === modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js' --- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js 2011-11-17 00:39:31 +0000 +++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js 2011-11-17 14:53:18 +0000 @@ -1828,8 +1828,8 @@ { xtype: 'button', cls: 'dv-btn-toolbar', - text: 'Save as image', - handler: function(b) { + text: 'Save as..', + execute: function(type) { var svg = document.getElementsByTagName('svg'); if (svg.length < 1) { @@ -1841,10 +1841,35 @@ document.getElementById('svgField').value = svg[0].parentNode.innerHTML; document.getElementById('widthField').value = DV.util.viewport.getSize().x - 100; document.getElementById('heightField').value = DV.util.viewport.getSize().y - 100; + document.getElementById('typeField').value = type; - var exportForm = document.getElementById('exportPNGForm'); + var exportForm = document.getElementById('exportForm'); exportForm.action = '../exportImage.action'; exportForm.submit(); + }, + listeners: { + afterrender: function(b) { + this.menu = Ext.create('Ext.menu.Menu', { + items: [ + { + text: 'PNG', + iconCls: 'dv-menu-toolbar-png', + minWidth: 80, + handler: function() { + b.execute('png'); + } + }, + { + text: 'PDF', + iconCls: 'dv-menu-toolbar-pdf', + minWidth: 80, + handler: function() { + b.execute('pdf'); + } + } + ] + }); + } } }, '->', === modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css' --- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css 2011-11-17 00:32:08 +0000 +++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css 2011-11-17 14:53:18 +0000 @@ -150,6 +150,10 @@ height: 32px; } +.x-btn-arrow { + background-image: url('../images/arrow.png'); +} + /* Button border */ .x-btn-default-toolbar-small { -moz-border-radius: 2px 2px 2px 2px; @@ -371,9 +375,17 @@ } .dv-btn-toolbar-text-1 { + color: #333; + font-weight: bold; +} +.dv-btn-toolbar-text-2 { color: #444; - font-weight: bold; -} -.dv-btn-toolbar-text-2 { - color: #555; +} + +.dv-menu-toolbar-png { + background-image:url('../images/png.png'); +} + +.dv-menu-toolbar-pdf { + background-image:url('../images/pdf.png'); } === added file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/pdf.png' Binary files dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/pdf.png 1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/pdf.png 2011-11-17 14:53:18 +0000 differ === added file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/png.png' Binary files dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/png.png 1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/images/png.png 2011-11-17 14:53:18 +0000 differ === modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html' --- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html 2011-11-16 19:23:27 +0000 +++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html 2011-11-17 14:53:18 +0000 @@ -8,11 +8,12 @@ -
+ +