Example usage for com.lowagie.text FontFactory getFont

List of usage examples for com.lowagie.text FontFactory getFont

Introduction

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

Prototype


public static Font getFont(String fontname, float size, int style, Color color) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

/**
 * Initializing Colors and fonts to be used in PDF Document.
 * Color scheme is taken from Carbide logo.
 *///from w  w w.  java  2 s.co  m
private void initStyles() {

    //
    // Colors used are picked up from Carbide.c++ -logo, from dark blue to white
    // #003399 = 0, 51, 153 -Dark blue
    // #0088ff = 0, 136, 255 -mid blue
    // #33aaff = 51, 170, 255 -mid blue 2
    // #88ccff = 136, 204, 255 -thin blue
    // #ffffff = -white
    //

    //
    //Using Carbide.c++ logo colors to decorate report
    //
    colorHeading = new Color(0, 51, 153);
    colorTableHeaderBackGrd = new Color(136, 204, 255);
    colorTable2ndHeaderBackGrd = new Color(0, 136, 255);

    //
    // Setting Severity Colors for PDF report from Analyser view colors.
    //
    org.eclipse.swt.graphics.Color color = AnalyserConstants.COLOR_SEVERITY_CRITICAL;
    colorSeverityCritical = new Color(color.getRed(), color.getGreen(), color.getBlue());

    color = AnalyserConstants.COLOR_SEVERITY_HIGH;
    colorSeverityHigh = new Color(color.getRed(), color.getGreen(), color.getBlue());

    color = AnalyserConstants.COLOR_SEVERITY_NORMAL;
    colorSeverityNormal = new Color(color.getRed(), color.getGreen(), color.getBlue());

    //
    // Font used in report
    //
    String font = FontFactory.HELVETICA;

    //
    // Creating fonts
    //
    fontTable2ndHeaderText = FontFactory.getFont(font, 10f, Font.NORMAL, Color.WHITE);
    fontHeader = FontFactory.getFont(font, 16, Font.BOLD, Color.BLACK);
    fontNormalSmallTables = FontFactory.getFont(font, 9f, Font.NORMAL);
    fontNormal = FontFactory.getFont(font, 10f, Font.NORMAL);
    fontHeading2 = FontFactory.getFont(font, 10f, Font.BOLD);
    fontHeading1 = FontFactory.getFont(font, 12f, Font.BOLD, colorHeading);

    cellPaddingSmall = 1.0f;
    cellPaddingTableHeader = 3.0f;

}

From source file:com.prime.location.billing.InvoicedBillingManager.java

/**
 * Print invoice/*from  w w  w.  j  a  v  a2 s  .co  m*/
 */
public void printInvoice() {
    try { //catch better your exceptions, this is just an example
        FacesContext context = FacesContext.getCurrentInstance();

        Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f);

        String fileName = "PDFFile";

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(pdf, baos);
        TableHeader event = new TableHeader();
        event.setHeader("Header Here");
        writer.setPageEvent(event);

        if (!pdf.isOpen()) {
            pdf.open();
        }

        PdfPCell cell;

        PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 });
        cell = new PdfPCell(new Paragraph("INVOICE",
                FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);
        header.setTotalWidth(527);
        header.setLockedWidth(true);

        cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription()));
        cell.setColspan(2);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);

        cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId()));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate())));
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        pdf.add(header);

        PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 });
        table.setSpacingBefore(15f);

        table.setTotalWidth(527);
        table.setLockedWidth(true);
        //table.setWidths(new int[]{3, 1, 1});

        table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY);

        table.addCell("Date");
        table.addCell("Name");
        table.addCell("Service");
        table.addCell("Rate");

        table.getDefaultCell().setBackgroundColor(null);

        cell = new PdfPCell(new Phrase("Total(US$): "));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setColspan(3);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount())));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        // There are three special rows
        table.setHeaderRows(2);
        // One of them is a footer
        table.setFooterRows(1);
        Font f = FontFactory.getFont(FontFactory.HELVETICA, 10);
        //add remaining
        for (AgencyBilling billing : selectedInvoice.getBillings()) {
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.getDefaultCell().setIndent(2);
            table.getDefaultCell().setFixedHeight(20);

            table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f));
            table.addCell(new Phrase(billing.getPerson().getName(), f));
            table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f));
            cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            table.addCell(cell);

        }

        pdf.add(table);

        writer.getAcroForm().setNeedAppearances(true);

        //document.add(new Phrase(TEXT));
        //Keep modifying your pdf file (add pages and more)
        pdf.close();

        writePDFToResponse(context.getExternalContext(), baos, fileName);

        context.responseComplete();

    } catch (Exception e) {
        //e.printStackTrace();          
    }
}

From source file:com.prime.report.template.TableHeader.java

/**
 * Adds a header to every page/*from w w  w.j a v a  2s .c o  m*/
 *
 * @param writer
 * @param document
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {

    PdfPTable table = new PdfPTable(4);
    try {
        table.setWidths(new int[] { 10, 11, 9, 1 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String logoPath = "/resources/image/logo.png";
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String logo = servletContext.getRealPath(logoPath);
        Image img = Image.getInstance(logo);

        table.addCell(Image.getInstance(img));

        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(new Phrase("New South West Facility Center",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, Color.BLACK)));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(String.format("Page %d of", writer.getPageNumber()));
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    } catch (IOException ex) {
        Logger.getLogger(TableHeader.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes the table of contents to the document.
 *
 * @param  document  The document to which the contents are to be written.
 *
 * @return  {@code true} if the contents information was written to the
 *          PDF document, or {@code false} if not.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 *///from w  w w  .j  a v a 2s .  c o m
private boolean writeContents(Document document) throws DocumentException {
    // First, make sure that there is actually something to write.  If we're
    // only going to write information for a single job or optimizing job, then
    // there is no reason to have a contents section.
    if (((reportJobs.length == 1) && (reportOptimizingJobs.length == 0))
            || ((reportJobs.length == 0) && (reportOptimizingJobs.length == 1))) {
        return false;
    }

    if (reportJobs.length > 0) {
        // Write the job data header.
        Paragraph p = new Paragraph("Job Data",
                FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
        document.add(p);

        // Create a table with the list of jobs.
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        writeTableHeaderCell(table, "Job ID");
        writeTableHeaderCell(table, "Description");
        writeTableHeaderCell(table, "Job Type");

        for (int i = 0; i < reportJobs.length; i++) {
            Job job = reportJobs[i];
            Anchor anchor = new Anchor(job.getJobID(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
            anchor.setReference('#' + job.getJobID());
            table.addCell(new PdfPCell(anchor));

            String descriptionStr = job.getJobDescription();
            if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
                descriptionStr = "(Not Specified)";
            }
            writeTableCell(table, descriptionStr);

            writeTableCell(table, job.getJobClass().getJobName());
        }
        document.add(table);

        // Write a blank line between the job data and optimizing job data.
        document.add(new Paragraph(" "));
    }

    if (reportOptimizingJobs.length > 0) {
        // Write the optimizing job data header.
        Paragraph p = new Paragraph("Optimizing Job Data",
                FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
        document.add(p);

        // Create a table with the list of jobs.
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        writeTableHeaderCell(table, "Optimizing Job ID");
        writeTableHeaderCell(table, "Description");
        writeTableHeaderCell(table, "Job Type");

        for (int i = 0; i < reportOptimizingJobs.length; i++) {
            OptimizingJob optimizingJob = reportOptimizingJobs[i];
            Anchor anchor = new Anchor(optimizingJob.getOptimizingJobID(),
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
            anchor.setReference('#' + optimizingJob.getOptimizingJobID());
            table.addCell(new PdfPCell(anchor));

            String descriptionStr = optimizingJob.getDescription();
            if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
                descriptionStr = "(Not Specified)";
            }
            writeTableCell(table, descriptionStr);

            writeTableCell(table, optimizingJob.getJobClass().getJobName());
        }
        document.add(table);
    }

    return true;
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes information about the provided job to the document.
 *
 * @param  document  The document to which the job information should be
 *                   written./*from  w w w.  ja v a  2 s .  c  om*/
 * @param  job       The job to include in the document.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 */
private void writeJob(Document document, Job job) throws DocumentException {
    Anchor anchor = new Anchor("Job " + job.getJobID(),
            FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
    anchor.setName(job.getJobID());
    Paragraph p = new Paragraph(anchor);
    document.add(p);

    // Write the general information to the document.
    p = new Paragraph("General Information",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    document.add(p);

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setWidths(new int[] { 30, 70 });
    writeTableCell(table, "Job ID");
    writeTableCell(table, job.getJobID());

    String optimizingJobID = job.getOptimizingJobID();
    if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) {
        writeTableCell(table, "Optimizing Job ID");
        writeTableCell(table, optimizingJobID);
    }

    String descriptionStr = job.getJobDescription();
    if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
        descriptionStr = "(Not Specified)";
    }
    writeTableCell(table, "Job Description");
    writeTableCell(table, descriptionStr);

    writeTableCell(table, "Job Type");
    writeTableCell(table, job.getJobClassName());

    writeTableCell(table, "Job Class");
    writeTableCell(table, job.getJobClass().getClass().getName());

    writeTableCell(table, "Job State");
    writeTableCell(table, job.getJobStateString());
    document.add(table);

    // Write the schedule config if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Schedule Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date startTime = job.getStartTime();
        String startStr;
        if (startTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(startTime);
        }
        writeTableCell(table, "Scheduled Start Time");
        writeTableCell(table, startStr);

        Date stopTime = job.getStopTime();
        String stopStr;
        if (stopTime == null) {
            stopStr = "(Not Specified)";
        } else {
            stopStr = dateFormat.format(stopTime);
        }
        writeTableCell(table, "Scheduled Stop Time");
        writeTableCell(table, stopStr);

        int duration = job.getDuration();
        String durationStr;
        if (duration > 0) {
            durationStr = duration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Scheduled Duration");
        writeTableCell(table, durationStr);

        writeTableCell(table, "Number of Clients");
        writeTableCell(table, String.valueOf(job.getNumberOfClients()));

        String[] requestedClients = job.getRequestedClients();
        if ((requestedClients != null) && (requestedClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < requestedClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Requested Clients");
            table.addCell(clientTable);
        }

        String[] monitorClients = job.getResourceMonitorClients();
        if ((monitorClients != null) && (monitorClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < monitorClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Resource Monitor Clients");
            table.addCell(clientTable);
        }

        writeTableCell(table, "Threads per Client");
        writeTableCell(table, String.valueOf(job.getThreadsPerClient()));

        writeTableCell(table, "Thread Startup Delay");
        writeTableCell(table, job.getThreadStartupDelay() + " milliseconds");

        writeTableCell(table, "Statistics Collection Interval");
        writeTableCell(table, job.getCollectionInterval() + " seconds");

        document.add(table);
    }

    // Write the job-specific parameter information if appropriate.
    if (includeJobConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Parameter Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Parameter[] params = job.getParameterList().getParameters();
        for (int i = 0; i < params.length; i++) {
            writeTableCell(table, params[i].getDisplayName());
            writeTableCell(table, params[i].getDisplayValue());
        }

        document.add(table);
    }

    // Write the statistical data if appropriate.
    if (includeStats && job.hasStats()) {
        document.add(new Paragraph(" "));
        p = new Paragraph("General Execution Data",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date actualStartTime = job.getActualStartTime();
        String startStr;
        if (actualStartTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(actualStartTime);
        }
        writeTableCell(table, "Actual Start Time");
        writeTableCell(table, startStr);

        Date actualStopTime = job.getActualStopTime();
        String stopStr;
        if (actualStopTime == null) {
            stopStr = "(Not Available)";
        } else {
            stopStr = dateFormat.format(actualStopTime);
        }
        writeTableCell(table, "Actual Stop Time");
        writeTableCell(table, stopStr);

        int actualDuration = job.getActualDuration();
        String durationStr;
        if (actualDuration > 0) {
            durationStr = actualDuration + " seconds";
        } else {
            durationStr = "(Not Available)";
        }
        writeTableCell(table, "Actual Duration");
        writeTableCell(table, durationStr);

        String[] clients = job.getStatTrackerClientIDs();
        if ((clients != null) && (clients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < clients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(clients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Clients Used");
            table.addCell(clientTable);
        }

        document.add(table);

        String[] trackerNames = job.getStatTrackerNames();
        for (int i = 0; i < trackerNames.length; i++) {
            StatTracker[] trackers = job.getStatTrackers(trackerNames[i]);
            if ((trackers != null) && (trackers.length > 0)) {
                document.newPage();
                StatTracker tracker = trackers[0].newInstance();
                tracker.aggregate(trackers);

                document.add(new Paragraph(" "));
                document.add(new Paragraph(trackerNames[i],
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));

                String[] summaryNames = tracker.getSummaryLabels();
                String[] summaryValues = tracker.getSummaryData();
                table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setWidths(new int[] { 50, 50 });
                for (int j = 0; j < summaryNames.length; j++) {
                    writeTableCell(table, summaryNames[j]);
                    writeTableCell(table, summaryValues[j]);
                }
                document.add(table);

                if (includeGraphs) {
                    try {
                        ParameterList params = tracker.getGraphParameterStubs(job);
                        BufferedImage graphImage = tracker.createGraph(job, Constants.DEFAULT_GRAPH_WIDTH,
                                Constants.DEFAULT_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }
    }

    // Write the resource monitor data if appropriate.
    if (includeMonitorStats && job.hasResourceStats()) {
        String[] trackerNames = job.getResourceStatTrackerNames();
        for (int i = 0; i < trackerNames.length; i++) {
            StatTracker[] trackers = job.getResourceStatTrackers(trackerNames[i]);
            if ((trackers != null) && (trackers.length > 0)) {
                document.newPage();
                StatTracker tracker = trackers[0].newInstance();
                tracker.aggregate(trackers);

                document.add(new Paragraph(" "));
                document.add(new Paragraph(trackerNames[i],
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));

                String[] summaryNames = tracker.getSummaryLabels();
                String[] summaryValues = tracker.getSummaryData();
                table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setWidths(new int[] { 50, 50 });
                for (int j = 0; j < summaryNames.length; j++) {
                    writeTableCell(table, summaryNames[j]);
                    writeTableCell(table, summaryValues[j]);
                }
                document.add(table);

                if (includeGraphs) {
                    try {
                        ParameterList params = tracker.getGraphParameterStubs(job);
                        BufferedImage graphImage = tracker.createMonitorGraph(job,
                                Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_MONITOR_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes information about the provided optimizing job to the document.
 *
 * @param  document       The document to which the job information should be
 *                        written.//from  w  ww  . ja  v a  2 s .  com
 * @param  optimizingJob  The optimizing job to include in the document.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 */
private void writeOptimizingJob(Document document, OptimizingJob optimizingJob) throws DocumentException {
    Anchor anchor = new Anchor("Optimizing Job " + optimizingJob.getOptimizingJobID(),
            FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
    anchor.setName(optimizingJob.getOptimizingJobID());
    Paragraph p = new Paragraph(anchor);
    document.add(p);

    // Write the general information to the document.
    p = new Paragraph("General Information",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    document.add(p);

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setWidths(new int[] { 30, 70 });
    writeTableCell(table, "Optimizing Job ID");
    writeTableCell(table, optimizingJob.getOptimizingJobID());

    writeTableCell(table, "Job Type");
    writeTableCell(table, optimizingJob.getJobClassName());

    String descriptionStr = optimizingJob.getDescription();
    if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
        descriptionStr = "(Not Specified)";
    }
    writeTableCell(table, "Base Description");
    writeTableCell(table, descriptionStr);

    writeTableCell(table, "Include Thread Count in Description");
    writeTableCell(table, String.valueOf(optimizingJob.includeThreadsInDescription()));

    writeTableCell(table, "Job State");
    writeTableCell(table, Constants.jobStateToString(optimizingJob.getJobState()));
    document.add(table);

    // Write the schedule config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Schedule Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date startTime = optimizingJob.getStartTime();
        String startStr;
        if (startTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(startTime);
        }
        writeTableCell(table, "Scheduled Start Time");
        writeTableCell(table, startStr);

        int duration = optimizingJob.getDuration();
        String durationStr;
        if (duration > 0) {
            durationStr = duration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Job Duration");
        writeTableCell(table, durationStr);

        writeTableCell(table, "Delay Between Iterations");
        writeTableCell(table, optimizingJob.getDelayBetweenIterations() + " seconds");

        writeTableCell(table, "Number of Clients");
        writeTableCell(table, String.valueOf(optimizingJob.getNumClients()));

        String[] requestedClients = optimizingJob.getRequestedClients();
        if ((requestedClients != null) && (requestedClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < requestedClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Requested Clients");
            table.addCell(clientTable);
        }

        String[] monitorClients = optimizingJob.getResourceMonitorClients();
        if ((monitorClients != null) && (monitorClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < monitorClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Resource Monitor Clients");
            table.addCell(clientTable);
        }

        writeTableCell(table, "Minimum Number of Threads");
        writeTableCell(table, String.valueOf(optimizingJob.getMinThreads()));

        int maxThreads = optimizingJob.getMaxThreads();
        String maxThreadsStr;
        if (maxThreads > 0) {
            maxThreadsStr = String.valueOf(maxThreads);
        } else {
            maxThreadsStr = "(Not Specified)";
        }
        writeTableCell(table, "Maximum Number of Threads");
        writeTableCell(table, maxThreadsStr);

        writeTableCell(table, "Thread Increment Between Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getThreadIncrement()));

        writeTableCell(table, "Statistics Collection Interval");
        writeTableCell(table, optimizingJob.getCollectionInterval() + " seconds");
        document.add(table);
    }

    // Get the optimization algorithm used.
    OptimizationAlgorithm optimizationAlgorithm = optimizingJob.getOptimizationAlgorithm();
    ParameterList paramList = optimizationAlgorithm.getOptimizationAlgorithmParameters();
    Parameter[] optimizationParams = paramList.getParameters();

    // Write the optimizing config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Optimization Settings",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        for (int i = 0; i < optimizationParams.length; i++) {
            writeTableCell(table, optimizationParams[i].getDisplayName());
            writeTableCell(table, optimizationParams[i].getDisplayValue());
        }

        writeTableCell(table, "Maximum Consecutive Non-Improving Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getMaxNonImproving()));

        writeTableCell(table, "Re-Run Best Iteration");
        writeTableCell(table, String.valueOf(optimizingJob.reRunBestIteration()));

        int reRunDuration = optimizingJob.getReRunDuration();
        String durationStr;
        if (reRunDuration > 0) {
            durationStr = reRunDuration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Re-Run Duration");
        writeTableCell(table, durationStr);

        document.add(table);
    }

    // Write the job-specific config to the document if appropriate.
    if (includeJobConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Parameter Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Parameter[] params = optimizingJob.getParameters().getParameters();
        for (int i = 0; i < params.length; i++) {
            writeTableCell(table, params[i].getDisplayName());
            writeTableCell(table, params[i].getDisplayValue());
        }

        document.add(table);
    }

    // Write the statistical data to the document if appropriate.
    if (includeStats && optimizingJob.hasStats()) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Execution Data",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date actualStartTime = optimizingJob.getActualStartTime();
        String startTimeStr;
        if (actualStartTime == null) {
            startTimeStr = "(Not Available)";
        } else {
            startTimeStr = dateFormat.format(actualStartTime);
        }
        writeTableCell(table, "Actual Start Time");
        writeTableCell(table, startTimeStr);

        Date actualStopTime = optimizingJob.getActualStopTime();
        String stopTimeStr;
        if (actualStopTime == null) {
            stopTimeStr = "(Not Available)";
        } else {
            stopTimeStr = dateFormat.format(actualStopTime);
        }
        writeTableCell(table, "Actual Stop Time");
        writeTableCell(table, stopTimeStr);

        Job[] iterations = optimizingJob.getAssociatedJobs();
        if ((iterations != null) && (iterations.length > 0)) {
            writeTableCell(table, "Job Iterations Completed");
            writeTableCell(table, String.valueOf(iterations.length));

            int optimalThreadCount = optimizingJob.getOptimalThreadCount();
            String threadStr;
            if (optimalThreadCount > 0) {
                threadStr = String.valueOf(optimalThreadCount);
            } else {
                threadStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Thread Count");
            writeTableCell(table, threadStr);

            double optimalValue = optimizingJob.getOptimalValue();
            String valueStr;
            if (optimalThreadCount > 0) {
                valueStr = decimalFormat.format(optimalValue);
            } else {
                valueStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Value");
            writeTableCell(table, valueStr);

            String optimalID = optimizingJob.getOptimalJobID();
            writeTableCell(table, "Optimal Job Iteration");
            if ((optimalID == null) || (optimalID.length() == 0)) {
                writeTableCell(table, "(Not Available)");
            } else if (includeOptimizingIterations) {
                anchor = new Anchor(optimalID,
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + optimalID);
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, optimalID);
            }
        }

        Job reRunIteration = optimizingJob.getReRunIteration();
        if (reRunIteration != null) {
            writeTableCell(table, "Re-Run Iteration");
            if (includeOptimizingIterations) {
                anchor = new Anchor(reRunIteration.getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + reRunIteration.getJobID());
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, reRunIteration.getJobID());
            }

            String valueStr;
            try {
                double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(reRunIteration);
                valueStr = decimalFormat.format(iterationValue);
            } catch (Exception e) {
                valueStr = "N/A";
            }

            writeTableCell(table, "Re-Run Iteration Value");
            writeTableCell(table, valueStr);
        }

        document.add(table);

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            document.add(new Paragraph(" "));
            p = new Paragraph("Job Iterations",
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
            document.add(p);

            table = new PdfPTable(2);
            table.setWidthPercentage(100);
            table.setWidths(new int[] { 50, 50 });

            for (int i = 0; i < iterations.length; i++) {
                String valueStr;
                try {
                    double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(iterations[i]);
                    valueStr = decimalFormat.format(iterationValue);
                } catch (Exception e) {
                    valueStr = "N/A";
                }

                anchor = new Anchor(iterations[i].getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + iterations[i].getJobID());
                table.addCell(new PdfPCell(anchor));
                writeTableCell(table, valueStr);
            }

            document.add(table);
        }

        if (includeGraphs && (iterations != null) && (iterations.length > 0)) {
            String[] statNames = iterations[0].getStatTrackerNames();
            for (int j = 0; j < statNames.length; j++) {
                StatTracker[] trackers = iterations[0].getStatTrackers(statNames[j]);
                if ((trackers != null) && (trackers.length > 0)) {
                    StatTracker tracker = trackers[0].newInstance();
                    tracker.aggregate(trackers);

                    try {
                        document.newPage();
                        ParameterList params = tracker.getGraphParameterStubs(iterations);
                        BufferedImage graphImage = tracker.createGraph(iterations,
                                Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            for (int i = 0; i < iterations.length; i++) {
                document.newPage();
                writeJob(document, iterations[i]);
            }
        }
        if (includeOptimizingIterations && (reRunIteration != null)) {
            document.newPage();
            writeJob(document, reRunIteration);
        }
    }
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes the specified text to the provided table as a header cell.
 *
 * @param  table  The table to which the header cell should be written.
 * @param  text   The text to write to the header cell.
 *//*from  w w  w .  j  av  a  2  s . com*/
private void writeTableHeaderCell(PdfPTable table, String text) {
    Phrase phrase = new Phrase(text, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    table.addCell(new PdfPCell(phrase));
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Performs the appropriate action necessary when starting a new page.  In
 * this case, we will write the SLAMD header to the top of the page.
 *
 * @param  writer    The writer used to write the PDF document.
 * @param  document  The PDF document being written.
 *//*from ww w  .j av  a 2  s  .c  o  m*/
public void onStartPage(PdfWriter writer, Document document) {
    try {
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);

        PdfPCell blueCell = new PdfPCell(new Phrase(" \n "));
        blueCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        blueCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        blueCell.setBackgroundColor(new Color(0x59, 0x4F, 0xBF));
        blueCell.setBorderWidth(inchesToPoints(1.0 / 16));
        blueCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        blueCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(blueCell);

        Phrase titlePhrase = new Phrase("SLAMD Generated Report",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0x59, 0x4F, 0xBF)));
        PdfPCell yellowCell = new PdfPCell(titlePhrase);
        yellowCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        yellowCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        yellowCell.setBackgroundColor(new Color(0xFB, 0xE2, 0x49));
        yellowCell.setBorderWidth(inchesToPoints(1.0 / 16));
        yellowCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        yellowCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(yellowCell);

        Phrase versionPhrase = new Phrase("Version " + DynamicConstants.SLAMD_VERSION,
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0xFF, 0xFF, 0xFF)));
        PdfPCell redCell = new PdfPCell(versionPhrase);
        redCell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
        redCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
        redCell.setBackgroundColor(new Color(0xD1, 0x21, 0x24));
        redCell.setBorderWidth(inchesToPoints(1.0 / 16));
        redCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF));
        redCell.setPadding(inchesToPoints(1.0 / 16));
        table.addCell(redCell);

        document.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

public PdfExporter(SongNodeLoader loader) {
    this.loader = loader;

    // Load fonts
    FontFactory.registerDirectories();/*from  www  . ja  va 2 s  .co  m*/
    BaseFont timesFont = null;
    try {
        timesFont = BaseFont.createFont("C:/Windows/Fonts/times.ttf", BaseFont.CP1250, true);
        logger.info("Embedded TTF fonts from C:/Windows/Fonts");
    } catch (Exception ex) {
        try {
            timesFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, true);
            logger.info("Embedded default fonts");
        } catch (Exception ex1) {
            logger.error("Failed to load fonts ...");
        }
    }

    // Initialize fonts
    if (timesFont != null) {
        songTitleFont = new Font(timesFont, 14f, Font.BOLD);
        textFont = new Font(timesFont, 11f, Font.NORMAL);
        chordFont = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, 11f, Font.BOLD);
    } else {
        songTitleFont = null;
        textFont = null;
        chordFont = null;
    }

    verseSpacing = new Paragraph(" ");
    verseSpacing.setLeading(5f, 0.5f);
}

From source file:de.maklerpoint.office.Schnittstellen.PDF.ExportListePDF.java

License:Open Source License

public void write() throws DocumentException, FileNotFoundException {

    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Document doc = null;/*from ww w.j a v a2s  .  c  o m*/

    if (titles.length > 7)
        doc = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    else
        doc = new Document(PageSize.A4, 20, 20, 20, 20);

    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    doc.addAuthor("MaklerPoint - www.maklerpoint.de");
    doc.addCreator("MaklerPoint - www.maklerpoint.de");
    doc.addCreationDate();
    doc.addTitle(title);

    doc.open();

    doc.add(new Paragraph(title, FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, Color.BLACK)));

    Table t = new Table(titles.length, data.length + 1);
    t.setPadding(3);
    t.setSpacing(0);
    t.setBorderWidth(1);

    for (int i = 0; i < titles.length; i++) {
        Cell c1 = new Cell(titles[i]);
        c1.setHeader(true);
        t.addCell(c1);
    }
    t.endHeaders();

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[i].length; j++) {
            Cell c1 = null;
            if (data[i][j] != null)
                c1 = new Cell(data[i][j].toString());
            else
                c1 = new Cell("");
            t.addCell(c1);
        }
    }

    doc.add(t);

    if (footer == null) {
        doc.add(new Paragraph(
                ("Export " + title + " - Genereriert am " + df.format(new Date(System.currentTimeMillis())))
                        + " von MaklerPoint",
                FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    } else {
        doc.add(new Paragraph(footer, FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    }

    doc.close();
}