List of usage examples for com.lowagie.text Image setRotation
public void setRotation(float r)
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;/* w w w . j a v a 2 s. co 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 w w . j av a 2 s. c o m*/ 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:org.mapfish.print.PDFUtils.java
License:Open Source License
public static Image createImage(RenderingContext context, double maxWidth, double maxHeight, URI url, float rotation) throws DocumentException { final Image image; try {// w w w . ja v a 2s . c o m image = getImage(context, url, (float) maxWidth, (float) maxHeight); } catch (IOException e) { throw new InvalidValueException("url", url.toString(), e); } if (rotation != 0.0F) { image.setRotation(rotation); } return image; }
From source file:org.posterita.businesslogic.administration.CustomerManager.java
License:Open Source License
public static String fidelityCard(Properties ctx, ArrayList<CustomerBean> customerList) throws OperationException { String reportName = RandomStringGenerator.randomstring() + ".pdf"; String reportPath = ReportManager.getReportPath(reportName); boolean shouldPrintCard = false; for (CustomerBean b : customerList) { if (b.getIsActive()) { shouldPrintCard = true;//from w w w . java2 s . c o m break; } } if (!shouldPrintCard) { throw new NoCustomerFoundException("Cannot print fidelity card. Cause no active customers were found."); } Document document = new Document(PageSize.A4, 3, 3, 2, 4);//l,r,t,b try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(reportPath)); // step 3: we open the document document.open(); PdfPTable main = new PdfPTable(2); main.setWidthPercentage(71.0f); main.getDefaultCell().setBorderColor(Color.gray); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(150.0f); Font smallFont = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD); //Font spaceFont = FontFactory.getFont(FontFactory.HELVETICA,6,Font.BOLD); //Font spaceFont2 = FontFactory.getFont(FontFactory.HELVETICA,15,Font.BOLD); //ResourceBundle rb = ResourceBundle.getBundle("MessageResources"); for (CustomerBean bean : customerList) { if (bean.getIsActive()) { String name = bean.getPartnerName(); String name1 = ""; String add2 = ""; String add1 = ""; String city = ""; if (bean.getAddress1() != null) add1 = bean.getAddress1(); if (bean.getAddress2() != null) add2 = bean.getAddress2(); if (bean.getCity() != null) city = bean.getCity(); String Address = " " + add1; String Add2 = " " + add2; String Add3 = " " + city; String BackPriv1Path = PathInfo.PROJECT_HOME + "/images/BackPriv1.jpg"; String backPriv2Path = PathInfo.PROJECT_HOME + "/images/backPriv2.jpg"; String frontImgPath = PathInfo.PROJECT_HOME + "/images/pc.png"; float WIDTH = 205; float HEIGHT = 135; Image Back1 = Image.getInstance(BackPriv1Path); Back1.scaleAbsolute(WIDTH - 40, HEIGHT / 3); Image Back2 = Image.getInstance(backPriv2Path); Back2.scaleAbsolute(WIDTH, HEIGHT / 3); Image frontImg = Image.getInstance(frontImgPath); frontImg.scaleAbsolute(WIDTH, HEIGHT); if (bean.getSurname() != null && bean.getSurname().trim().length() > 0) name1 = " " + name + " " + name1 + bean.getSurname(); byte[] barcode = BarcodeManager.getBarcodeAsByte(bean.getBpartnerId().toString()); Image barcodeImg = Image.getInstance(barcode); barcodeImg.setRotation(1.57f); barcodeImg.scaleAbsolute(HEIGHT - 55f, WIDTH / 5); //document.add(barcodeImg); PdfPTable card = new PdfPTable(2); card.getDefaultCell().setBorderWidth(0.0f); PdfPCell c = null; card.setWidthPercentage(50.0f); PdfPTable t = new PdfPTable(1); PdfPTable nametable = new PdfPTable(1); c = new PdfPCell(Back1); c.setBorderWidth(0.0f); nametable.addCell(c); c = new PdfPCell(new Phrase(name1, smallFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setVerticalAlignment(Element.ALIGN_CENTER); c.setBorderWidth(0.0f); nametable.addCell(c); c = new PdfPCell(new Phrase(Address, smallFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setVerticalAlignment(Element.ALIGN_CENTER); c.setBorderWidth(0.0f); //c.setColspan(2); nametable.addCell(c); c = new PdfPCell(new Phrase(Add2, smallFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setVerticalAlignment(Element.ALIGN_CENTER); c.setBorderWidth(0.0f); //c.setColspan(2); nametable.addCell(c); c = new PdfPCell(new Phrase(Add3, smallFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setVerticalAlignment(Element.ALIGN_CENTER); c.setBorderWidth(0.0f); //c.setColspan(2); nametable.addCell(c); //nametable.getDefaultCell(); nametable.getDefaultCell().setBorderWidth(0.0f); nametable.setHorizontalAlignment(Element.ALIGN_CENTER); card.addCell(nametable); c = new PdfPCell(barcodeImg); c.setBorderWidth(0.0f); //c.setColspan(2); c.setHorizontalAlignment(Element.ALIGN_RIGHT); c.setVerticalAlignment(Element.ALIGN_MIDDLE); c.setPadding(5.0f); card.addCell(c); c = new PdfPCell(Back2); c.setBorderWidth(0.0f); c.setColspan(2); card.addCell(c); c = new PdfPCell(new Phrase(name1, smallFont)); c.setBorderWidth(0.0f); t.addCell(c); c = new PdfPCell(new Phrase(Address, smallFont)); c.setBorderWidth(0.0f); t.addCell(c); c = new PdfPCell(new Phrase(Add3, smallFont)); c.setBorderWidth(0.0f); t.addCell(c); PdfPTable card1 = new PdfPTable(1); card.getDefaultCell().setBorderWidth(0.0f); PdfPCell c1 = null; card.setWidthPercentage(50.0f); c1 = new PdfPCell(frontImg); c1.setBorderWidth(0.0f); card1.addCell(c1); main.addCell(card); main.addCell(card1); } } document.add(main); } // TODO handle the following exception neatly catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); return reportName; }