dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10946
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3021: Made to export page of pdf a bit more wider
------------------------------------------------------------
revno: 3021
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-03-14 12:45:16 +0700
message:
Made to export page of pdf a bit more wider
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java 2011-02-27 22:34:30 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java 2011-03-14 05:45:16 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.util.ContextUtils;
import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfPTable;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
@@ -59,7 +60,7 @@
// -------------------------------------------------------------------------
private Grid grid;
-
+
public void setGrid( Grid grid )
{
this.grid = grid;
@@ -78,8 +79,8 @@
// ---------------------------------------------------------------------
Grid _grid = (Grid) invocation.getStack().findValue( "grid" );
-
- grid = _grid != null ? _grid : grid;
+
+ grid = _grid != null ? _grid : grid;
// ---------------------------------------------------------------------
// Configure response
@@ -89,33 +90,36 @@
OutputStream out = response.getOutputStream();
- String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".pdf";
-
+ String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) )
+ + ".pdf";
+
ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, true, filename, false );
// ---------------------------------------------------------------------
// Write PDF to output stream
// ---------------------------------------------------------------------
-
+
Document document = openDocument( out );
-
+
PdfPTable table = new PdfPTable( grid.getVisibleWidth() );
-
+
table.setHeaderRows( 1 );
+ table.setWidthPercentage( 100f );
+ table.setKeepTogether( false );
- //TODO make wider
+ // TODO make wider
table.addCell( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ) );
table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) );
table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) );
table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) );
-
+
for ( GridHeader header : grid.getVisibleHeaders() )
{
table.addCell( getItalicCell( header.getName() ) );
}
table.addCell( getEmptyCell( grid.getVisibleWidth(), 10 ) );
-
+
for ( List<Object> row : grid.getVisibleRows() )
{
for ( Object col : row )
@@ -124,8 +128,24 @@
}
}
+ adjustColumnWitdh( grid, table );
+
addTableToDocument( document, table );
closeDocument( document );
}
+
+ private void adjustColumnWitdh( Grid grid, PdfPTable table )
+ throws DocumentException
+ {
+ int numColumns = grid.getWidth();
+ float[] widths = new float[numColumns];
+ widths[0] = 2;
+
+ for ( int i = 1; i < numColumns; i++ )
+ {
+ widths[i] = 1;
+ }
+ table.setWidths( widths );
+ }
}