Example usage for com.lowagie.text.pdf BaseFont HELVETICA_BOLD

List of usage examples for com.lowagie.text.pdf BaseFont HELVETICA_BOLD

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont HELVETICA_BOLD.

Prototype

String HELVETICA_BOLD

To view the source code for com.lowagie.text.pdf BaseFont HELVETICA_BOLD.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java

License:Open Source License

public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc,
        boolean whiteBackground) throws Exception {
    final int margin = 15;
    File f = File.createTempFile("cages__", ".pdf");
    Document doc = new Document(PageSize.A4.rotate());
    Image maleImg, femaleImg, nosexImg;
    try {/* w ww.  ja v a2 s . com*/
        maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png"));
        femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png"));
        nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png"));
    } catch (Exception e) {
        throw new Exception("Could not find images in the classpath: " + e);
    }

    FileOutputStream os = new FileOutputStream(f);
    PdfWriter writer = PdfWriter.getInstance(doc, os);
    doc.open();

    PdfContentByte canvas = writer.getDirectContentUnder();

    float tileW = (doc.getPageSize().getWidth()) / 4;
    float tileH = (doc.getPageSize().getHeight()) / 2;
    for (int i = 0; i < cages.size(); i++) {
        Container cage = cages.get(i);

        Study study = cage.getStudy();
        Set<Group> groups = cage.getGroups();
        Group group = cage.getGroup();
        Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME);
        animals.addAll(cage.getBiosamples());

        //Find the treatments applied to this group
        Set<NamedTreatment> allTreatments = new LinkedHashSet<>();
        for (Group gr : groups) {
            allTreatments.addAll(gr.getAllTreatments(-1));
        }

        //Draw
        if (i % 8 == 0) {
            if (i > 0)
                doc.newPage();
            drawCageSeparation(doc, canvas);
        }

        int col = (i % 8) % 4;
        int row = (i % 8) / 4;

        float x = margin + tileW * col;
        float x2 = x + tileW - margin;
        float baseY = tileH * row;
        float y;

        //Display Sex
        canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50));
        Image img = null;
        String sex = getMetadata(animals, "Sex");
        if (study.isBlindAll()) {
            img = nosexImg;
        } else if (sex.equals("M")) {
            img = maleImg;
        } else if (sex.equals("F")) {
            img = femaleImg;
        } else if (sex.length() > 0) {
            img = nosexImg;
        }
        if (img != null) {
            img.scaleToFit(20, 20);
            img.setAbsolutePosition(tileW * (col + 1) - 33,
                    doc.getPageSize().getHeight() - (tileH * row + 12 + margin));
            doc.add(img);
        }
        if (group != null && group.getColor() != null && (study != null && !study.isBlind())
                && !whiteBackground) {
            Color c = group.getColor();
            canvas.saveState();
            canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170);
            canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2,
                    tileH - 2);
            canvas.fill();
            canvas.restoreState();
        }
        Color treatmentColor = Color.BLACK;
        if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) {
            int offset = 0;
            for (NamedTreatment t : allTreatments) {
                if (t.getColor() != null) {
                    if (allTreatments.size() == 1)
                        treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2,
                                t.getColor().getBlue() / 2);
                    canvas.saveState();
                    canvas.setColorStroke(Color.BLACK);
                    canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(),
                            t.getColor().getBlue());
                    y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28;
                    canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4,
                            22, 22);
                    canvas.fillStroke();
                    canvas.restoreState();
                    offset++;
                }
            }
        }

        canvas.beginText();
        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f);
        canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x,
                doc.getPageSize().getHeight() - (baseY + 23), 0);

        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f);
        y = 42 + baseY;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 15;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 86;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 22;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 14;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 23;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 50;
        canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0);
        canvas.endText();

        y = 42 + baseY;
        print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65,
                doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f);
        y += 15;

        if (animals.size() <= 6) {
            int n = 0;
            for (Biosample animal : animals) {
                print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50,
                        12, 12, FontFactory.HELVETICA, Color.BLACK, 11f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60,
                            doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD,
                            Color.BLACK, 11f);
                }
                n++;
            }
        } else {
            int nPerRow = animals.size() / 2;
            int n = 0;
            for (Biosample animal : animals) {
                int nx = n / nPerRow;
                int ny = n % nPerRow;
                print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2,
                        doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12,
                        FontFactory.HELVETICA, Color.BLACK, 10f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35,
                            doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12,
                            12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f);
                }
                n++;
            }
        }

        y += 86;
        print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0,
                10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10,
                FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 22;
        print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11,
                BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 14;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11,
                    BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 23;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y,
                    x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor,
                    printTreatmentDesc ? 9f : 10f);
        y += 50;
        print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2,
                15, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2,
                20, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
    }

    doc.close();
    os.close();
    Desktop.getDesktop().open(f);
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }

}

From source file:com.moss.pdf.template.core.Renderer.java

License:Open Source License

public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception {

    PdfReader reader = new PdfReader(in);

    Document document = new Document(reader.getPageSizeWithRotation(1));

    PdfWriter writer = PdfWriter.getInstance(document, out);

    document.open();/*from w w w  .ja  v a2s . c o  m*/

    for (int i = 1; i <= reader.getNumberOfPages(); i++) {

        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage customPage = writer.getImportedPage(reader, i);

        /*
         * add the page to our new document, turning this page to its 
         * original rotation
         */
        int pageRotation = reader.getPageRotation(i);

        if (pageRotation > 0) {

            System.out.println("page rotation found: " + pageRotation);

            double angle = -((2 * Math.PI) * pageRotation / 360);
            //         double angle = -(Math.PI / 2);

            cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle),
                    (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x
                    document.top() + document.topMargin() // y
            );
        } else {
            cb.addTemplate(customPage, 0f, 0f);
        }

        Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>();

        for (PropertyMapping field : fields) {

            if (field.getPageNumber() != i) {
                continue;
            }

            /*
             * Only builtin fonts are supported at the moment
             */
            BaseFont font;
            int fontSize;
            int alignment;
            String text;
            float x, y;
            float rotation;

            {
                font = fonts.get(field.getFontName());

                if (font == null) {

                    FontName e = field.getFontName();
                    String name = null;

                    if (FontName.COURIER == e) {
                        name = BaseFont.COURIER;
                    } else if (FontName.COURIER_BOLD == e) {
                        name = BaseFont.COURIER_BOLD;
                    } else if (FontName.COURIER_BOLD_OBLIQUE == e) {
                        name = BaseFont.COURIER_BOLDOBLIQUE;
                    } else if (FontName.COURIER_OBLIQUE == e) {
                        name = BaseFont.COURIER_OBLIQUE;
                    } else if (FontName.HELVETICA == e) {
                        name = BaseFont.HELVETICA;
                    } else if (FontName.HELVETICA_BOLD == e) {
                        name = BaseFont.HELVETICA_BOLD;
                    } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) {
                        name = BaseFont.HELVETICA_BOLDOBLIQUE;
                    } else if (FontName.HELVETICA_OBLIQUE == e) {
                        name = BaseFont.HELVETICA_OBLIQUE;
                    } else if (FontName.TIMES_BOLD == e) {
                        name = BaseFont.TIMES_BOLD;
                    } else if (FontName.TIMES_BOLD_ITALIC == e) {
                        name = BaseFont.TIMES_BOLDITALIC;
                    } else if (FontName.TIMES_ITALIC == e) {
                        name = BaseFont.TIMES_ITALIC;
                    } else if (FontName.TIMES_ROMAN == e) {
                        name = BaseFont.TIMES_ROMAN;
                    }

                    if (name == null) {
                        throw new RuntimeException("Unknown font type: " + e);
                    }

                    font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                    fonts.put(field.getFontName(), font);
                }

                fontSize = field.getFontSize();

                if (TextAlignment.LEFT == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_LEFT;
                } else if (TextAlignment.CENTER == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_CENTER;
                } else if (TextAlignment.RIGHT == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_RIGHT;
                } else {
                    alignment = PdfContentByte.ALIGN_LEFT;
                }

                Object value = p.eval(field.getExpr());

                if (value == null) {
                    text = "";
                } else {
                    text = value.toString();
                }

                x = field.getX() * POINTS_IN_A_CM;
                y = field.getY() * POINTS_IN_A_CM;

                rotation = 0;
            }

            cb.beginText();

            cb.setFontAndSize(font, fontSize);

            cb.showTextAligned(alignment, text, x, y, rotation);

            cb.endText();
        }

        document.newPage();
    }

    reader.close();
    document.close();
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

/**
 * @param experiment/*from  w  w  w .jav a  2s  .  c o m*/
 * @return
 */
private Element getMeasurementTable(Experiment3VO experiment, List<Buffer3VO> buffers) {

    PdfPTable table = new PdfPTable(MEASUREMENT_COLUMNS.length);

    table.setWidthPercentage(100f);
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setColspan(MEASUREMENT_COLUMNS.length);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setColspan(1);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    for (int i = 0; i < MEASUREMENT_COLUMNS.length; i++) {
        table.addCell(this.getCell(MEASUREMENT_COLUMNS[i], BaseFont.HELVETICA_BOLD));
    }
    table.getDefaultCell().setBackgroundColor(null);

    List<List<String>> data = this.getExperimentMesurementData(experiment, buffers);

    for (List<String> list : data) {
        for (String string : list) {
            table.addCell(getCell(string));
        }
    }
    return table;
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private Element getImageTable(Experiment3VO experiment, List<Buffer3VO> buffers) {

    PdfPTable table = new PdfPTable(ImageColumns.length);

    table.setWidthPercentage(100f);/*  w  w w.  j  a  v a 2s.c om*/
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setColspan(ImageColumns.length);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setColspan(1);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    for (int i = 0; i < ImageColumns.length; i++) {
        table.addCell(this.getCell(ImageColumns[i], BaseFont.HELVETICA_BOLD));
    }
    table.getDefaultCell().setBackgroundColor(null);

    List<Measurement3VO> measurements = experiment.getMeasurements();
    Collections.sort(measurements, MeasurementComparator
            .compare(MeasurementComparator.getComparator(MeasurementComparator.PRIOTIRY_SORT_ASC)));
    for (int x = 0; x < measurements.size(); x++) {
        Measurement3VO measurement = measurements.get(x);
        Specimen3VO specimen = experiment.getSampleById(measurement.getSpecimenId());
        if (specimen.getMacromolecule3VO() != null) {
            SaxsDataCollection3VO dataCollection = experiment
                    .getDataCollectionByMeasurementId(measurement.getMeasurementId());

            ArrayList<String> list = this.addAnalysisRow(measurement, experiment, buffers);
            if (list.size() > 0) {
                int sizeTable = list.get(0).length();
                PdfPTable nested1 = new PdfPTable(sizeTable);
                nested1.getDefaultCell().setBorder(0);
                for (int i = 0; i < list.size(); i++) {
                    if (i == 0) {
                        nested1.getDefaultCell().setBackgroundColor(PdfRtfExporter.LIGHT_GREY_COLOR);
                        nested1.getDefaultCell().setBorder(0);
                        Paragraph cell = this.getCell(this.COLUMNS[i] + ": " + list.get(i));
                        nested1.addCell(cell);
                    } else {
                        nested1.getDefaultCell().setBackgroundColor(null);
                        nested1.getDefaultCell().setBorder(0);
                        PdfPCell cell = new PdfPCell(this.getCell(this.COLUMNS[i] + ": " + list.get(i)));
                        cell.setBorder(0);
                        nested1.addCell(cell);
                    }
                }
                table.addCell(new PdfPCell(nested1));

                if (dataCollection.getSubstraction3VOs() != null) {
                    if (dataCollection.getSubstraction3VOs().size() > 0) {
                        Subtraction3VO substraction = ((Subtraction3VO) (dataCollection.getSubstraction3VOs()
                                .toArray()[0]));

                        String scatteringImage = BiosaxsActions
                                .checkFilePathForDevelopment(substraction.getScatteringFilePath());
                        if (scatteringImage != null) {
                            if (new File(scatteringImage).exists()) {
                                try {
                                    PdfPCell cell = new PdfPCell(Image.getInstance(scatteringImage), true);
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                } catch (Exception e) {
                                    PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                    e.printStackTrace();
                                }
                            } else {
                                PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                cell.setBorder(0);
                                table.addCell(cell);
                            }
                        } else {
                            PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                            cell.setBorder(0);
                            table.addCell(cell);
                        }

                        String guinierImage = BiosaxsActions
                                .checkFilePathForDevelopment(substraction.getGuinierFilePath());
                        if (guinierImage != null) {
                            if (new File(guinierImage).exists()) {
                                try {
                                    PdfPCell cell = new PdfPCell(Image.getInstance(guinierImage), true);
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                } catch (Exception e) {
                                    PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                    e.printStackTrace();
                                }
                            } else {
                                PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                cell.setBorder(0);
                                table.addCell(cell);
                            }
                        } else {
                            PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                            cell.setBorder(0);
                            table.addCell(cell);
                        }

                        String kraktyImage = BiosaxsActions
                                .checkFilePathForDevelopment(substraction.getKratkyFilePath());
                        if (kraktyImage != null) {
                            if (new File(kraktyImage).exists()) {
                                try {
                                    PdfPCell cell = new PdfPCell(Image.getInstance(kraktyImage), true);
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                } catch (Exception e) {
                                    PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                    e.printStackTrace();
                                }
                            } else {
                                PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                cell.setBorder(0);
                                table.addCell(cell);
                            }
                        } else {
                            PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                            cell.setBorder(0);
                            table.addCell(cell);
                        }

                        String gnomImage = BiosaxsActions
                                .checkFilePathForDevelopment(substraction.getGnomFilePath());
                        if (gnomImage != null) {
                            if (new File(gnomImage).exists()) {
                                try {
                                    PdfPCell cell = new PdfPCell(Image.getInstance(gnomImage), true);
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                } catch (Exception e) {
                                    PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                    cell.setBorder(0);
                                    table.addCell(cell);
                                    e.printStackTrace();
                                }
                            } else {
                                PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                                cell.setBorder(0);
                                table.addCell(cell);
                            }
                        } else {
                            PdfPCell cell = new PdfPCell(this.getCell("Image not found"));
                            cell.setBorder(0);
                            table.addCell(cell);
                        }
                    }
                }
            }
        }
    }
    return table;
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private Element getAnalysis(Experiment3VO experiment, List<Buffer3VO> buffers) {
    PdfPTable table = new PdfPTable(COLUMNS.length);

    /** SUBTITLE **/
    table.getDefaultCell().setColspan(5);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(this.getCell("Sample", BaseFont.HELVETICA_BOLD));

    table.getDefaultCell().setColspan(5);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(this.getCell("Guinier", BaseFont.HELVETICA_BOLD));

    table.getDefaultCell().setColspan(3);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(this.getCell("Gnom", BaseFont.HELVETICA_BOLD));

    table.getDefaultCell().setColspan(2);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(this.getCell("Porod", BaseFont.HELVETICA_BOLD));
    table.setWidthPercentage(100f);//w w  w. jav a 2 s.com
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setColspan(COLUMNS.length);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setColspan(1);
    table.getDefaultCell().setBackgroundColor(PdfRtfExporter.BLUE_COLOR);
    for (int i = 0; i < COLUMNS.length; i++) {
        table.addCell(this.getCell(COLUMNS[i], BaseFont.HELVETICA_BOLD));
    }
    table.getDefaultCell().setBackgroundColor(null);

    List<List<String>> data = this.getExperimentAnalysisData(experiment, buffers);

    for (List<String> list : data) {
        for (String string : list) {
            table.addCell(getCell(string));
        }
    }
    return table;
}

From source file:net.algem.contact.TeacherCtrl.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 w  w  . j ava 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("student.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)));

    List<ScheduleElement> items = getFollowUpSchedules(userId, from, to);
    //LOGGER.log(Level.INFO, items.toString());
    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(), normalFont));
            table.addCell(new Phrase(r.getStart() + "-" + r.getEnd(), normalFont));
            table.addCell(new Phrase(new Hour(r.getLength()).toString(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("room").getName(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("course").getName(), normalFont));
            table.addCell(new Phrase(r.getPerson().getFirstName() + " " + r.getPerson().getName(), normalFont));
            table.addCell(new Phrase(status, normalFont));
            table.addCell(new Phrase(note == null ? "" : note, normalFont));
            table.addCell(new Phrase(content1 == null ? "" : content1.replaceAll("[\r\n]", " "), normalFont));
            table.addCell(new Phrase(content2 == null ? "" : content2.replaceAll("[\r\n]", " "), 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 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  ww  w.jav  a  2s. com*/

    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:org.kuali.kfs.sys.PdfFormFillerUtil.java

License:Open Source License

/**
 * This Method creates a custom watermark on the File.
 *
 * @param templateStream/*from   ww  w  .j a v a 2s  .c o  m*/
 * @param watermarkText
 * @return
 * @throws IOException
 * @throws DocumentException
 */
public static byte[] createWatermarkOnFile(byte[] templateStream, String watermarkText)
        throws IOException, DocumentException {
    // Create a PDF reader for the template
    PdfReader pdfReader = new PdfReader(templateStream);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    // Create a PDF writer
    PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
    int n = pdfReader.getNumberOfPages();
    int i = 1;
    PdfContentByte over;
    BaseFont bf;
    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
        PdfGState gstate = new PdfGState();
        gstate.setFillOpacity(0.5f);
        while (i <= n) {
            // Watermark under the existing page
            Rectangle pageSize = pdfReader.getPageSizeWithRotation(i);
            over = pdfStamper.getOverContent(i);
            over.beginText();
            over.setFontAndSize(bf, 200);
            over.setGState(gstate);
            over.setColorFill(Color.LIGHT_GRAY);
            over.showTextAligned(Element.ALIGN_CENTER, watermarkText, (pageSize.width() / 2),
                    (pageSize.height() / 2), 45);
            over.endText();
            i++;
        }
        pdfStamper.close();
    } catch (DocumentException ex) {
        throw new IOException("iText error creating watermark on PDF", ex);
    } catch (IOException ex) {
        throw new IOException("IO error creating watermark on PDF", ex);
    }
    return outputStream.toByteArray();
}

From source file:org.pentaho.reporting.libraries.fonts.itext.ITextBuiltInFontRegistry.java

License:Open Source License

private FontFamily createHelveticaFamily() {
    final DefaultFontFamily fontFamily = new DefaultFontFamily("Helvetica");
    fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA, false, false, false));
    fontFamily/*from  w  w  w .  jav a 2 s  . c  o  m*/
            .addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLD, true, false, false));
    fontFamily.addFontRecord(
            new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_OBLIQUE, false, true, true));
    fontFamily.addFontRecord(
            new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLDOBLIQUE, true, true, true));
    return fontFamily;
}

From source file:org.pz.platypus.plugin.html.HtmlFont.java

License:Open Source License

/**
 * Get the name by which iText refers to this font. This routine is mostly occupied
 * with the special handling of the base14 fonts. For all other fonts, this routine
 * simply returns its existing name./*www.ja v a 2  s.  c  om*/
 *
 * @param f PdfFont whose iText name we're getting
 * @return a string containing the iText usable name for this font.
 */
String createItextFontName(final HtmlFont f) {
    String iTextFontName;
    String typefaceName = f.typeface;

    // handle the different versions of base14 fonts
    if (typefaceName.equals("COURIER")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.COURIER_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.COURIER_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.COURIER_OBLIQUE;
        else
            iTextFontName = BaseFont.COURIER;
    } else if (typefaceName.equals("HELVETICA")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.HELVETICA_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.HELVETICA_OBLIQUE;
        else
            iTextFontName = BaseFont.HELVETICA;
    } else if (typefaceName.equals("TIMES_ROMAN")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.TIMES_BOLDITALIC;
            else
                iTextFontName = BaseFont.TIMES_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.TIMES_ITALIC;
        else
            iTextFontName = BaseFont.TIMES_ROMAN;
    } else if (typefaceName.equals("SYMBOL")) {
        iTextFontName = BaseFont.SYMBOL;
    } else if (typefaceName.equals("DINGBATS")) {
        iTextFontName = BaseFont.ZAPFDINGBATS;
    } else
    // not a base14 font. So make sure we've loaded the font files for Platypus
    // then look up this font among them. If it's still not there, then return
    // a TIMES_ROMAN and note the error.
    {
        //            if( htmlData.getTypefaceMap() == null ) {
        //                TypefaceMap typefaceMap = new TypefaceMap( htmlData.getGdd() );
        //                typefaceMap.loadFamilies();
        //                htmlData.setTypefaceMap( typefaceMap );
        //            }

        // if the font files for this typeface/font family have not been previously registered,
        // then get the filenames from the typefaceMap and register them in iText's FontFactory
        if (!FontFactory.isRegistered(typefaceName)) {
            String[] fontFiles = pdfData.getTypefaceMap().getFamilyFilenames(typefaceName);
            for (String fontFile : fontFiles) {
                FontFactory.register(fontFile);
            }
            gdd.log("Registered fonts for " + typefaceName + " in iText");
        }

        if (FontFactory.isRegistered(typefaceName)) {
            iTextFontName = typefaceName;
        } else {
            // the filename does not exist on the system, so substitute TIMES_ROMAN
            iTextFontName = BaseFont.TIMES_ROMAN;
        }
        //            }
        //            else {
        //                gdd.logInfo(
        //                        gdd.getLit( "FILE#" ) + " " + source.getFileNumber() + " " +
        //                        gdd.getLit( "LINE#" ) + " " + source.getLineNumber() + ": " +
        //                        gdd.getLit( "ERROR.INVALID_FONT_TYPEFACE" ) + " " +
        //                        f.typeface + " " +
        //                        gdd.getLit( "IGNORED" ));
        //                iTextFontName = typeface;
    }
    return (iTextFontName);
}