Example usage for com.lowagie.text Font setSize

List of usage examples for com.lowagie.text Font setSize

Introduction

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

Prototype

public void setSize(float size) 

Source Link

Document

Sets the size.

Usage

From source file:com.conecta.sat.utils.BuildPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition", "attachment; filename=Reporte" + name.format(new Date()) + ".pdf");
    List<PdfDTO> list = (List<PdfDTO>) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(9);
    table.setWidthPercentage(100);//from  w  ww .  j ava2  s  .  co  m
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Reporte de Tokens", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph(df.format(new Date()), font);
    fecha.setAlignment(Element.ALIGN_RIGHT);
    document.add(fecha);

    Paragraph pNombre = new Paragraph(nombreUsuario, font);
    pNombre.setAlignment(Element.ALIGN_RIGHT);
    document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Serial Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Estatus Entrega", font));
    cell.setPhrase(new Phrase("Estatus Entrega al Centro Financiero", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Estatus Entrega al Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Estatus Activacin", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Centro Financiero", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente nico", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Folio Pivotal", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("ID nico", font));
    //        table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha de ltima modificacin", font));
    table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    for (PdfDTO pdf : list) {
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getSerial(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getEntrega(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getEntrega(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getActivacion(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getCentro(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getTipo(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getCliente(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getFolioPivotal(), font2));
        table.addCell(cell);

        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
        //            cell.addElement( new Phrase(pdf.getIdUnico(),font2) );
        //            table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getLastUpdate(), font2));
        table.addCell(cell);
    }

    document.add(table);
}

From source file:com.krawler.accounting.fontsetting.FontFamilySelector.java

License:Open Source License

private void applyPropertiesToFont(Font font, Color color, Float size, Integer style) {
    if (color != null)
        font.setColor(color);//w  ww  .  jav a 2  s. c o  m
    if (size != null)
        font.setSize(size);
    if (style != null)
        font.setStyle(style);
}

From source file:cz.incad.kramerius.pdf.utils.pdf.FontMap.java

License:Open Source License

public FontMap(File fontDirectory) throws DocumentException, IOException {
    super();/*from   www .  j a  va  2 s. c  o m*/
    this.fontDirectory = fontDirectory;

    Font logoFont = createGentiumFont(this.fontDirectory);
    logoFont.setSize(48f);

    Font normalFont = createGentiumFont(this.fontDirectory);
    normalFont.setSize(14f);

    Font strongFont = createGentiumFont(this.fontDirectory);
    strongFont.setSize(14f);
    strongFont.setStyle(Font.BOLD);

    Font header4Font = createGentiumFont(this.fontDirectory);
    header4Font.setSize(16f);
    header4Font.setStyle(Font.BOLD);

    Font smallerFont = createGentiumFont(this.fontDirectory);
    smallerFont.setSize(12f);

    Font smallFont = createGentiumFont(this.fontDirectory);
    smallFont.setSize(10f);

    this.registerFont(NORMAL_FONT, normalFont);
    this.registerFont(STRONG_FONT, strongFont);
    this.registerFont(LOGO_FONT, logoFont);
    this.registerFont(HEADER4_FONT, header4Font);
    this.registerFont(SMALLER_FONT, smallerFont);
    this.registerFont(SMALL_FONT, smallFont);

}

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {/*w ww  . ja v  a 2  s .  c om*/
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:EplanPrinter.RTFWrite.java

License:Open Source License

public String addItem(String comment, String category, String group) throws DocumentException, IOException {
    if (cg.compareTo(group) != 0) {
        count = 1;/*  ww w  . j  a  v a 2s .  c o m*/
        cg = group;
        cc = category;

        Font groupContent = new Font();
        groupContent.setStyle("bold");
        groupContent.setStyle("underline");
        groupContent.setSize(12);
        Paragraph g = new Paragraph(group, groupContent);

        Font catContent = new Font();
        catContent.setSize(12);
        Paragraph c = new Paragraph(category, catContent);
        c.setIndentationLeft(30);
        document.add(g);
        document.add(c);
    } else if (cc.compareTo(category) != 0) {
        count = 1;
        cc = category;
        Paragraph c = new Paragraph(category);
        c.setIndentationLeft(30);
        document.add(c);
    }
    Paragraph p = new Paragraph();
    //document.add(p);
    String test = count + ". " + comment;
    test = test.replaceAll("<p>", " ");
    test = test.replaceAll("</p>", " ");

    if (test.indexOf("<ol>") != -1) {
        test = test.replaceAll("<ol>", "");
        test = test.replaceAll("</ol>", "");
        test = test.replaceAll("</li>", "<br />");
        int subCount = 1;
        while (test.indexOf("<li>") != -1) {
            test = test.replaceFirst("<li>", subCount + ". ");
            subCount++;
        }
        int marker = test.lastIndexOf("<br />");
        String sub1 = test.substring(0, marker);
        String sub2 = test.substring(marker);
        sub2 = sub2.replaceAll("<br />", "");
        test = sub1 + sub2;
    }
    if (test.indexOf("<ul>") != -1) {
        test = test.replaceAll("<ul>", "");
        test = test.replaceAll("</ul>", "");
        test = test.replaceAll("</li>", "<br />");
        int c = 149;
        char ch = (char) 149;
        test = test.replaceAll("<li>", "&bull;");
        int marker = test.lastIndexOf("<br />");
        String sub1 = test.substring(0, marker);
        String sub2 = test.substring(marker);
        sub2 = sub2.replaceAll("<br />", "");
        test = sub1 + sub2;
    }

    StringReader str = new StringReader(test);
    List<Element> e = HTMLWorker.parseToList(str, null);
    for (int k = 0; k < e.size(); ++k) {
        p.add((com.lowagie.text.Element) e.get(k));
    }

    p.setIndentationLeft(40);
    p.setFirstLineIndent(30);
    document.add(p);

    count = count + 1;

    return "";
}

From source file:ilarkesto.integration.itext.Paragraph.java

License:Open Source License

private Font createFont(String name, FontStyle fontStyle) {
    Font font;
    try {/*from   ww w. ja v  a2 s .co m*/
        font = new Font(BaseFont.createFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    } catch (Exception ex) {
        throw new RuntimeException("Loading font failed: " + name, ex);
    }

    if (fontStyle != null) {
        font.setStyle(createStyle(fontStyle));
        font.setSize(PdfBuilder.mmToPoints(fontStyle.getSize()));
        font.setColor(fontStyle.getColor());
    }

    return font;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public void createCommuneFooter(PdfWriter writer) throws Exception {

    PdfContentByte cb = writer.getDirectContent();
    Font nameFont = getDefaultParagraphFont();
    nameFont.setSize(9);
    Font textFont = getDefaultTextFont();
    textFont.setSize(9);//from   w w  w.java  2 s  .  co  m

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setNoWrap(true);

    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);

    table.addCell(new Phrase(iwb.getProperty("commune.name_mailaddr", "Mailaddress"), nameFont));
    table.addCell(new Phrase(iwb.getProperty("commune.name_visitaddr", "Visitaddress"), nameFont));
    table.addCell(new Phrase(iwb.getProperty("commune.name_contact", "Contact"), nameFont));
    table.addCell(new Phrase(iwb.getProperty("commune.name_org_nr", "Organizationsnr"), nameFont));

    table.addCell(new Phrase(iwb.getProperty("commune.mail_name", "Mail name"), getTextFont()));
    table.addCell(new Phrase(iwb.getProperty("commune.visit_name", "Visit name"), textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.website", "www.some-place.com"), textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.org_number", "XXXXXX-XXXX"), textFont));

    table.addCell(new Phrase(iwb.getProperty("commune.mail_zip", "Zip code"), textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.visit_streetaddr", "Street and number,"), textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.support_email", "email@someplace.com"), textFont));
    table.addCell(new Phrase(" ", textFont));

    table.addCell(new Phrase(" ", textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.visit_zip", "Visit zip"), textFont));
    table.addCell(new Phrase(iwb.getProperty("commune.office_phone", "office phone"), textFont));
    table.addCell(new Phrase(" ", textFont));

    int distFromBottomMM = 30;
    int[] widths = { 20, 20, 30, 20 };
    table.setWidths(widths);
    table.setTotalWidth(getPointsFromMM(210 - 25 - 20));
    table.writeSelectedRows(0, -1, getPointsFromMM(25), getPointsFromMM(distFromBottomMM), cb);

    PdfContentByte linebyte = new PdfContentByte(writer);
    // we add some crosses to visualize the destinations

    linebyte.moveTo(getPointsFromMM(25), getPointsFromMM(distFromBottomMM + 2));
    linebyte.lineTo(getPointsFromMM(210 - 25), getPointsFromMM(distFromBottomMM + 2));

    linebyte.stroke();

    // we add the template on different positions
    cb.add(linebyte);
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private Font decodeFont(String fontstring, Font returnFont) {
    if (fontstring != null) {
        int family = -1;
        StringTokenizer tokener = new StringTokenizer(fontstring, "-");
        // family part
        if (tokener.hasMoreTokens()) {
            family = Font.getFamilyIndex(tokener.nextToken());
        }//from w w w  .  j  a  v a  2  s  .  c  o  m
        if (family > -1) {
            Font font = new Font(family);
            // size part
            if (tokener.hasMoreTokens()) {
                float size = Float.parseFloat(tokener.nextToken());
                font.setSize(size);
            }
            // style part
            if (tokener.hasMoreTokens()) {
                font.setStyle(tokener.nextToken());
            }
            // color part
            if (tokener.hasMoreTokens()) {
                font.setColor(IWColor.getAWTColorFromHex(tokener.nextToken()));
            }
            return font;
        }
    }
    return returnFont;
}

From source file:managedbean.afos.FlightDutyBacking.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();/*from   w  w  w  .ja  v a2 s .c om*/
    pdf.setPageSize(PageSize.A4);
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "logo.png";
    Image logoImg = Image.getInstance(logo);
    logoImg.scalePercent(20f);
    SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a");

    Font titleFont = new Font();
    Font subtitleFont = new Font();
    titleFont.setSize(16);
    titleFont.setStyle(Font.BOLD);
    subtitleFont.setSize(12);
    subtitleFont.setStyle(Font.BOLD);

    Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont);
    title.setAlignment(Element.ALIGN_CENTER);
    title.setSpacingAfter(12f);

    Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont);
    subTitle1.setSpacingAfter(8f);

    Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont);
    subTitle2.setSpacingBefore(12f);
    subTitle2.setSpacingAfter(12f);

    com.lowagie.text.List list = new com.lowagie.text.List(true, 15);
    list.setLettered(true);
    list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo());
    list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo());
    Airport departure, arrival;
    departure = selectedFlightSchedule.getLeg().getDepartAirport();
    arrival = selectedFlightSchedule.getLeg().getArrivalAirport();
    sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure)));
    list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " ("
            + departure.getCity().getCityName() + " Time)");
    sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival)));
    list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " ("
            + arrival.getCity().getCityName() + " Time)");
    list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")");
    list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")");

    pdf.add(logoImg);
    pdf.add(new Paragraph(" "));
    pdf.add(title);
    pdf.add(subTitle1);
    pdf.add(list);
    pdf.add(subTitle2);
    pdf.setMargins(72, 72, 72, 72);
    pdf.addAuthor("Merlion Airline");
    pdf.addCreationDate();
    sdf.applyPattern("dd/MM/yyyy_hh:mm:ss");
    pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_"
            + sdf.format(selectedFlightSchedule.getDepartDate()));
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private Font createLinkFont() {
    /*/*w  w  w  . j  a  v  a2  s.co m*/
     * Font for anchors (links)
     */
    Font linkFont = new Font();
    linkFont.setStyle(Font.UNDERLINE);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(linkFontSize);

    return linkFont;
}