Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java @ 7700:9211f8cafe8a
(issue1559) Improve Exception handling and allow null titles
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 16 Dec 2013 19:08:39 +0100 |
parents | 9509359c8db8 |
children | 56e7e6c18c26 |
comparison
equal
deleted
inserted
replaced
7699:4daaf5e51dfb | 7700:9211f8cafe8a |
---|---|
238 | 238 |
239 Document document = null; | 239 Document document = null; |
240 if (landscape) { | 240 if (landscape) { |
241 document = new Document(page.rotate()); | 241 document = new Document(page.rotate()); |
242 log.debug("Create landscape pdf."); | 242 log.debug("Create landscape pdf."); |
243 } | 243 } else { |
244 else | |
245 document = new Document(page); | 244 document = new Document(page); |
245 } | |
246 | 246 |
247 try { | 247 try { |
248 PdfWriter writer = PdfWriter.getInstance(document, out); | 248 PdfWriter writer = PdfWriter.getInstance(document, out); |
249 | 249 |
250 document.addSubject(chart.getTitle().getText()); | 250 document.addSubject(chart.getTitle() != null ? chart.getTitle().getText() : ""); |
251 document.addCreationDate(); | 251 document.addCreationDate(); |
252 document.open(); | 252 document.open(); |
253 | 253 |
254 PdfContentByte content = writer.getDirectContent(); | 254 try { |
255 | 255 PdfContentByte content = writer.getDirectContent(); |
256 PdfTemplate template = content.createTemplate(width, height); | 256 |
257 Graphics2D graphics = template.createGraphics(width, height); | 257 PdfTemplate template = content.createTemplate(width, height); |
258 | 258 Graphics2D graphics = template.createGraphics(width, height); |
259 double[] origin = getCenteredAnchor( | 259 |
260 marginLeft, marginRight, marginBottom, marginTop, | 260 double[] origin = getCenteredAnchor( |
261 width, height, | 261 marginLeft, marginRight, marginBottom, marginTop, |
262 size[0], size[1]); | 262 width, height, |
263 | 263 size[0], size[1]); |
264 Rectangle2D area = new Rectangle2D.Double( | 264 |
265 origin[0], origin[1], size[0], size[1]); | 265 Rectangle2D area = new Rectangle2D.Double( |
266 | 266 origin[0], origin[1], size[0], size[1]); |
267 ChartRenderingInfo info = new ChartRenderingInfo(); | 267 |
268 | 268 ChartRenderingInfo info = new ChartRenderingInfo(); |
269 chart.draw(graphics, area, info); | 269 |
270 graphics.dispose(); | 270 chart.draw(graphics, area, info); |
271 content.addTemplate(template, 0f, 0f); | 271 graphics.dispose(); |
272 } | 272 content.addTemplate(template, 0f, 0f); |
273 catch (DocumentException de) { | 273 } |
274 finally { | |
275 document.close(); | |
276 } | |
277 } catch (DocumentException de) { | |
274 log.error("Error while exporting chart to pdf.", de); | 278 log.error("Error while exporting chart to pdf.", de); |
275 } | |
276 finally { | |
277 document.close(); | |
278 } | 279 } |
279 } | 280 } |
280 | 281 |
281 | 282 |
282 /** | 283 /** |