Example usage for com.lowagie.text Phrase Phrase

List of usage examples for com.lowagie.text Phrase Phrase

Introduction

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

Prototype

public Phrase(float leading, String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:net.algem.security.UserCtrl.java

License:Open Source License

private File getFollowUpAsPDF(String userId, String from, String to)
        throws IOException, BadElementException, DocumentException {
    String path = "/tmp/" + "suivi-" + userId + ".pdf";
    File f = new File(path);
    LOGGER.log(Level.INFO, f.getName());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(document, byteArrayOutputStream); // Do this BEFORE document.open()
    document.open();/*from w  ww  . j  a v  a  2  s .  c o m*/

    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1.1f, 1.2f, 0.6f, 1.5f, 1.5f, 2f, 0.5f, 0.5f, 1.9f, 1.9f });

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
    BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, false);
    Font normalFont = new Font(bf, 10);
    Font boldFont = new Font(bfb, 10);

    String fromLabel = messageSource.getMessage("from.label", null, CTX_LOCALE);
    String toLabel = messageSource.getMessage("to.label", null, CTX_LOCALE);
    String prefix = messageSource.getMessage("follow-up.label", null, CTX_LOCALE) + " "
            + organization.get("name.label");
    String period = fromLabel.toLowerCase() + " " + from + " " + toLabel.toLowerCase() + " " + to;
    PdfPCell headerCell = new PdfPCell(new Phrase(prefix + " " + period, boldFont));

    headerCell.setBackgroundColor(Color.LIGHT_GRAY);
    headerCell.setColspan(10);
    table.addCell(headerCell);

    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("date.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("time.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("time.length.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("room.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("course.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("teacher.label", null, CTX_LOCALE), boldFont)));
    String abs = messageSource.getMessage("absence.label", null, CTX_LOCALE);
    table.addCell(new PdfPCell(new Phrase(abs != null ? abs.substring(0, 3) + "." : "", boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("score.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("individual.logbook.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("collective.comment.label", null, CTX_LOCALE), boldFont)));

    fillPdfTable(table, getFollowUpSchedules(userId, from, to), normalFont);

    document.add(table);
    document.close();
    byte[] pdfBytes = byteArrayOutputStream.toByteArray();
    Files.write(Paths.get(path), pdfBytes);
    return f;
}

From source file:net.algem.security.UserCtrl.java

License:Open Source License

private void fillPdfTable(PdfPTable table, List<ScheduleElement> items, Font font) {
    for (ScheduleElement e : items) {
        List<ScheduleRangeElement> ranges = new ArrayList<ScheduleRangeElement>(
                (Collection<? extends ScheduleRangeElement>) e.getRanges());

        for (ScheduleRangeElement r : ranges) {
            String status = CommonDao.getAbsenceFromNumberStatus(r.getFollowUp().getStatus());
            String note = r.getFollowUp().getNote();
            String content1 = r.getFollowUp().getContent();
            String content2 = e.getFollowUp().getContent();
            table.addCell(new Phrase(e.getDateFr().toString(), font));
            table.addCell(new Phrase(r.getStart() + "-" + r.getEnd(), font));
            table.addCell(new Phrase(new Hour(r.getLength()).toString(), font));
            table.addCell(new Phrase(e.getDetail().get("room").getName(), font));
            table.addCell(new Phrase(e.getDetail().get("course").getName(), font));
            table.addCell(new Phrase(e.getDetail().get("teacher").getName(), font));
            table.addCell(new Phrase(status, font));
            table.addCell(new Phrase(note == null ? "" : note, font));
            table.addCell(new Phrase(content1 == null ? "" : content1.replaceAll("[\r\n]", " "), font));
            table.addCell(new Phrase(content2 == null ? "" : content2.replaceAll("[\r\n]", " "), font));
        }//ww  w.j  av  a  2  s.  c o m
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfAbstractTableReport.java

License:Apache License

void initTable(List<String> headers, int[] relativeWidths) throws DocumentException {
    assert headers.size() == relativeWidths.length;
    final PdfPTable mytable = new PdfPTable(headers.size());
    mytable.setWidthPercentage(100);/*from   ww  w  .  j a v a  2s . c o  m*/
    mytable.setWidths(relativeWidths);
    mytable.setHeaderRows(1);
    final PdfPCell defaultCell = mytable.getDefaultCell();
    defaultCell.setGrayFill(0.9f);
    defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    defaultCell.setPaddingLeft(0);
    defaultCell.setPaddingRight(0);
    final Font tableHeaderFont = PdfFonts.TABLE_HEADER.getFont();
    for (final String header : headers) {
        mytable.addCell(new Phrase(header, tableHeaderFont));
    }
    defaultCell.setPaddingLeft(2);
    defaultCell.setPaddingRight(2);
    this.table = mytable;
}

From source file:net.bull.javamelody.internal.web.pdf.PdfAbstractTableReport.java

License:Apache License

void addCell(String string) {
    table.addCell(new Phrase(string, cellFont));
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

@Override
void toPdf() throws IOException, DocumentException {
    addParagraph(buildSummary(), "systemmonitor.png");
    writeGraphs(collector.getDisplayedCounterJRobins(), smallGraphs);

    final List<Counter> counters = collector.getRangeCountersToBeDisplayed(counterRange);
    final List<PdfCounterReport> pdfCounterReports = writeCounters(counters);

    final List<PdfCounterRequestContextReport> pdfCounterRequestContextReports = new ArrayList<PdfCounterRequestContextReport>();
    if (!collectorServer) {
        addParagraph(getString("Requetes_en_cours"), "hourglass.png");
        // si on n'est pas sur le serveur de collecte il n'y a qu'un javaInformations
        pdfCounterRequestContextReports//from   ww  w.  j a v  a2 s . c  o  m
                .addAll(writeCurrentRequests(javaInformationsList.get(0), counters, pdfCounterReports));
    }

    addToDocument(new Phrase("\n", normalFont));
    addParagraph(getString("Informations_systemes"), "systeminfo.png");
    new PdfJavaInformationsReport(javaInformationsList, getDocument()).toPdf();

    addParagraph(getString("Threads"), "threads.png");
    writeThreads(false);

    PdfCounterReport pdfJobCounterReport = null;
    Counter rangeJobCounter = null;
    if (isJobEnabled()) {
        rangeJobCounter = collector.getRangeCounter(counterRange, Counter.JOB_COUNTER_NAME);
        addToDocument(new Phrase("\n", normalFont));
        addParagraph(getString("Jobs"), "jobs.png");
        writeJobs(rangeJobCounter, false);
        pdfJobCounterReport = writeCounter(rangeJobCounter);
    }

    if (isCacheEnabled()) {
        addToDocument(new Phrase("\n", normalFont));
        addParagraph(getString("Caches"), "caches.png");
        writeCaches(false);
    }

    newPage();
    addParagraph(getString("Statistiques_detaillees"), "systemmonitor.png");
    writeGraphs(collector.getDisplayedOtherJRobins(), smallOtherGraphs);
    writeGraphDetails();

    writeCountersDetails(pdfCounterReports);

    if (!collectorServer) {
        addParagraph(getString("Requetes_en_cours_detaillees"), "hourglass.png");
        // si on n'est pas sur le serveur de collecte il n'y a qu'un javaInformations
        writeCurrentRequestsDetails(pdfCounterRequestContextReports);
    }

    addParagraph(getString("Informations_systemes_detaillees"), "systeminfo.png");
    new PdfJavaInformationsReport(javaInformationsList, getDocument()).writeInformationsDetails();

    addParagraph(getString("Threads_detailles"), "threads.png");
    writeThreads(true);

    if (isJobEnabled()) {
        addToDocument(new Phrase("\n", normalFont));
        addParagraph(getString("Jobs_detailles"), "jobs.png");
        writeJobs(rangeJobCounter, true);
        writeCounterDetails(pdfJobCounterReport);
    }

    if (isCacheEnabled()) {
        addToDocument(new Phrase("\n", normalFont));
        addParagraph(getString("Caches_detailles"), "caches.png");
        writeCaches(true);
    }

    writeDurationAndOverhead();
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private List<PdfCounterRequestContextReport> writeCurrentRequests(JavaInformations javaInformations,
        List<Counter> counters, List<PdfCounterReport> pdfCounterReports)
        throws IOException, DocumentException {
    final List<PdfCounterRequestContextReport> pdfCounterRequestContextReports = new ArrayList<PdfCounterRequestContextReport>();
    final List<CounterRequestContext> rootCurrentContexts;
    if (currentRequests == null) {
        rootCurrentContexts = collector.getRootCurrentContexts(counters);
    } else {//w  w w.  j  a va 2 s .c o  m
        rootCurrentContexts = currentRequests;
    }
    if (rootCurrentContexts.isEmpty()) {
        addToDocument(new Phrase(getString("Aucune_requete_en_cours"), normalFont));
    } else {
        final PdfCounterRequestContextReport pdfCounterRequestContextReport = new PdfCounterRequestContextReport(
                rootCurrentContexts, pdfCounterReports, javaInformations.getThreadInformationsList(),
                javaInformations.isStackTraceEnabled(), pdfDocumentFactory, getDocument());
        pdfCounterRequestContextReport.toPdf();
        pdfCounterRequestContextReports.add(pdfCounterRequestContextReport);
    }
    return pdfCounterRequestContextReports;
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private void writeCurrentRequestsDetails(List<PdfCounterRequestContextReport> pdfCounterRequestContextReports)
        throws IOException, DocumentException {
    for (final PdfCounterRequestContextReport pdfCounterRequestContextReport : pdfCounterRequestContextReports) {
        pdfCounterRequestContextReport.writeContextDetails();
    }/*from  w ww  .j av a 2s.co  m*/
    if (pdfCounterRequestContextReports.isEmpty()) {
        addToDocument(new Phrase(getString("Aucune_requete_en_cours"), normalFont));
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private void writeThreads(boolean includeDetails) throws DocumentException, IOException {
    String eol = "";
    for (final JavaInformations javaInformations : javaInformationsList) {
        addToDocument(new Phrase(eol, normalFont));
        final PdfThreadInformationsReport pdfThreadInformationsReport = new PdfThreadInformationsReport(
                javaInformations.getThreadInformationsList(), javaInformations.isStackTraceEnabled(),
                pdfDocumentFactory, getDocument());
        pdfThreadInformationsReport.writeIntro(javaInformations);
        pdfThreadInformationsReport.writeDeadlocks();

        if (includeDetails) {
            pdfThreadInformationsReport.toPdf();
        }// ww w  . j av  a  2 s.c  om
        eol = "\n";
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private void writeCaches(boolean includeDetails) throws DocumentException {
    String eol = "";
    for (final JavaInformations javaInformations : javaInformationsList) {
        if (!javaInformations.isCacheEnabled()) {
            continue;
        }/*from  w  w  w  . j  av a  2s. com*/
        final List<CacheInformations> cacheInformationsList = javaInformations.getCacheInformationsList();
        final String msg = getFormattedString("caches_sur", cacheInformationsList.size(),
                javaInformations.getHost(), javaInformations.getCurrentlyExecutingJobCount());
        addToDocument(new Phrase(eol + msg, boldFont));

        if (includeDetails) {
            new PdfCacheInformationsReport(cacheInformationsList, getDocument()).toPdf();
        }
        eol = "\n";
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private void writeJobs(Counter rangeJobCounter, boolean includeDetails) throws DocumentException, IOException {
    String eol = "";
    for (final JavaInformations javaInformations : javaInformationsList) {
        if (!javaInformations.isJobEnabled()) {
            continue;
        }//from  ww  w.  j av  a  2s.  co  m
        final List<JobInformations> jobInformationsList = javaInformations.getJobInformationsList();
        final String msg = getFormattedString("jobs_sur", jobInformationsList.size(),
                javaInformations.getHost(), javaInformations.getCurrentlyExecutingJobCount());
        addToDocument(new Phrase(eol + msg, boldFont));

        if (includeDetails) {
            new PdfJobInformationsReport(jobInformationsList, rangeJobCounter, getDocument()).toPdf();
        }
        eol = "\n";
    }
}