List of usage examples for com.lowagie.text Image scaleAbsolute
public void scaleAbsolute(float newWidth, float newHeight)
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * returns the cell for the mesh map//from w w w. j a v a2 s.com * * @param wfMesh * @return */ private Cell getMeshMapCell(WorkflowMesh3VO wfMesh) { String imgMap = null; String cartographyPath = wfMesh.getCartographyPath(); if (cartographyPath != null) { imgMap = PathUtils.FitPathToOS(cartographyPath); } try { if (imgMap != null) { Image jpgMap = Image.getInstance(imgMap); // System.out.println(jpgMap.getWidth()+" * "+jpgMap.getHeight()); jpgMap.scaleAbsolute(jpgMap.getWidth() * IMAGE_HEIGHT / jpgMap.getHeight(), IMAGE_HEIGHT); Cell cellImage = new Cell(jpgMap); cellImage.setLeading(0); cellImage.setBorderWidth(0); cellImage.setHorizontalAlignment(Element.ALIGN_CENTER); return cellImage; } else { return new Cell(new Paragraph("no map found", FONT_DOC)); } } catch (IOException e) { try { return new Cell(new Paragraph(imgMap + " not found", FONT_DOC)); } catch (BadElementException e1) { e1.printStackTrace(); return null; } } catch (Exception e) { try { return new Cell(new Paragraph(imgMap + " not found", FONT_DOC)); } catch (BadElementException e1) { e1.printStackTrace(); return null; } } }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * returns a cell with a given image inside * //from w w w . jav a 2s . co m * @param image * @return * @throws Exception */ private Cell getCellImage(String image) throws Exception { if (image != null && !image.equals("")) { try { Image jpg1 = Image.getInstance(image); jpg1.scaleAbsolute(jpg1.getWidth() * IMAGE_HEIGHT / jpg1.getHeight(), IMAGE_HEIGHT); Cell cell = new Cell(jpg1); cell.setLeading(0); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); return cell; } catch (IOException e) { return new Cell(new Paragraph(image + " not found", FONT_DOC)); } } return new Cell(new Paragraph("", FONT_DOC)); }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
private Chunk getChunkImage(String image) throws BadElementException, MalformedURLException, IOException { Image jpg = Image.getInstance(image); jpg.scaleAbsolute(jpg.getWidth() * 10 / jpg.getHeight(), 10); return new Chunk(jpg, 0, 0); }
From source file:ispyb.common.util.export.ExiPdfRtfExporter.java
License:Open Source License
/** * returns a cell with a given image inside * //from w w w. ja v a2s. c o m * @param image * @return * @throws Exception */ private Cell getCellImage(Map<String, Object> dataCollectionMapItem, String imageParam) throws Exception { if (dataCollectionMapItem.get(imageParam) != null && !(dataCollectionMapItem.get(imageParam).toString()).equals("")) { String image = dataCollectionMapItem.get(imageParam).toString(); image = PathUtils.getPath(image); try { Image jpg1 = Image.getInstance(image); jpg1.scaleAbsolute(jpg1.getWidth() * IMAGE_HEIGHT / jpg1.getHeight(), IMAGE_HEIGHT); Cell cell = new Cell(jpg1); cell.setLeading(0); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); return cell; } catch (IOException e) { return new Cell(new Paragraph(image + " not found", FONT_DOC)); } } return new Cell(new Paragraph("", FONT_DOC)); }
From source file:ispyb.common.util.export.ExiPdfRtfExporter.java
License:Open Source License
/** * returns a cell with a given image inside * /*w w w . j a v a 2s .co m*/ * @param image * @return * @throws Exception */ private Cell getCellImage(String imagePath) throws Exception { if (imagePath != null) { String image = PathUtils.getPath(imagePath); try { Image jpg1 = Image.getInstance(image); jpg1.scaleAbsolute(jpg1.getWidth() * IMAGE_HEIGHT / jpg1.getHeight(), IMAGE_HEIGHT); Cell cell = new Cell(jpg1); cell.setLeading(0); cell.setBorderWidth(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); return cell; } catch (IOException e) { return new Cell(new Paragraph(image + " not found", FONT_DOC)); } } return new Cell(new Paragraph("", FONT_DOC)); }
From source file:it.eng.spagobi.engines.chart.Utilities.ExportCharts.java
License:Mozilla Public License
/** * Set the dimension of the image to fit the A4 page size * The layout of the page should be horizontal * @param jpg the image to fit//from w w w .j a va 2s . com */ public static void fitImage(Image jpg) { if (jpg.getWidth() > PageSize.A4.getHeight()) { float imgScaledWidth = PageSize.A4.getHeight() - 100; float imgScaledHeight = (imgScaledWidth / jpg.getWidth()) * jpg.getHeight(); jpg.scaleAbsolute(imgScaledWidth, imgScaledHeight); } if (jpg.getHeight() > PageSize.A4.getWidth()) { float imgScaledHeight = PageSize.A4.getWidth() - 100; float imgScaledWidth = (imgScaledHeight / jpg.getHeight()) * jpg.getWidth(); jpg.scaleAbsolute(imgScaledWidth, imgScaledHeight); } }
From source file:it.eng.spagobi.engines.geo.service.DrawMapAction.java
License:Mozilla Public License
public void service(SourceBean serviceRequest, SourceBean serviceResponse) { String outputFormat = null;//from w w w. j av a 2s.c o m String executionId = null; File maptmpfile = null; boolean inlineResponse; String responseFileName; Monitor totalTimeMonitor = null; Monitor totalTimePerFormatMonitor = null; Monitor flushingResponseTotalTimeMonitor = null; Monitor errorHitsMonitor = null; logger.debug("IN"); try { super.service(serviceRequest, serviceResponse); totalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.totalTime"); executionId = getAttributeAsString("SBI_EXECUTION_ID"); outputFormat = getAttributeAsString(OUTPUT_FORMAT); logger.debug("Parameter [" + OUTPUT_FORMAT + "] is equal to [" + outputFormat + "]"); inlineResponse = getAttributeAsBoolean(INLINE_RESPONSE, true); logger.debug("Parameter [" + INLINE_RESPONSE + "] is equal to [" + inlineResponse + "]"); if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceStartEvent(); if (outputFormat == null) { logger.info("Parameter [" + outputFormat + "] not specified into request"); outputFormat = (String) getGeoEngineInstance().getEnv().get(GeoEngineConstants.ENV_OUTPUT_TYPE); logger.debug("Env Parameter [" + GeoEngineConstants.ENV_OUTPUT_TYPE + "] is equal to [" + outputFormat + "]"); } if (outputFormat == null) { logger.info( "Parameter [" + GeoEngineConstants.ENV_OUTPUT_TYPE + "] not specified into environment"); outputFormat = DEFAULT_OUTPUT_TYPE; } totalTimePerFormatMonitor = MonitorFactory .start("GeoEngine.drawMapAction." + outputFormat + "totalTime"); try { if (outputFormat.equalsIgnoreCase(GeoEngineConstants.PDF)) { maptmpfile = getGeoEngineInstance().renderMap(GeoEngineConstants.JPEG); } else { maptmpfile = getGeoEngineInstance().renderMap(outputFormat); } } catch (Throwable t) { throw new DrawMapServiceException(getActionName(), "Impossible to render map", t); } responseFileName = "map.svg"; IStreamEncoder encoder = null; File tmpFile = null; if (outputFormat.equalsIgnoreCase(GeoEngineConstants.JPEG)) { encoder = new SVGMapConverter(); responseFileName = "map.jpeg"; } else if (outputFormat.equalsIgnoreCase(GeoEngineConstants.PDF)) { encoder = new SVGMapConverter(); BufferedInputStream bis = null; String dirS = System.getProperty("java.io.tmpdir"); File imageFile = null; bis = new BufferedInputStream(new FileInputStream(maptmpfile)); try { int contentLength = 0; int b = -1; String contentFileName = "tempJPEGExport"; freezeHttpResponse(); File dir = new File(dirS); imageFile = File.createTempFile("tempJPEGExport", ".jpeg", dir); FileOutputStream stream = new FileOutputStream(imageFile); encoder.encode(bis, stream); stream.flush(); stream.close(); File dirF = new File(dirS); tmpFile = File.createTempFile("tempPDFExport", ".pdf", dirF); Document pdfDocument = new Document(); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(tmpFile)); pdfDocument.open(); Image jpg = Image.getInstance(imageFile.getPath()); jpg.setRotation(new Double(Math.PI / 2).floatValue()); jpg.scaleAbsolute(770, 520); pdfDocument.add(jpg); pdfDocument.close(); docWriter.close(); maptmpfile = tmpFile; } finally { bis.close(); if (imageFile != null) imageFile.delete(); } responseFileName = "map.pdf"; encoder = null; } try { flushingResponseTotalTimeMonitor = MonitorFactory .start("GeoEngine.drawMapAction.flushResponse.totalTime"); writeBackToClient(maptmpfile, encoder, inlineResponse, responseFileName, getContentType(outputFormat)); } catch (IOException e) { logger.error("error while flushing output", e); if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceErrorEvent("Error while flushing output"); throw new DrawMapServiceException(getActionName(), "Error while flushing output", e); } if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceEndEvent(); maptmpfile.delete(); if (tmpFile != null) tmpFile.delete(); } catch (Throwable t) { errorHitsMonitor = MonitorFactory.start("GeoEngine.errorHits"); errorHitsMonitor.stop(); DrawMapServiceException wrappedException; if (t instanceof DrawMapServiceException) { wrappedException = (DrawMapServiceException) t; } else { wrappedException = new DrawMapServiceException(getActionName(), "An unpredicted error occurred while executing " + getActionName() + " service", t); } wrappedException.setDescription(wrappedException.getRootCause()); Throwable rootException = wrappedException.getRootException(); if (rootException instanceof SpagoBIEngineRuntimeException) { wrappedException.setHints(((SpagoBIEngineRuntimeException) rootException).getHints()); } throw wrappedException; } finally { if (flushingResponseTotalTimeMonitor != null) flushingResponseTotalTimeMonitor.stop(); if (totalTimePerFormatMonitor != null) totalTimePerFormatMonitor.stop(); if (totalTimeMonitor != null) totalTimeMonitor.stop(); } logger.debug("OUT"); }
From source file:it.eng.spagobi.engines.geo.service.initializer.ExecutionProxyGeoEngineStartAction.java
License:Mozilla Public License
public void service(SourceBean serviceRequest, SourceBean serviceResponse) throws GeoEngineException { GeoEngineInstance geoEngineInstance; Map env;/* w ww. ja v a 2 s .c om*/ byte[] analysisStateRowData; GeoEngineAnalysisState analysisState = null; String executionContext; String executionId; String documentLabel; String outputType; Monitor hitsPrimary = null; Monitor hitsByDate = null; Monitor hitsByUserId = null; Monitor hitsByDocumentId = null; Monitor hitsByExecutionContext = null; logger.debug("IN"); try { setEngineName(ENGINE_NAME); super.service(serviceRequest, serviceResponse); //if(true) throw new SpagoBIEngineStartupException(getEngineName(), "Test exception"); logger.debug("User Id: " + getUserId()); logger.debug("Audit Id: " + getAuditId()); logger.debug("Document Id: " + getDocumentId()); logger.debug("Template: " + getTemplateAsSourceBean()); hitsPrimary = MonitorFactory.startPrimary("GeoEngine.requestHits"); hitsByDate = MonitorFactory.start( "GeoEngine.requestHits." + DateFormat.getDateInstance(DateFormat.SHORT).format(new Date())); hitsByUserId = MonitorFactory.start("GeoEngine.requestHits." + getUserId()); hitsByDocumentId = MonitorFactory.start("GeoEngine.requestHits." + getDocumentId()); executionContext = getAttributeAsString(EXECUTION_CONTEXT); logger.debug("Parameter [" + EXECUTION_CONTEXT + "] is equal to [" + executionContext + "]"); executionId = getAttributeAsString(EXECUTION_ID); logger.debug("Parameter [" + EXECUTION_ID + "] is equal to [" + executionId + "]"); documentLabel = getAttributeAsString(DOCUMENT_LABEL); logger.debug("Parameter [" + DOCUMENT_LABEL + "] is equal to [" + documentLabel + "]"); outputType = getAttributeAsString(OUTPUT_TYPE); logger.debug("Parameter [" + OUTPUT_TYPE + "] is equal to [" + outputType + "]"); logger.debug("Execution context: " + executionContext); String isDocumentCompositionModeActive = (executionContext != null && executionContext.equalsIgnoreCase("DOCUMENT_COMPOSITION")) ? "TRUE" : "FALSE"; logger.debug("Document composition mode active: " + isDocumentCompositionModeActive); hitsByExecutionContext = MonitorFactory.start("GeoEngine.requestHits." + (isDocumentCompositionModeActive.equalsIgnoreCase("TRUE") ? "compositeDocument" : "singleDocument")); env = getEnv("TRUE".equalsIgnoreCase(isDocumentCompositionModeActive), documentLabel, executionId); if (outputType != null) { env.put(GeoEngineConstants.ENV_OUTPUT_TYPE, outputType); } geoEngineInstance = GeoEngine.createInstance(getTemplateAsSourceBean(), env); geoEngineInstance.setAnalysisMetadata(getAnalysisMetadata()); analysisStateRowData = getAnalysisStateRowData(); if (analysisStateRowData != null) { logger.debug("AnalysisStateRowData: " + new String(analysisStateRowData)); analysisState = new GeoEngineAnalysisState(); analysisState.load(analysisStateRowData); logger.debug("AnalysisState: " + analysisState.toString()); } else { logger.debug("AnalysisStateRowData: NULL"); } if (analysisState != null) { geoEngineInstance.setAnalysisState(analysisState); } String selectedMeasureName = getAttributeAsString("default_kpi"); logger.debug("Parameter [" + "default_kpi" + "] is equal to [" + selectedMeasureName + "]"); if (!StringUtilities.isEmpty(selectedMeasureName)) { geoEngineInstance.getMapRenderer().setSelectedMeasureName(selectedMeasureName); } if ("TRUE".equalsIgnoreCase(isDocumentCompositionModeActive)) { setAttribute(DynamicPublisher.PUBLISHER_NAME, "SIMPLE_UI_PUBLISHER"); } else { setAttribute(DynamicPublisher.PUBLISHER_NAME, "AJAX_UI_PUBLISHER"); } String id = getAttributeAsString("SBI_EXECUTION_ID"); setAttributeInSession(GEO_ENGINE_INSTANCE, geoEngineInstance); } catch (Exception e) { SpagoBIEngineStartupException serviceException = null; if (e instanceof SpagoBIEngineStartupException) { serviceException = (SpagoBIEngineStartupException) e; } else { Throwable rootException = e; while (rootException.getCause() != null) { rootException = rootException.getCause(); } String str = rootException.getMessage() != null ? rootException.getMessage() : rootException.getClass().getName(); String message = "An unpredicted error occurred while executing " + getEngineName() + " service." + "\nThe root cause of the error is: " + str; serviceException = new SpagoBIEngineStartupException(getEngineName(), message, e); } throw serviceException; } finally { if (hitsByExecutionContext != null) hitsByExecutionContext.stop(); if (hitsByDocumentId != null) hitsByDocumentId.stop(); if (hitsByUserId != null) hitsByUserId.stop(); if (hitsByDate != null) hitsByDate.stop(); if (hitsPrimary != null) hitsPrimary.stop(); } // Put draw Map Action String outputFormat = null; File maptmpfile = null; boolean inlineResponse; String responseFileName; Monitor totalTimeMonitor = null; Monitor totalTimePerFormatMonitor = null; Monitor flushingResponseTotalTimeMonitor = null; Monitor errorHitsMonitor = null; logger.debug("IN"); try { super.service(serviceRequest, serviceResponse); totalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.totalTime"); //executionId = getAttributeAsString( "SBI_EXECUTION_ID" ); outputFormat = getAttributeAsString(OUTPUT_FORMAT); logger.debug("Parameter [" + OUTPUT_FORMAT + "] is equal to [" + outputFormat + "]"); inlineResponse = getAttributeAsBoolean(INLINE_RESPONSE, true); logger.debug("Parameter [" + INLINE_RESPONSE + "] is equal to [" + inlineResponse + "]"); if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceStartEvent(); IEngineInstance iEngInst = (IEngineInstance) getAttributeFromSession(EngineConstants.ENGINE_INSTANCE); GeoEngineInstance geoInstance = (GeoEngineInstance) iEngInst; if (outputFormat == null) { logger.info("Parameter [" + outputFormat + "] not specified into request"); //outputFormat = (String)((GeoEngineInstance)).getEnv().get(GeoEngineConstants.ENV_OUTPUT_TYPE); outputFormat = (String) geoInstance.getEnv().get(GeoEngineConstants.ENV_OUTPUT_TYPE); logger.debug("Env Parameter [" + GeoEngineConstants.ENV_OUTPUT_TYPE + "] is equal to [" + outputFormat + "]"); } if (outputFormat == null) { logger.info( "Parameter [" + GeoEngineConstants.ENV_OUTPUT_TYPE + "] not specified into environment"); outputFormat = DEFAULT_OUTPUT_TYPE; } totalTimePerFormatMonitor = MonitorFactory .start("GeoEngine.drawMapAction." + outputFormat + "totalTime"); try { if (outputFormat.equalsIgnoreCase(GeoEngineConstants.PDF)) { maptmpfile = geoInstance.renderMap(GeoEngineConstants.JPEG); } else { maptmpfile = geoInstance.renderMap(outputFormat); } } catch (Throwable t) { throw new DrawMapServiceException(getActionName(), "Impossible to render map", t); } responseFileName = "map.svg"; IStreamEncoder encoder = null; File tmpFile = null; if (outputFormat.equalsIgnoreCase(GeoEngineConstants.JPEG)) { encoder = new SVGMapConverter(); responseFileName = "map.jpeg"; } else if (outputFormat.equalsIgnoreCase(GeoEngineConstants.PDF)) { encoder = new SVGMapConverter(); BufferedInputStream bis = null; String dirS = System.getProperty("java.io.tmpdir"); File imageFile = null; bis = new BufferedInputStream(new FileInputStream(maptmpfile)); try { int contentLength = 0; int b = -1; String contentFileName = "tempJPEGExport"; freezeHttpResponse(); File dir = new File(dirS); imageFile = File.createTempFile("tempJPEGExport", ".jpeg", dir); FileOutputStream stream = new FileOutputStream(imageFile); encoder.encode(bis, stream); stream.flush(); stream.close(); File dirF = new File(dirS); tmpFile = File.createTempFile("tempPDFExport", ".pdf", dirF); Document pdfDocument = new Document(); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(tmpFile)); pdfDocument.open(); Image jpg = Image.getInstance(imageFile.getPath()); jpg.setRotation(new Double(Math.PI / 2).floatValue()); jpg.scaleAbsolute(770, 520); pdfDocument.add(jpg); pdfDocument.close(); docWriter.close(); maptmpfile = tmpFile; } finally { bis.close(); if (imageFile != null) imageFile.delete(); } responseFileName = "map.pdf"; encoder = null; } try { flushingResponseTotalTimeMonitor = MonitorFactory .start("GeoEngine.drawMapAction.flushResponse.totalTime"); writeBackToClient(maptmpfile, encoder, inlineResponse, responseFileName, getContentType(outputFormat)); } catch (IOException e) { logger.error("error while flushing output", e); if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceErrorEvent("Error while flushing output"); throw new DrawMapServiceException(getActionName(), "Error while flushing output", e); } if (getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceEndEvent(); maptmpfile.delete(); if (tmpFile != null) tmpFile.delete(); } catch (Throwable t) { errorHitsMonitor = MonitorFactory.start("GeoEngine.errorHits"); errorHitsMonitor.stop(); DrawMapServiceException wrappedException; if (t instanceof DrawMapServiceException) { wrappedException = (DrawMapServiceException) t; } else { wrappedException = new DrawMapServiceException(getActionName(), "An unpredicted error occurred while executing " + getActionName() + " service", t); } wrappedException.setDescription(wrappedException.getRootCause()); Throwable rootException = wrappedException.getRootException(); if (rootException instanceof SpagoBIEngineRuntimeException) { wrappedException.setHints(((SpagoBIEngineRuntimeException) rootException).getHints()); } throw wrappedException; } finally { if (flushingResponseTotalTimeMonitor != null) flushingResponseTotalTimeMonitor.stop(); if (totalTimePerFormatMonitor != null) totalTimePerFormatMonitor.stop(); if (totalTimeMonitor != null) totalTimeMonitor.stop(); } logger.debug("OUT"); logger.debug("OUT"); }
From source file:it.eng.spagobi.engines.worksheet.services.export.ExportChartAction.java
License:Mozilla Public License
/** * Set the dimension of the image to fit the A4 page size * The layout of the page should be horizontal * @param jpg the image to fit/*w ww .j a v a 2 s . co m*/ */ private void fitImage(Image jpg) { if (jpg.getWidth() > PageSize.A4.getHeight()) { float imgScaledWidth = PageSize.A4.getHeight() - 100; float imgScaledHeight = (imgScaledWidth / jpg.getWidth()) * jpg.getHeight(); jpg.scaleAbsolute(imgScaledWidth, imgScaledHeight); } if (jpg.getHeight() > PageSize.A4.getWidth()) { float imgScaledHeight = PageSize.A4.getWidth() - 100; float imgScaledWidth = (imgScaledHeight / jpg.getHeight()) * jpg.getWidth(); jpg.scaleAbsolute(imgScaledWidth, imgScaledHeight); } }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private com.lowagie.text.Image awtImageToImage(java.awt.Image awtImage, jdbreport.model.Cell srcCell, float w, float h) throws BadElementException, IOException { com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(awtImage, null); boolean scaled = srcCell.isScaleIcon(); double kx = 1.0 / GraphicUtil.getScreenScaleX(); double ky = 1.0 / GraphicUtil.getScreenScaleY(); float imageWidth = (float) (image.getWidth() * kx); float imageHeight = (float) (image.getHeight() * ky); if (!scaled) { if (imageWidth < w) { w = imageWidth;//ww w . j a v a2 s. c o m } if (imageHeight < h) { h = imageHeight; } } if (imageWidth >= w || imageHeight >= h) { scaled = true; } if (scaled) { image.scaleAbsolute(w - 2, h - 2); } return image; }