Example usage for com.lowagie.text Image getInstance

List of usage examples for com.lowagie.text Image getInstance

Introduction

In this page you can find the example usage for com.lowagie.text Image getInstance.

Prototype

public static Image getInstance(Image image) 

Source Link

Document

gets an instance of an Image

Usage

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  a va2 s. c om
    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  . j  av a2 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:it.eng.spagobi.engines.worksheet.exporter.WorkSheetPDFExporter.java

License:Mozilla Public License

private void setHeader(JSONObject header) {
    try {//w ww . ja  v a 2s.c  om
        String title = header.optString(TITLE);
        String imgName = header.optString(IMG);
        String imagePosition = header.optString(POSITION);
        Image image = null;
        if (imgName != null && !imgName.equals("") && !imgName.equals("null")) {
            File imageFile = getImage(imgName);
            if (!imageFile.exists() || !imageFile.isFile()) {
                logger.error("Image " + imgName + " not found!!!");
            } else {
                image = Image.getInstance(imageFile.getPath());
                fitImage(image, IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
                setHeaderImagePosition(image, imagePosition);
                pdfDocument.add(image);
            }
        }
        if (title != null && !title.trim().equals("") && !title.trim().equals("<br>")) {

            title = new String(title.getBytes("ISO-8859-1")); // workaround for encoding problem
            float[] titlePosition = getHeaderTitlePosition(image, imagePosition);
            addHtmlToPdfContentByte(title, titlePosition);

        }
    } catch (Exception e) {
        throw new RuntimeException("Error while adding header", e);
    }
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetPDFExporter.java

License:Mozilla Public License

private void setFooter(JSONObject footer) {
    try {/*from  w  w w.j  a v  a  2 s  . c om*/
        String title = footer.optString(TITLE);
        String imgName = footer.optString(IMG);
        String imagePosition = footer.optString(POSITION);
        Image image = null;
        if (imgName != null && !imgName.equals("") && !imgName.equals("null")) {
            File imageFile = getImage(imgName);
            if (!imageFile.exists() || !imageFile.isFile()) {
                logger.error("Image " + imgName + " not found!!!");
            } else {
                image = Image.getInstance(imageFile.getPath());
                fitImage(image, IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
                setFooterImagePosition(image, imagePosition);
                pdfDocument.add(image);
            }
        }
        if (title != null && !title.trim().equals("") && !title.trim().equals("<br>")) {

            title = new String(title.getBytes("ISO-8859-1")); // workaround for encoding problem
            float[] titlePosition = getFooterTitlePosition(image, imagePosition);
            addHtmlToPdfContentByte(title, titlePosition);

        }
    } catch (Exception e) {
        throw new RuntimeException("Error while adding header", e);
    }
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetPDFExporter.java

License:Mozilla Public License

private void addChart(File imageFile, JSONObject content, float[] margins)
        throws MalformedURLException, IOException, DocumentException {
    Image jpg = Image.getInstance(imageFile.getPath());

    float topMargin = margins[0];
    float bottomMargin = margins[1];

    float chartMaxHeight = PageSize.A4.getWidth() - (topMargin + bottomMargin); // remember that the page is A4 rotated
    float chartMaxWidth = PageSize.A4.getHeight() - (MARGIN_LEFT + MARGIN_RIGHT); // remember that the page is A4 rotated

    float[] newDimensions = fitImage(jpg, chartMaxWidth, chartMaxHeight);

    float positionX = (PageSize.A4.getHeight() - newDimensions[0]) / 2;
    float positionY = bottomMargin + (chartMaxHeight - newDimensions[1]) / 2; // center the image into the available height
    jpg.setAbsolutePosition(positionX, positionY);
    pdfDocument.add(jpg);//from w  w w  . j a  v a 2s. co  m
}

From source file:it.eng.spagobi.engines.worksheet.services.export.ExportChartAction.java

License:Mozilla Public License

private void transformSVGIntoPDF(InputStream inputStream, OutputStream outputStream)
        throws IOException, DocumentException {
    FileOutputStream imageFileOutputStream = null;
    File imageFile = null;/*from   w w w  . ja  va2 s  . c o m*/
    try {
        imageFile = File.createTempFile("chart", ".jpg");
        imageFileOutputStream = new FileOutputStream(imageFile);
        transformSVGIntoPNG(inputStream, imageFileOutputStream);

        Document pdfDocument = new Document(PageSize.A4.rotate());
        PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream);
        pdfDocument.open();
        Image jpg = Image.getInstance(imageFile.getPath());
        fitImage(jpg);

        pdfDocument.add(jpg);
        pdfDocument.close();
        docWriter.close();
    } finally {
        if (imageFileOutputStream != null) {
            try {
                imageFileOutputStream.close();
            } catch (IOException e) {
                logger.error(e);
            }
        }
        if (imageFile.exists()) {
            imageFile.delete();
        }
    }
}

From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LogInterface logger = getLogger(request);

    String titolo = request.getParameter("titolo");
    String descrizione = request.getParameter("descrizione");
    String scala = request.getParameter("scala");
    String mapx = request.getParameter("mapx");
    String mapy = request.getParameter("mapy");
    //creo URL alla mappa
    URL urlMappa = new URL(URLDecoder.decode(request.getParameter("urlMappa"), "UTF-8"));
    URI uriMappa = null;/*from w  ww.jav a2s.c  o m*/
    try {
        uriMappa = new URI(urlMappa.getProtocol(), null, urlMappa.getHost(), urlMappa.getPort(),
                urlMappa.getPath(), urlMappa.getQuery() + "&mode=map&scale=" + scala + "&mapxy=" + mapx + "+"
                        + mapy + "&map_size=500 500",
                null);
        logger.info("URI di stampa mappa: " + uriMappa);
    } catch (URISyntaxException e) {
        logger.error("URI errore di sintassi", e);
    }

    Font BOLD15 = new Font(Font.HELVETICA, 15, Font.BOLD);
    Font FONT12 = new Font(Font.HELVETICA, 12, Font.NORMAL);
    Font FONT10 = new Font(Font.HELVETICA, 10, Font.NORMAL);

    Document doc = new Document();
    ;
    PdfWriter pdf = null;
    Paragraph par = new Paragraph();

    try {

        //creo il PDF
        response.setContentType("application/pdf");
        pdf = PdfWriter.getInstance(doc, response.getOutputStream());

        //attributi file
        doc.addTitle("Mappa di Prato");
        doc.addAuthor("Comune di Prato");
        doc.open();

        //intestazione
        par.setAlignment(Paragraph.ALIGN_CENTER);
        print("Comune di Prato", BOLD15, par, doc);
        print(titolo, FONT10, par, doc);
        print("", FONT10, par, doc);

        //mappa
        Image mappa = Image.getInstance(uriMappa.toURL());
        mappa.setAlignment(Image.MIDDLE);
        mappa.setBorder(Rectangle.BOX);
        mappa.setBorderWidth(1f);
        doc.add(mappa);

    } catch (Exception e) {
        logger.error("Errore durante la creazione del PDF", e);
        printErr(doc);
    } finally {
        doc.close();
        pdf.close();
        response.getOutputStream().close();
    }
}

From source file:jm.nom.clas.Carnet.java

public void onEndPage(PdfWriter writer, Document document) {
    try {/*from  w  w  w .j  av  a2 s  .c  o  m*/
        //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\";
        Image imagelogo = Image.getInstance(_dir + "fondocarnet.jpg");
        imagelogo.scaleAbsolute(860, 625);//ancho, alto
        imagelogo.setAbsolutePosition(0, 10);
        document.add(imagelogo);
    } catch (DocumentException ex) {
        Logger.getLogger(pdfEmpleadosCarnets.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(pdfEmpleadosCarnets.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setLogo(String logo, int ancho, int alto) {
    PdfPCell celdaImg = null;/*from  ww w  .  j  a  v a 2  s  .  co  m*/
    try {
        Image imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(ancho, alto);
        celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setPadding(0);
    } catch (Exception e) {
        celdaImg = null;
    }
    return celdaImg;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setLogo(String logo, int ancho, int alto, int alineacion) {
    PdfPCell celdaImg = null;/*from  ww w.j av a2 s  .c  o  m*/
    try {
        Image imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(ancho, alto);
        celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setHorizontalAlignment(alineacion);
        celdaImg.setPadding(0);
    } catch (Exception e) {
        celdaImg = null;
    }
    return celdaImg;
}