Example usage for com.lowagie.text Font Font

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

Introduction

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

Prototype


public Font() 

Source Link

Document

Constructs a Font.

Usage

From source file:com.geek.tutorial.itext.bookmarks.Anchor.java

License:Open Source License

public Anchor() throws Exception {

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("anchor.pdf"));
    document.open();/*from  www. j  av a 2 s. c  o  m*/

    // Code 1
    Font font = new Font();
    font.setColor(Color.BLUE);
    font.setStyle(Font.UNDERLINE);

    document.add(new Chunk("Chapter 1"));
    document.add(new Paragraph(new Chunk("Press here to go chapter 2", font).setLocalGoto("2")));// Code 2
    document.newPage();

    document.add(new Chunk("Chapter 2").setLocalDestination("2"));
    document.add(new Paragraph(
            new Chunk("http://www.geek-tutorials.com", font).setAnchor("http://www.geek-tutorials.com")));//Code 3
    document.add(
            new Paragraph(new Chunk("Open outline.pdf chapter 3", font).setRemoteGoto("outline.pdf", "3")));//Code 4

    document.close();

}

From source file:com.krawler.esp.servlets.ExportMPXServlet.java

License:Open Source License

public void createPDFFile(Connection conn, HttpServletRequest request, HttpServletResponse response)
        throws ConfigurationException {
    String projid = request.getParameter("projectid");
    try {//from  ww w . j  av a2 s .  co m
        String userid = AuthHandler.getUserid(request);
        String companyid = AuthHandler.getCompanyid(request);
        String tasks = projdb.getProjectTasks(conn, projid, userid, companyid, 0, -1, true);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        Document document = new Document(PageSize.A4);
        document.setPageSize(PageSize.A4.rotate());
        PdfWriter writer = PdfWriter.getInstance(document, os);
        setHeaderFooter(document, request.getParameter("header"));
        JSONObject jobj = new JSONObject(request.getParameter("options"));
        JSONArray jarr = jobj.getJSONArray("data");
        ArrayList tabCols = new ArrayList();
        ArrayList tabArr = createTables(jarr, tabCols, document);//new ArrayList();
        writer.setPageEvent(new EndPage());

        HashMap taskIdIndex = new HashMap();
        JSONArray taskArr = new com.krawler.utils.json.base.JSONObject(tasks).getJSONArray("data");
        for (int c = 0; c < taskArr.length(); c++) {
            com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c);
            taskIdIndex.put(temp.getString("taskid"), temp.getInt("taskindex"));
        }
        taskIdIndex.put("0", 0);
        for (int c = 0; c < taskArr.length(); c++) {
            com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c);
            String pred = "";
            if (!StringUtil.isNullOrEmpty(temp.getString("predecessor"))) {
                String[] p = temp.getString("predecessor").split(",");
                for (int i = 0; i < p.length; i++) {
                    pred += taskIdIndex.get(p[i]).toString() + ",";
                }
                pred = pred.substring(0, (pred.length() - 1));
            }
            String taskResourceNames = projdb.getTaskResourcesNames(conn, temp.getString("taskid"), projid);
            for (int i = 0; i < tabArr.size(); i++) {
                int lvl = 0;
                if (i == 0) {
                    lvl = temp.getInt("level");
                }
                String[] colArr = (String[]) tabCols.get(i);
                String[] values = getPDFCellOfRec(colArr, temp, pred, taskResourceNames);
                Font fnt = new Font();
                if (temp.getBoolean("isparent")) {
                    fnt.setStyle(Font.BOLD);
                } else {
                    fnt.setStyle(Font.NORMAL);
                }
                addPdfRowToTable(values, (PdfPTable) tabArr.get(i), fnt, lvl);
            }
        }
        document.open();
        getCompanyDetails(request);
        addComponyLogo(document);
        for (int i = 0; i < tabArr.size(); i++) {
            PdfPTable temp = (PdfPTable) tabArr.get(i);
            temp.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
            document.add(temp);
            document.newPage();
        }
        document.close();
        os.close();
        String fname = request.getParameter("filename");
        os.close();
        response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + ".pdf\"");
        response.setContentType("application/octet-stream");
        response.setContentLength(os.size());
        response.getOutputStream().write(os.toByteArray());
        response.getOutputStream().flush();
        String type = "[PDF]";
        AddToAuditTrail(conn, request, projid, type);
        conn.commit();
    } catch (ServiceException ex) {
        Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException e) {
        Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e);
    } catch (SessionExpiredException e) {
        Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e);
    }
}

From source file:com.krawler.esp.servlets.ExportMPXServlet.java

License:Open Source License

public static PdfPTable createPdfTable(ArrayList header, ArrayList widths, ArrayList tabCol, Document doc)
        throws DocumentException {
    PdfPTable temp = new PdfPTable(header.size());
    float[] wid = new float[widths.size()];
    String[] cols = new String[header.size()];
    for (int i = 0; i < widths.size(); i++) {
        wid[i] = (float) (Integer.parseInt(widths.get(i).toString()));
        cols[i] = header.get(i).toString();
    }/*from w w  w . j a v  a 2  s.  c  o m*/
    temp.setWidthPercentage(wid, doc.getPageSize());
    temp.setTotalWidth(100);
    Font fnt1 = new Font();
    fnt1.setStyle(Font.NORMAL);
    addPdfRowToTable(cols, temp, fnt1, 0);
    temp.setHeaderRows(1);
    tabCol.add(cols);
    return temp;
}

From source file:com.mycompany.devman.domain.Raport.java

public static void main(String[] args) {

    Document document = new Document(); // Tworzymy dokument

    //* Ustawianie rozmiarw dokumentu
    Rectangle rect = new Rectangle(PageSize.A4); //Tworzenie elementu - rozmiaru dokumentu, ktry bdzie kwadratem o rozmiarze 210mm x 297mm - format a4
    // Utilities.millimetersToPoints(210), Utilities.millimetersToPoints(297)
    document.setPageSize(rect);/* www.j a v  a  2s .com*/

    Font[] fonts = { new Font(), new Font(Font.HELVETICA, 14, Font.NORMAL) };

    try { //Blok Try jest po to poniewa nie zawsze moemy mie miejsce tam gdzie chcemy zapisa pdf
        PdfWriter.getInstance(document, new FileOutputStream("raport.pdf"));

        document.open(); //Otwarcie dokumentu - teraz moemy do niego wsadza co kolwiek chcemy
        Paragraph paragraph = new Paragraph();
        paragraph.add("Raport");
        document.add(paragraph); //dodanie paragrafu do dokumentu
        document.close();
    } catch (Exception e) {
        e.printStackTrace(); // Wywietli error
    }

}

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  a2  s  .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:fr.opensagres.xdocreport.itext.extension.ExtendedChunk.java

License:Open Source License

public ExtendedChunk(ExtendedDocument ownerDocument, String textContent) {
    this(ownerDocument, textContent, new Font());
}

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  . jav  a  2s  . c o m
    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() {
    /*//from  w  w w .  j  a  v  a  2  s  . c  o m
     * Font for anchors (links)
     */
    Font linkFont = new Font();
    linkFont.setStyle(Font.UNDERLINE);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(linkFontSize);

    return linkFont;
}

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

License:Open Source License

private Font createHeaderFont() {
    /*/*from  www. j a  va2 s  .c  o  m*/
     * Font for the headers
     */
    Font headerFont = new Font();
    headerFont.setStyle(Font.BOLD);
    headerFont.setSize(headerFontSize);

    return headerFont;
}

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

License:Open Source License

private void addReplyLink(Document document, String replyURL) throws DocumentException {
    PdfPTable replyTable = new PdfPTable(1);
    replyTable.setWidthPercentage(100f);

    replyTable.setSplitLate(false);//from  www  . jav a2 s.  com

    replyTable.setSpacingBefore(5f);
    replyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    Font linkFont = new Font();

    linkFont.setStyle(Font.BOLD);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(headerFontSize);

    Chunk anchor = new Chunk("Reply", linkFont);

    anchor.setAnchor(replyURL);

    Phrase phrase = new Phrase();

    phrase.add(anchor);

    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(Rectangle.NO_BORDER);

    replyTable.addCell(cell);

    document.add(replyTable);
}