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:org.sonar.report.pdf.entity.ComplexityDistribution.java

License:Open Source License

public Image getGraphic() {
    Image image = null;/*from w w w. j  av  a2s  .com*/
    try {
        if (yValues.length != 0) {
            image = Image.getInstance(sonarBaseUrl + "/chart?cht=cvb&chdi=300x200&chca=" + formatXValues()
                    + "&chov=y&chrav=y&chv=" + formatYValues()
                    + "&chorgv=y&chcaaml=0.05&chseamu=0.2&chins=5&chcaamu=0.05&chcav=y&chc=777777,777777,777777,777777,777777,777777,777777");
            image.setAlignment(Image.ALIGN_MIDDLE);
        }
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return image;
}

From source file:org.sonar.report.pdf.entity.RadarGraphic.java

License:Open Source License

public Image getGraphic() {
    Image image = null;//w  w  w  .  j  a va 2 s. co  m
    try {
        String requestUrl = sonarUrl + "/chart?ck=xradar&w=210&h=110&c=777777|F8A036&m=100&g=0.25&" + "l=Eff.("
                + efficiency + "%25),Mai.(" + maintainability + "%25),Por.(" + portability + "%25),Rel.("
                + reliavility + "%25),Usa.(" + usability + "%25)&" + "v=" + efficiency + "," + maintainability
                + "," + portability + "," + reliavility + "," + usability;
        Logger.debug("Getting radar graphic: " + requestUrl);
        image = Image.getInstance(requestUrl);
        image.setAlignment(Image.ALIGN_MIDDLE);
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return image;
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

@Override
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter)
        throws org.dom4j.DocumentException, ReportException {
    try {/*from w  ww  . j a va  2s .co  m*/
        URL largeLogo;
        if (super.getConfigProperty("front.page.logo").startsWith("http://")) {
            largeLogo = new URL(super.getConfigProperty("front.page.logo"));
        } else {
            largeLogo = this.getClass().getClassLoader()
                    .getResource(super.getConfigProperty("front.page.logo"));
        }
        Image logoImage = Image.getInstance(largeLogo);
        logoImage.scaleAbsolute(360, 200);
        Rectangle pageSize = frontPageDocument.getPageSize();
        logoImage.setAbsolutePosition(Style.FRONTPAGE_LOGO_POSITION_X, Style.FRONTPAGE_LOGO_POSITION_Y);
        frontPageDocument.add(logoImage);

        PdfPTable title = new PdfPTable(1);
        title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        title.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String projectRow = super.getProject().getName();
        String versionRow = super.getProject().getMeasures().getVersion();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateRow = df.format(super.getProject().getMeasures().getDate());
        String descriptionRow = super.getProject().getDescription();

        title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(versionRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2));
        title.addCell(new Phrase(super.getProject().getMeasure(MetricKeys.PROFILE).getDataValue(),
                Style.FRONTPAGE_FONT_3));
        title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3));
        title.setTotalWidth(
                pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin());
        title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), Style.FRONTPAGE_LOGO_POSITION_Y - 150,
                frontPageWriter.getDirectContent());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.report.pdf.Header.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {/* w  w  w .  ja  v a 2 s  .com*/
        Image logoImage = Image.getInstance(logo);
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(4);
        head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE);
        head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
        head.addCell(logoImage);
        Phrase projectName = new Phrase(project.getName(),
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY));
        Phrase phrase = new Phrase("Sonar PDF Report",
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY));
        head.getDefaultCell().setColspan(2);
        head.addCell(phrase);
        head.getDefaultCell().setColspan(1);
        head.addCell(projectName);
        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent());
        head.setSpacingAfter(10);
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.report.pdf.PDFReporter.java

License:Open Source License

public Image getTendencyImage(int tendencyQualitative, int tendencyCuantitative) {
    // tendency parameters are t_qual and t_quant tags returned by webservices api
    String iconName;/*w ww  .jav  a2  s  .  com*/
    if (tendencyQualitative == 0) {
        switch (tendencyCuantitative) {
        case -2:
            iconName = "-2-black.png";
            break;
        case -1:
            iconName = "-1-black.png";
            break;
        case 1:
            iconName = "1-black.png";
            break;
        case 2:
            iconName = "2-black.png";
            break;
        default:
            iconName = "none.png";
        }
    } else {
        switch (tendencyQualitative) {
        case -2:
            iconName = "-2-red.png";
            break;
        case -1:
            iconName = "-1-red.png";
            break;
        case 1:
            iconName = "1-green.png";
            break;
        case 2:
            iconName = "2-green.png";
            break;
        default:
            iconName = "none.png";
        }
    }
    Image tendencyImage = null;
    try {
        tendencyImage = Image.getInstance(this.getClass().getResource("/tendency/" + iconName));
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return tendencyImage;
}

From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java

License:Open Source License

private void printChapterSection(ChapterAutoNumber chapter, String sectionName)
        throws DocumentException, IOException {
    String sectionDisplayName = getTextProperty("extendedpdf." + sectionName);
    String imagePath = screenshotsDir + File.separator + sectionName + ".png";
    File file = new File(imagePath);
    if (file.exists() && !file.isDirectory()) {
        Section section = chapter.addSection(new Paragraph(sectionDisplayName, Style.TITLE_FONT));
        Image image = Image.getInstance(imagePath);
        section.add(image);/*from   ww  w. j av  a  2s.  c o  m*/
        section.add(Chunk.NEWLINE);
    }
}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

public void writeImage(String image, String legend, AppElement element) {
    Section section = sections.size() > 0 ? sections.peek() : chapter;

    URL url = this.getClass().getResource(image);
    if (url == null)
        return;/*from ww  w. jav a2s. c o  m*/

    try {
        Image img = Image.getInstance(url);
        if (img != null) {
            img.scaleToFit(document.getPageSize().getWidth() - 100, document.getPageSize().getHeight() - 100);
            section.add(img);
            if (legend != null)
                writeParagraph(legend, element);
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot add given image to document", e);
    }
}

From source file:org.unitime.timetable.export.rooms.RoomsExportPDF.java

License:Apache License

protected A getCell(RoomDetailInterface room, Column column, ExportContext context) {
    switch (column.getColumn()) {
    case NAME:/*from  ww w  .jav  a  2s  .c o m*/
        A a = new A(room.hasDisplayName() ? MESSAGES.label(room.getLabel(), room.getDisplayName())
                : room.getLabel());
        for (DepartmentInterface d : room.getDepartments())
            if (d.getDeptCode().equals(context.getDepartment()) && d.getPreference() != null)
                a.setColor(d.getPreference().getColor());
        return a;

    case EXTERNAL_ID:
        return new A(room.hasExternalId() ? room.getExternalId() : "");

    case TYPE:
        return new A(room.getRoomType().getLabel());

    case CAPACITY:
        return new A(room.getCapacity() == null ? "0" : room.getCapacity().toString()).right();

    case EXAM_CAPACITY:
        return new A(room.getExamCapacity() == null ? "" : room.getExamCapacity().toString()).right();

    case AREA:
        return new A(room.getArea() == null ? "" : context.getAreaFormat().format(room.getArea())).right();

    case COORDINATES:
        return new A(
                room.hasCoordinates()
                        ? context.getCoordinateFormat().format(room.getX()) + ","
                                + context.getCoordinateFormat().format(room.getY())
                        : "");

    case ROOM_CHECK:
        return new A(room.isIgnoreRoomCheck() ? MESSAGES.exportFalse() : MESSAGES.exportTrue());

    case DISTANCE_CHECK:
        return new A(room.isIgnoreTooFar() ? MESSAGES.exportFalse() : MESSAGES.exportTrue());

    case PREFERENCE:
        if (!room.hasDepartments())
            return new A();
        a = new A();
        for (DepartmentInterface d : room.getDepartments()) {
            if (d.getPreference() == null)
                continue;
            a.add(new A(d.getPreference().getAbbv() + " " + context.dept2string(d, true))
                    .color(d.getPreference().getColor()));
        }
        return a;

    case MAP:
        if (room.hasMiniMapUrl()) {
            try {
                Image image = Image.getInstance(new URL(room.getMiniMapUrl()));
                image.scaleToFit(150f, 100f);
                image.setBorder(Rectangle.BOX);
                image.setBorderWidth(1f);
                image.setBorderColor(new Color(Integer.parseInt("9CB0CE", 16)));
                return new A(image);
            } catch (Exception e) {
                return new A();
            }
        } else {
            return new A();
        }

    case PICTURES:
        AttachmentTypeInterface type = (column.getIndex() == 0 ? null
                : context.getPictureTypes().get(column.getIndex() - 1));
        if (room.hasPictures(type)) {
            a = new A();
            for (RoomPictureInterface picture : room.getPictures(type)) {
                RoomPicture rp = RoomPictureDAO.getInstance().get(picture.getUniqueId());
                if (rp != null) {
                    try {
                        Image image = Image.getInstance(rp.getDataFile());
                        image.scaleToFit(150f, 100f);
                        image.setBorder(Rectangle.BOX);
                        image.setBorderWidth(1f);
                        image.setBorderColor(new Color(Integer.parseInt("9CB0CE", 16)));
                        a.add(new A(image));
                    } catch (Exception e) {
                    }
                }
            }
            return a;
        } else {
            return new A();
        }

    case AVAILABILITY:
        return availability(room, false, context);

    case DEPARTMENTS:
        if (!room.hasDepartments())
            return new A();
        if (context.isAllDepartments(room.getDepartments()))
            return new A(MESSAGES.departmentsAllLabel()).set(F.ITALIC);
        a = new A();
        for (DepartmentInterface d : room.getDepartments()) {
            A b = new A(context.dept2string(d, true)).color(d.getColor());
            if (d.equals(room.getControlDepartment()))
                b.underline();
            a.add(b);
        }
        return a;

    case CONTROL_DEPT:
        return new A(context.dept2string(room.getControlDepartment(), true))
                .color(room.getControlDepartment() == null ? null : room.getControlDepartment().getColor());

    case EXAM_TYPES:
        if (!room.hasExamTypes())
            return new A();
        a = new A();
        for (ExamTypeInterface t : room.getExamTypes()) {
            a.add(new A(t.getLabel()));
        }
        return a;

    case PERIOD_PREF:
        return periodPreferences(room, context);

    case EVENT_DEPARTMENT:
        return new A(context.dept2string(room.getEventDepartment(), false))
                .color(room.getEventDepartment() == null ? null : room.getEventDepartment().getColor());

    case EVENT_STATUS:
        return room.getEventStatus() != null ? new A(CONSTANTS.eventStatusAbbv()[room.getEventStatus()])
                : room.getDefaultEventStatus() != null
                        ? new A(CONSTANTS.eventStatusAbbv()[room.getDefaultEventStatus()]).italic()
                        : new A();

    case EVENT_AVAILABILITY:
        return availability(room, true, context);

    case EVENT_MESSAGE:
        return room.getEventNote() != null ? new A(room.getEventNote())
                : new A(room.getDefaultEventNote()).italic();

    case BREAK_TIME:
        return room.getBreakTime() != null ? new A(room.getBreakTime().toString())
                : room.getDefaultBreakTime() != null ? new A(room.getDefaultBreakTime().toString()).italic()
                        : new A();

    case GROUPS:
        if (!room.hasGroups())
            return new A();
        a = new A();
        for (GroupInterface g : room.getGroups()) {
            a.add(new A(g.getLabel() + (g.getDepartment() == null ? ""
                    : " (" + context.dept2string(g.getDepartment(), true) + ")"))
                            .color(g.getDepartment() == null ? null : g.getDepartment().getColor()));
        }
        return a;

    case FEATURES:
        if (column.getIndex() == 0)
            return features(room.getFeatures(), null, context);
        else
            return features(room.getFeatures(), context.getRoomFeatureTypes().get(column.getIndex() - 1),
                    context);

    default:
        return null;
    }
}

From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java

License:Open Source License

public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception {
    if (text == null)
        return;/*from   w w w  . jav a  2  s  .  co  m*/
    if (text.indexOf("<span") >= 0)
        text = text.replaceAll("</span>", "").replaceAll("<span .*>", "");
    Font font = PdfFont.getFont(bold);
    BaseFont bf = font.getBaseFont();
    float width = bf.getWidthPoint(text, font.getSize());
    PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
    template.beginText();
    template.setColorFill(Color.BLACK);
    template.setFontAndSize(bf, font.getSize());
    template.setTextMatrix(0, 2);
    template.showText(text);
    template.endText();
    template.setWidth(width);
    template.setHeight(font.getSize() + 2);
    //make an Image object from the template
    Image img = Image.getInstance(template);
    img.setRotationDegrees(270);
    //embed the image in a Chunk
    Chunk ck = new Chunk(img, 0, 0);

    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(ck));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    } else {
        cell.getPhrase().add(ck);
    }
}

From source file:org.viafirma.util.QRCodeUtil.java

License:Apache License

/**
 * Genera un nuevo pdf con la imagen firmada y el pie de firma.
 * @param url Url desde la que se puede descargar el documeto
 *///from   w w  w .j  a v  a 2 s  . c o m
public void generarImagenPdf(byte[] input, String texto, String url, String textoQR, String codFirma,
        OutputStream out) throws ExcepcionErrorInterno {
    try {
        // Nuevo Documento PDF
        Document document = new Document();

        // Obtenemos el tamao de la pgina
        Rectangle pageSize = document.getPageSize();

        PdfWriter.getInstance(document, out);
        document.open();
        addContent(texto, url, textoQR, codFirma, document, pageSize, true, false);

        // Aadimos imagen original
        Image imagen = Image.getInstance(input);
        imagen.setBorder(10);
        imagen.scaleToFit(500, 500);
        imagen.setAbsolutePosition(50, pageSize.getHeight() - 400);
        document.add(imagen);

        // Cerramos el documento
        document.close();

    } catch (Exception e) {
        throw new ExcepcionErrorInterno(CodigoError.ERROR_INTERNO, e);
    }

}