Example usage for com.itextpdf.text FontFactory getFont

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

Introduction

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

Prototype


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

Source Link

Document

Constructs a Font-object.

Usage

From source file:modelo.DTO.PDF_Registro2.java

public static void generar() throws DocumentException, FileNotFoundException, BadElementException, IOException {
    Rectangle pageSize = new Rectangle(816f, 1056f); //ancho y alto
    miPDF = new Document(pageSize, 0, 0, 0, 0);

    PdfWriter.getInstance(miPDF, new FileOutputStream(PDF_Registro2.rutaDestino + ".pdf"));
    miPDF.open();/*from   w  ww  .jav  a  2 s.co m*/
    miPDF.addTitle("Registro");
    miPDF.addAuthor("Universidad Tecnolgica de Len");
    miPDF.addSubject("Constancia de Registro");
    miPDF.addKeywords("1");

    //Inicio
    //Image foto = Image.getInstance("src/imagens/Registro.png");
    String thisIp = InetAddress.getLocalHost().getHostAddress();
    Image foto = Image.getInstance("http://" + thisIp + ":8084/ExamenParcial2Web/imagenes/Registro.png");
    foto.setAlignment(Chunk.ALIGN_MIDDLE);
    foto.scaleToFit(816, 754);

    miPDF.add(foto);
    PdfPTable ta = new PdfPTable(2);
    PdfPCell celda;

    celda = new PdfPCell(new Paragraph("\nClave:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + clave + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nNombre:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + nombre + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nE-mail:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + email + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nUT:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + procedencia + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    miPDF.add(ta);
    miPDF.close();

    //Fin 
    miPDF.close();
}

From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java

/**
 * Create the header for the PDF/*from  w  w w.  j a va 2  s  . c  om*/
 *
 * @return header
 */
private Paragraph header() {
    Paragraph par = new Paragraph("Eetcafe de hartige hap", FontFactory.getFont("Times-Roman", 20, Font.BOLD));

    par.setAlignment(Element.ALIGN_CENTER);

    return par;
}

From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java

/**
 * create the table for the PDF//from   w w w.j a va 2 s. c  o  m
 *
 * @return table
 */
private Paragraph table() {

    Paragraph par = new Paragraph();

    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

    Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD);
    Font normal = FontFactory.getFont("Times-Roman", 13);

    table.addCell(new Phrase("Product:", fontbold));
    table.addCell(new Phrase("Prijs:", fontbold));
    table.addCell(new Phrase("Aantal:", fontbold));
    table.addCell(new Phrase("Totaalprijs:", fontbold));

    for (ImmutableProduct product : bestelling.getProducten()) {
        table.addCell(new Phrase(product.getNaam(), normal));
        table.addCell(new Phrase(product.getPrijsFormat(), normal));
        table.addCell(new Phrase(String.valueOf(product.getAantal()), normal));

        cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("Excl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("BTW 21%", fontbold));
    cell.setBorder(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold));
    cell.setColspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Incl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);
    par.add(table);

    return par;
}

From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java

private Paragraph header() {
    Paragraph par = new Paragraph("Eetcafe de hartige hap", FontFactory.getFont("Times-Roman", 20, Font.BOLD));

    par.setAlignment(Element.ALIGN_CENTER);

    return par;/*from   w  w w .  j ava  2  s .c  o  m*/
}

From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java

private Paragraph table() {

    Paragraph par = new Paragraph();

    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);// www.  j a  v a2s.c  o m
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

    Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD);
    Font normal = FontFactory.getFont("Times-Roman", 13);

    table.addCell(new Phrase("Product:", fontbold));
    table.addCell(new Phrase("Prijs:", fontbold));
    table.addCell(new Phrase("Aantal:", fontbold));
    table.addCell(new Phrase("Totaalprijs:", fontbold));

    for (ImmutableProduct product : bestelling.getProducten()) {
        table.addCell(new Phrase(product.getNaam(), normal));
        table.addCell(new Phrase(product.getPrijsFormat(), normal));
        table.addCell(new Phrase(String.valueOf(product.getAantal()), normal));

        cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("Excl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("BTW 21%", fontbold));
    cell.setBorder(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold));
    cell.setColspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Incl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);
    par.add(table);

    return par;
}

From source file:nz.ac.waikato.cms.doc.SimplePDFOverlay.java

License:Open Source License

/**
 * Applies the instructions to the input PDF.
 *
 * @return      null if successful, otherwise error message
 */// w w  w .j av  a2 s .c  om
public String execute() {
    String result;
    String line;
    BufferedReader breader;
    FileReader freader;
    int i;
    int lineNo;
    String units;
    int pageNo;
    PdfReader reader;
    PdfStamper stamper;
    PdfContentByte cb;
    ColumnText ct;
    Font font;
    String[] parts;
    StringBuilder text;

    result = null;

    freader = null;
    breader = null;
    try {
        reader = new PdfReader(new FileInputStream(m_Pdf.getAbsolutePath()));
        stamper = new PdfStamper(reader, new FileOutputStream(m_Output.getAbsolutePath()));
        freader = new FileReader(m_Instructions);
        breader = new BufferedReader(freader);
        lineNo = 0;
        units = "pt";
        pageNo = 1;
        cb = stamper.getOverContent(pageNo);
        font = null;
        while ((line = breader.readLine()) != null) {
            lineNo++;
            if (line.trim().startsWith(PREFIX_COMMENT))
                continue;
            if (line.trim().length() == 0)
                continue;
            if (line.startsWith(PREFIX_UNITS)) {
                units = line.substring(PREFIX_UNITS.length()).trim().toLowerCase();
            } else if (line.startsWith(PREFIX_PAGE)) {
                pageNo = Integer.parseInt(line.substring(PREFIX_PAGE.length()).trim());
                cb = stamper.getOverContent(pageNo);
            } else if (line.startsWith(PREFIX_FONT)) {
                parts = line.substring(PREFIX_FONT.length()).trim().split(" ");
                if (parts.length == 3)
                    font = FontFactory.getFont(parts[0], Float.parseFloat(parts[1]),
                            new BaseColor(parseColor(parts[2]).getRGB()));
                else
                    m_Logger.warning("Font instruction not in expected format (" + FORMAT_FONT + "):\n" + line);
            } else if (line.startsWith(PREFIX_TEXT)) {
                parts = line.substring(PREFIX_TEXT.length()).trim().split(" ");
                if (parts.length >= 7) {
                    ct = new ColumnText(cb);
                    ct.setSimpleColumn(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // llx
                            parseLocation(parts[1], reader.getPageSize(pageNo).getHeight(), units), // lly
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // urx
                            parseLocation(parts[3], reader.getPageSize(pageNo).getHeight(), units), // ury
                            Float.parseFloat(parts[4]), // leading
                            parseAlignment(parts[5])); // alignment
                    text = new StringBuilder();
                    for (i = 6; i < parts.length; i++) {
                        if (text.length() > 0)
                            text.append(" ");
                        text.append(parts[i]);
                    }
                    if (font == null)
                        ct.setText(new Phrase(text.toString()));
                    else
                        ct.setText(new Phrase(text.toString(), font));
                    ct.go();
                } else {
                    m_Logger.warning("Text instruction not in expected format (" + FORMAT_TEXT + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_LINE)) {
                parts = line.substring(PREFIX_LINE.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // color
                    cb.moveTo(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units)); // y
                    cb.lineTo(parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units)); // h
                    cb.stroke();
                    cb.restoreState();
                } else {
                    m_Logger.warning("Line instruction not in expected format (" + FORMAT_LINE + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_RECT)) {
                parts = line.substring(PREFIX_RECT.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.rectangle(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // h
                    );
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke
                    if (parts.length >= 7) {
                        cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill
                        cb.fillStroke();
                    } else {
                        cb.stroke();
                    }
                    cb.restoreState();
                } else {
                    m_Logger.warning(
                            "Rectangle instruction not in expected format (" + FORMAT_RECT + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_OVAL)) {
                parts = line.substring(PREFIX_OVAL.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.ellipse(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x1
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y1
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // x2
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // y2
                    );
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke
                    if (parts.length >= 7) {
                        cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill
                        cb.fillStroke();
                    } else {
                        cb.stroke();
                    }
                    cb.restoreState();
                } else {
                    m_Logger.warning("Oval instruction not in expected format (" + FORMAT_OVAL + "):\n" + line);
                }
            } else {
                m_Logger.warning("Unknown command on line #" + lineNo + ":\n" + line);
            }
        }
        stamper.close();
    } catch (Exception e) {
        result = "Failed to process!\n" + Utils.throwableToString(e);
    } finally {
        FileUtils.closeQuietly(breader);
        FileUtils.closeQuietly(freader);
    }

    return result;
}

From source file:om.edu.squ.squportal.portlet.tsurvey.dao.pdf.TeachingSurveyPdfImpl.java

License:Open Source License

/**
 * //  ww  w  .  j ava 2  s.  co m
 * method name  : getPdfSurveyAnalysis
 * @param object
 * @param semesterYear
 * @param questionByYear
 * @param questionSetNo
 * @param byos
 * @param inputStream
 * @param res
 * @return
 * @throws DocumentException
 * @throws IOException
 * TeachingSurveyPdfImpl
 * return type  : OutputStream
 * 
 * purpose      : Generate PDF content
 *
 * Date          :   Mar 28, 2016 7:21:04 PM
 */
public OutputStream getPdfSurveyAnalysis(Object object, String semesterYear, String questionByYear,
        int questionSetNo, ByteArrayOutputStream byos, InputStream inputStream, ResourceResponse res)
        throws DocumentException, IOException {

    Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, BaseColor.BLACK);

    PdfReader pdfTemplate = new PdfReader(inputStream);
    PdfStamper pdfStamper = new PdfStamper(pdfTemplate, byos);
    Survey survey = (Survey) object;
    String sectionNos = "";
    String seatsTaken = "";
    DecimalFormat formatter = new DecimalFormat("###.##");

    String RIGHT = Constants.RIGHT;
    String CENTER = Constants.CENTER;
    String LEFT = Constants.LEFT;

    pdfStamper.getAcroFields().setField("txtCourse", survey.getCourseCode() + " / " + survey.getCourseName());
    pdfStamper.getAcroFields().setField("txtCollegeName", survey.getCollegeName());

    for (SurveyResponse resp : survey.getSurveyResponses()) {
        sectionNos = sectionNos + resp.getSectionNo() + " ";
        seatsTaken = String.valueOf(resp.getSeatsTaken());
    }

    pdfStamper.getAcroFields().setField("txtSectionNo", sectionNos);
    pdfStamper.getAcroFields().setField("txtDepartmentName", survey.getDepartmentName());
    pdfStamper.getAcroFields().setField("txtEmpName", survey.getEmpName());
    pdfStamper.getAcroFields().setField("txtStudentRegistered", seatsTaken);

    pdfStamper.getAcroFields().setField("txtSemesterYear", semesterYear);

    pdfStamper.getAcroFields().setGenerateAppearances(true);

    /* ****************** */

    PdfPTable table = new PdfPTable(13);

    table.addCell(getPdfCell("", 2, 0, font, LEFT));
    table.addCell(getPdfCell(
            UtilProperty.getMessage("prop.course.teaching.survey.analysis.course.teaching.items", null), 2, 0,
            font, CENTER));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.response.number", null), 0,
                    6, font, CENTER));
    table.addCell(getPdfCell(
            UtilProperty.getMessage("prop.course.teaching.survey.analysis.response.percentage", null), 2, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.mean", null), 0, 4,
            font, CENTER));

    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.disagree.strong", null), 0,
                    0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.disagree", null), 0,
            0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.agree", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.agree.strong", null),
            0, 0, font, CENTER));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.applicable.not", null), 0,
                    0, font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.total", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.sect", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.crs", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.dept", null), 0, 0,
            font, CENTER));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.col", null), 0, 0,
            font, CENTER));

    /* ---------------------------------------------------------------------------- */
    table.addCell(getPdfCell("", 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.course.items", null),
            0, 12, font, CENTER));

    int cTotal = 0;
    float cPctVal = 0f;
    float cSectionMean = 0f;
    float cCourseMean = 0f;
    float cDepart = 0f;
    float cCollege = 0f;
    int rowCount = 0;

    for (SurveyResponse sures : survey.getSurveyResponses()) {
        for (Analysis analysis : sures.getAnalysisList()) {
            if (analysis.getQuestion().equals("Q2") || analysis.getQuestion().equals("Q14")
                    || analysis.getQuestion().equals(questionByYear)) {
                /***  First part    ***/
                table.addCell(getPdfCell(analysis.getQuestion(), 0, 0, font));
                table.addCell(
                        getPdfCell(
                                UtilProperty.getMessage("prop.course.teaching.survey.analysis.set"
                                        + questionSetNo + ".question" + analysis.getQuestionLabel(), null),
                                0, 0, font, LEFT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongDisagree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDisAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getNotApplicable()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getTotal()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getPercentageResponse()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getSectionMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCourseMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDepartmentMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCollegeMean()), 0, 0, font, RIGHT));

                cTotal = cTotal + analysis.getTotal();
                cPctVal = cPctVal + analysis.getPercentageResponse();
                cSectionMean = cSectionMean + analysis.getSectionMean();
                cCourseMean = cCourseMean + analysis.getCollegeMean();
                cDepart = cDepart + analysis.getDepartmentMean();
                cCollege = cCollege + analysis.getCollegeMean();
                rowCount = rowCount + 1;

            }
        }
    }

    /***  First part - Summary   ***/
    table.addCell(getPdfCell(String.valueOf(""), 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.summary", null), 0,
            0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(""), 0, 5, font));
    table.addCell(getPdfCell(String.valueOf(cTotal), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cPctVal / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cSectionMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCourseMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cDepart / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCollege / rowCount)), 0, 0, font, RIGHT));

    table.addCell(getPdfCell("", 0, 13, font));

    table.addCell(getPdfCell("", 0, 0, font));
    table.addCell(
            getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.teaching.items", null), 0,
                    12, font, LEFT));

    cTotal = 0;
    cPctVal = 0f;
    cSectionMean = 0f;
    cCourseMean = 0f;
    cDepart = 0f;
    cCollege = 0f;
    rowCount = 0;
    for (SurveyResponse sures : survey.getSurveyResponses()) {
        for (Analysis analysis : sures.getAnalysisList()) {
            if (!(analysis.getQuestion().equals("Q2") || analysis.getQuestion().equals("Q14")
                    || analysis.getQuestion().equals(questionByYear))) {

                table.addCell(getPdfCell(analysis.getQuestion(), 0, 0, font));
                table.addCell(
                        getPdfCell(
                                UtilProperty.getMessage("prop.course.teaching.survey.analysis.set"
                                        + questionSetNo + ".question" + analysis.getQuestionLabel(), null),
                                0, 0, font, LEFT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongDisagree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDisAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getStrongAgree()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getNotApplicable()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getTotal()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getPercentageResponse()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getSectionMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCourseMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getDepartmentMean()), 0, 0, font, RIGHT));
                table.addCell(getPdfCell(String.valueOf(analysis.getCollegeMean()), 0, 0, font, RIGHT));

                cTotal = cTotal + analysis.getTotal();
                cPctVal = cPctVal + analysis.getPercentageResponse();
                cSectionMean = cSectionMean + analysis.getSectionMean();
                cCourseMean = cCourseMean + analysis.getCollegeMean();
                cDepart = cDepart + analysis.getDepartmentMean();
                cCollege = cCollege + analysis.getCollegeMean();
                rowCount = rowCount + 1;

            }

        }

    }

    /***  Second part - Summary   ***/
    table.addCell(getPdfCell(String.valueOf(""), 0, 0, font));
    table.addCell(getPdfCell(UtilProperty.getMessage("prop.course.teaching.survey.analysis.summary", null), 0,
            0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(""), 0, 5, font));
    table.addCell(getPdfCell(String.valueOf(cTotal), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cPctVal / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cSectionMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCourseMean / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cDepart / rowCount)), 0, 0, font, RIGHT));
    table.addCell(getPdfCell(String.valueOf(formatter.format(cCollege / rowCount)), 0, 0, font, RIGHT));

    if (!survey.getMessage().equals("")) {
        table.addCell(getPdfCell("", 0, 13, font));
        table.addCell(getPdfCell("", 0, 0, font));
        table.addCell(getPdfCell(survey.getMessage(), 0, 12, font, CENTER));
    }

    table.setTotalWidth(750);
    table.setLockedWidth(true);
    table.setWidths(new float[] { 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });

    ColumnText column = new ColumnText(pdfStamper.getOverContent(1));
    Rectangle rectPage1 = new Rectangle(120, 20, 659, 480);

    column.setSimpleColumn(rectPage1);
    column.addElement(table);

    int status = column.go();

    pdfStamper.setFormFlattening(true);

    pdfStamper.close();

    pdfTemplate.close();

    res.setContentType("application/pdf");

    return res.getPortletOutputStream();

}

From source file:org.com.controller.ProductController.java

@RequestMapping(value = "/repProduct", method = RequestMethod.GET)
public void productReport(Model m, HttpServletResponse response, HttpServletRequest request,
        OutputStream outputStream) throws Exception {
    String name = "ProductReport-";
    Date d = new Date();
    name = name + d.toString() + ".pdf";
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=" + name);
    Rectangle pagesize = new Rectangle(216f, 720f);
    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, outputStream);
    document.open();/*from  w w  w.j  av  a2  s  . c  o  m*/
    document.addTitle("PRODUCT DETAILSA REPORT");
    document.add(new Paragraph("PRODUCT DETAILSA REPORT ",
            FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN)));
    document.add(new Paragraph("DATE: " + new Date()));
    document.add(new Paragraph("-------------------------------------------------------- "));
    document.add(new Paragraph(" "));
    ProductDaoImpl pdi = new ProductDaoImpl();
    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell("ID");
    table.addCell("TITLE");
    table.addCell("PUBLISHER");
    table.addCell("PRICE");
    ArrayList<ProductTable> list = pdi.getAllProduct();
    for (ProductTable u : list) {
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPid().toString());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getPname());
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPublisher());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getSprice().toString());
    }
    document.add(table);
    document.close();

}

From source file:org.dspace.disseminate.CitationDocument.java

/**
 * Takes a DSpace {@link Bitstream} and uses its associated METADATA to
 * create a cover page./*from w w w . ja  v  a 2  s .c  o  m*/
 *
 * @param cDoc The cover page document to add cited information to.
 * @param writer
 * @param cMeta
 *            METADATA retrieved from the parent collection.
 * @throws IOException
 * @throws DocumentException
 */
private void generateCoverPage(Document cDoc, PdfWriter writer, CitationMeta cMeta) throws DocumentException {
    cDoc.open();
    writer.setCompressionLevel(0);

    Item item = cMeta.getItem();

    //Set up some fonts
    Font helv26 = FontFactory.getFont(FontFactory.HELVETICA, 26f, BaseColor.BLACK);
    Font helv16 = FontFactory.getFont(FontFactory.HELVETICA, 16f, BaseColor.BLACK);
    Font helv12 = FontFactory.getFont(FontFactory.HELVETICA, 12f, BaseColor.BLACK);
    Font helv12_italic = FontFactory.getFont(FontFactory.HELVETICA_OBLIQUE, 12f, BaseColor.BLACK);
    Font helv11_bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11f, BaseColor.BLACK);
    Font helv9 = FontFactory.getFont(FontFactory.HELVETICA, 9f, BaseColor.BLACK);

    // 1 - Header:
    //  University Name
    //  Repository Name                                                        repository.url
    Paragraph university = new Paragraph("The Ohio State University", helv11_bold);
    cDoc.add(university);

    PdfPTable repositoryTable = new PdfPTable(2);
    repositoryTable.setWidthPercentage(100);

    Chunk repositoryName = new Chunk("Knowledge Bank", helv11_bold);
    PdfPCell nameCell = new PdfPCell();
    nameCell.setBorderWidth(0);
    nameCell.addElement(repositoryName);

    Chunk repositoryURL = new Chunk("kb.osu.edu", helv11_bold);
    repositoryURL.setAnchor("http://kb.osu.edu");

    PdfPCell urlCell = new PdfPCell();
    urlCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    urlCell.setBorderWidth(0);
    urlCell.addElement(repositoryURL);

    repositoryTable.addCell(nameCell);
    repositoryTable.addCell(urlCell);

    repositoryTable.setSpacingAfter(5);

    cDoc.add(repositoryTable);

    // Line Separator
    LineSeparator lineSeparator = new LineSeparator();
    cDoc.add(lineSeparator);

    // 2 - Bread Crumbs
    // Community Name                                                          Collection Name
    PdfPTable breadcrumbTable = new PdfPTable(2);
    breadcrumbTable.setWidthPercentage(100);

    Chunk communityName = new Chunk(getOwningCommunity(item), helv9);
    PdfPCell commCell = new PdfPCell();
    commCell.setBorderWidth(0);
    commCell.addElement(communityName);

    Chunk collectionName = new Chunk(getOwningCollection(item), helv9);
    PdfPCell collCell = new PdfPCell();
    collCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    collCell.setBorderWidth(0);
    collCell.addElement(collectionName);

    breadcrumbTable.addCell(commCell);
    breadcrumbTable.addCell(collCell);

    breadcrumbTable.setSpacingBefore(5);
    breadcrumbTable.setSpacingAfter(5);

    cDoc.add(breadcrumbTable);

    // Line Separator
    cDoc.add(lineSeparator);

    // 3 - Metadata
    // date.issued
    // dc.title
    // dc.creator; dc.creator
    Paragraph dateIssued = new Paragraph(getFirstMetadata(item, "dc.date.issued"), helv12);
    dateIssued.setSpacingBefore(20);
    cDoc.add(dateIssued);

    Paragraph title = new Paragraph(item.getName(), helv26);
    title.setSpacingBefore(15);
    cDoc.add(title);

    Paragraph creators = new Paragraph(getAllMetadataSeperated(item, "dc.creator"), helv16);
    creators.setSpacingBefore(30);
    creators.setSpacingAfter(20);
    cDoc.add(creators);

    // Line Separator
    cDoc.add(lineSeparator);

    // 4 - Citation
    // dc.identifier.citation
    // dc.identifier.uri
    Paragraph citation = new Paragraph(getFirstMetadata(item, "dc.identifier.citation"), helv12);

    Chunk identifierChunk = new Chunk(getFirstMetadata(item, "dc.identifier.uri"), helv12);
    identifierChunk.setAnchor(getFirstMetadata(item, "dc.identifier.uri"));

    Paragraph identifier = new Paragraph();
    identifier.add(identifierChunk);

    cDoc.add(citation);
    cDoc.add(identifier);

    // 5 - License
    // Downloaded from the Knowledge Bank, The Ohio State University's institutional repository
    Paragraph license = new Paragraph(
            "Downloaded from the Knowledge Bank, The Ohio State University's institutional repository",
            helv12_italic);
    license.setSpacingBefore(10);
    cDoc.add(license);

    cDoc.close();
}

From source file:org.flowable.app.rest.runtime.RelatedContentResource.java

License:Apache License

void createPdf(String dest, ArrayList<String> info) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();//from   ww  w.java 2s. c  om
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Chunk chunk = new Chunk("Relatrio", chapterFont);
    Chapter chapter = new Chapter(new Paragraph(chunk), 1);
    chapter.setNumberDepth(0);

    int i = 0;
    for (; i < info.size(); i++) {
        chapter.add(new Paragraph(info.get(i), paragraphFont));
    }
    document.add(chapter);
    document.close();
}