Example usage for com.lowagie.text Font NORMAL

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

Introduction

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

Prototype

int NORMAL

To view the source code for com.lowagie.text Font NORMAL.

Click Source Link

Document

this is a possible style.

Usage

From source file:demo.dwr.simple.UploadDownload.java

License:Apache License

/**
 * Generates a PDF file with the given text
 * http://itext.ugent.be/itext-in-action/
 * @return A PDF file as a byte array//from  www . ja  v a 2 s  .c  o m
 */
public FileTransfer downloadPdfFile(String contents) throws Exception {
    if (contents == null || contents.length() == 0) {
        contents = "[BLANK]";
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, buffer);

    // ?itext-asian
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // ?WINDOW c:\windows\Fonts\xxx.ttf
    // ?classpath: /src/main/resources/fonts/simsong.ttf

    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);

    document.addCreator("DWR.war using iText");
    document.open();
    document.add(new Paragraph(contents, fontChinese));
    document.close();

    return new FileTransfer("example.pdf", "application/pdf", buffer.toByteArray());
}

From source file:desktopbugtracker.export.PdfFont.java

License:Open Source License

public static Font forTitleProject() {
    return new Font(Font.HELVETICA, 36, Font.NORMAL);
}

From source file:desktopbugtracker.export.PdfFont.java

License:Open Source License

public static Font forTitleBug() {
    return new Font(Font.HELVETICA, 20, Font.NORMAL);
}

From source file:domain.reports.menu.PDFReportMenu.java

License:LGPL

@Override
protected void createPDF(GenericTransaction data, ByteArrayOutputStream buf) throws Throwable {

    //inicializar documento: tamano de pagina, orientacion, margenes
    Document doc = new Document();
    PdfWriter docWriter = PdfWriter.getInstance(doc, buf);
    doc.setPageSize(PageSize.LETTER.rotate());
    doc.setMargins(30, 30, 30, 40);/*from  w w  w  .j  a v  a2s.  c o  m*/

    doc.open();

    //crear fonts por defecto
    tblHeaderFont = new Font(Font.HELVETICA, 10f, Font.BOLD);
    tblBodyFont = new Font(Font.HELVETICA, 10f, Font.NORMAL);

    //definir pie de pagina del lado izquierdo
    String footerText = this.getFooter(); //read it from config.xml or web.xml
    String reportDate = StringUtil.formatDate(new java.util.Date(), "dd-MM-yyyy HH:mm");

    //crear template (objeto interno de IText) y manejador de evento 
    //para imprimir el pie de pagina
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb = docWriter.getDirectContent();
    tpl = cb.createTemplate(20, 14);
    docWriter.setPageEvent(new PDFPageEvents(footerText, pageXofY, tpl, bf, cb, reportDate));

    //titulo - lo lee de config.xml por defecto
    reportTitle = getReportTitle();
    Paragraph t = new Paragraph(reportTitle, new Font(Font.HELVETICA, 14f, Font.BOLD));
    t.setAlignment(Rectangle.ALIGN_RIGHT);
    doc.add(t);

    //logo
    img = Image.getInstance(getImage(this.getServerBaseURL() + logoPath, false));
    img.scalePercent(100);
    float imgY = doc.top() - img.getHeight();
    float imgX = doc.left();
    img.setAbsolutePosition(imgX, imgY);
    doc.add(img);

    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));

    //for each master record print a master/detail section
    MasterDetailReader dataobj = (MasterDetailReader) data;
    Recordset master = dataobj.getRecordset("master");
    master.top();
    while (master.next()) {
        //blank line
        doc.add(new Paragraph(" "));

        //print master section
        doc.add(getGroupMaster(master));

        //print detail section
        doc.add(getGroupDetail(master, dataobj.getDetail(master)));

    }

    //print grand total
    doc.add(new Paragraph(" "));

    doc.close();
    docWriter.close();

}

From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException {
    boolean result = false;
    UnitTrayLabel label = new UnitTrayLabel();
    LabelEncoder encoder = new LabelEncoder(label);
    Image image = encoder.getImage();
    int counter = 0;
    try {/* ww  w  . j a  v  a 2s.  c om*/
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("labels.pdf"));
        document.setPageSize(PageSize.LETTER);
        document.open();

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100f);
        //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        float[] cellWidths = { 30f, 20f, 30f, 20f };
        table.setWidths(cellWidths);

        UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
        if (taxa == null) {
            taxa = uls.findAll();
        }
        Iterator<UnitTrayLabel> i = taxa.iterator();
        PdfPCell cell = null;
        PdfPCell cell_barcode = null;
        // Create two lists of 12 cells, the first 6 of each representing
        // the left hand column of 6 labels, the second 6 of each 
        // representing the right hand column.  
        // cells holds the text for each label, cells_barcode the barcode.
        ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12);
        ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12);
        for (int x = 0; x < 12; x++) {
            cells.add(null);
            cells_barcode.add(null);
        }
        int cellCounter = 0;
        while (i.hasNext()) {
            // Loop through all of the taxa (unit tray labels) found to print 
            label = i.next();
            for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                // For each taxon, loop through the number of requested copies 
                // Generate a text and a barcode cell for each, and add to array for page
                log.debug("Label " + toPrint + " of " + label.getNumberToPrint());
                cell = new PdfPCell();
                cell.setBorderColor(Color.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                cell.disableBorderSide(PdfPCell.RIGHT);
                cell.setPaddingLeft(3);

                String higherNames = "";
                if (label.getTribe().trim().length() > 0) {
                    higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe();
                } else {
                    higherNames = label.getFamily() + ": " + label.getSubfamily();
                }
                Paragraph higher = new Paragraph();
                higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                higher.add(new Chunk(higherNames));
                cell.addElement(higher);

                Paragraph name = new Paragraph();
                Chunk genus = new Chunk(label.getGenus().trim() + " ");
                genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                Chunk species = new Chunk(label.getSpecificEpithet().trim());
                Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>)
                if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) {
                    if (label.getSpecificEpithet().startsWith("nr. ")) {
                        normal = new Chunk("nr. ");
                        normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                        species = new Chunk(label.getSpecificEpithet().trim().substring(4));
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                    } else {
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                    }
                } else {
                    species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                String s = "";
                if (label.getSubspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim());
                if (label.getSubspecificEpithet().contains(".")
                        || label.getSubspecificEpithet().contains("[")) {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                } else {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                if (label.getInfraspecificRank().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim());
                infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                if (label.getInfraspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim());
                infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                if (label.getUnNamedForm().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim());
                unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                name.add(genus);
                if (normal != null) {
                    name.add(normal);
                }
                name.add(species);
                name.add(subspecies);
                name.add(infraRank);
                name.add(infra);
                name.add(unNamed);
                cell.addElement(name);

                Paragraph authorship = new Paragraph();
                authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                if (label.getAuthorship() != null && label.getAuthorship().length() > 0) {
                    Chunk c_authorship = new Chunk(label.getAuthorship());
                    authorship.add(c_authorship);
                }
                cell.addElement(authorship);
                //cell.addElement(new Paragraph(" "));
                if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) {
                    Paragraph drawerNumber = new Paragraph();
                    drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                    Chunk c_drawerNumber = new Chunk(label.getDrawerNumber());
                    drawerNumber.add(c_drawerNumber);
                    cell.addElement(drawerNumber);
                } else {
                    if (label.getCollection() != null && label.getCollection().length() > 0) {
                        Paragraph collection = new Paragraph();
                        collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                        Chunk c_collection = new Chunk(label.getCollection());
                        collection.add(c_collection);
                        cell.addElement(collection);
                    }
                }

                cell_barcode = new PdfPCell();
                cell_barcode.setBorderColor(Color.LIGHT_GRAY);
                cell_barcode.disableBorderSide(PdfPCell.LEFT);
                cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);

                encoder = new LabelEncoder(label);
                image = encoder.getImage();
                image.setAlignment(Image.ALIGN_TOP);
                cell_barcode.addElement(image);

                cells.add(cellCounter, cell);
                cells_barcode.add(cellCounter, cell_barcode);

                cellCounter++;
                // If we have hit a full set of 12 labels, add them to the document
                // in two columns, filling left column first, then right
                if (cellCounter == 12) {
                    // add a page of 12 cells in columns of two.
                    for (int x = 0; x < 6; x++) {
                        if (cells.get(x) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x));
                            table.addCell(cells_barcode.get(x));
                        }
                        if (cells.get(x + 6) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x + 6));
                            table.addCell(cells_barcode.get(x + 6));
                        }
                    }
                    // Reset to begin next page
                    cellCounter = 0;
                    document.add(table);
                    table = new PdfPTable(4);
                    table.setWidthPercentage(100f);
                    table.setWidths(cellWidths);
                    for (int x = 0; x < 12; x++) {
                        cells.set(x, null);
                        cells_barcode.set(x, null);
                    }
                }
            } // end loop through toPrint (for a taxon)
            counter++;
        } // end while results has next (for all taxa requested)
          // get any remaining cells in pairs
        for (int x = 0; x < 6; x++) {
            if (cells.get(x) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x));
                table.addCell(cells_barcode.get(x));
            }
            if (cells.get(x + 6) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x + 6));
                table.addCell(cells_barcode.get(x + 6));
            }
        }
        // add any remaining cells
        document.add(table);
        try {
            document.close();
        } catch (Exception e) {
            throw new PrintFailedException("No labels to print." + e.getMessage());
        }
        // Check to see if there was content in the document.
        if (counter == 0) {
            result = false;
        } else {
            // Printed to pdf ok.
            result = true;
            // Increment number printed.
            i = taxa.iterator();
            while (i.hasNext()) {
                label = i.next();
                for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                    label.setPrinted(label.getPrinted() + 1);
                }
                label.setNumberToPrint(0);
                try {
                    uls.attachDirty(label);
                } catch (SaveFailedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("File not found.");
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("Error buiding PDF document.");
    } catch (OutOfMemoryError e) {
        System.out.println("Out of memory error. " + e.getMessage());
        System.out.println("Failed.  Too many labels.");
        throw new PrintFailedException("Ran out of memory, too many labels at once.");
    }
    return result;
}

From source file:etc.Exporter.java

License:Open Source License

public static void saveAsPDF(File file, Task task) {
    try {/*from  w  ww.  ja v  a2s  .  c om*/
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(file));

        document.open();
        Paragraph taskid = new Paragraph("ID e Detyres: " + task.getIdentifier(),
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(taskid);

        Paragraph creator = new Paragraph("Krijuar nga " + task.getCreator().toString() + "["
                + task.getCreationTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy - HH.mm")) + "]",
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(creator);

        Paragraph executor = new Paragraph("Per zbatim prej: " + task.getExecutor().toString(),
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(executor);

        Paragraph title = new Paragraph(task.getTitle().toUpperCase(),
                FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD));
        document.add(title);

        Paragraph description = new Paragraph(task.getDescription(),
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL));
        document.add(description);

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);

        PdfPTable table = new PdfPTable(1);
        table.addCell(cell);
        table.setWidthPercentage(100f);
        document.add(table);

        if (task instanceof dc.CompletedTask) {
            document.add(new Paragraph(
                    "Gjendja: Perfunduar [" + ((dc.CompletedTask) task).getCompletitionTime()
                            .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
            document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(),
                    FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)));
            document.add(new Paragraph(((dc.CompletedTask) task).getAnnotations(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)));
        } else if (task instanceof dc.RejectedTask) {
            document.add(new Paragraph(
                    "Gjendja: Refuzuar [" + ((dc.RejectedTask) task).getRejectionTime()
                            .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
            document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(),
                    FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)));
            document.add(new Paragraph(((dc.RejectedTask) task).getAnnotations(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)));
        } else {
            document.add(new Paragraph("Gjendja: Ne Pritje",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
        }

        document.close();

        Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.getAbsolutePath());
        p.waitFor();
    } catch (DocumentException | InterruptedException | IOException ex) {
        Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

@SuppressWarnings("unchecked")
private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException {

    LineSeparator hr = new LineSeparator();
    StyleSheet styles = new StyleSheet();
    Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD);

    Iterator<ClientMessage> it = cm.iterator();
    Cell c = null;/*from   w  w w  .j av a 2 s. co m*/
    while (it.hasNext()) {
        ClientMessage fwdCm = it.next();
        if (isForward) {
            c = new Cell();
        }

        // Subject (only if isForward)
        if (isForward) {
            String subjectText = fwdCm.getSubject();
            String dateText = formatDate(fwdCm.getDate());
            Chunk subject = new Chunk(subjectText, fbold);
            Chunk date = new Chunk(dateText, fbold);
            Paragraph subjectPar = new Paragraph(subject + ", " + date);
            subjectPar.setIndentationLeft(5.0f);
            c.add(subjectPar);
            c.add(Chunk.NEWLINE);
        } else {
            String dateText = formatDate(fwdCm.getDate());
            Chunk date = new Chunk(dateText, fbold);
            Paragraph datePar = new Paragraph(date);
            datePar.setAlignment(Element.ALIGN_RIGHT);
            d.add(datePar);
        }

        // Sender
        String senderText = formatAddress(fwdCm.getSender());
        Chunk sender = new Chunk(senderText, fbold);
        sender.setTextRise(10.0f);
        Paragraph senderPar = new Paragraph(sender);
        if (isForward) {
            senderPar.setIndentationLeft(5.0f);
            c.add(senderPar);
        } else {
            d.add(senderPar);
        }

        appendRecipients(d, c, isForward, "To:", fwdCm.getTo());
        appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc());
        appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc());
        if (isForward) {
            c.add(Chunk.NEWLINE);
        }

        // Body
        String bodyText = fwdCm.getBody().getCleanHtml();
        Paragraph bodyPar = new Paragraph();
        bodyPar.setFont(fnormal);
        if (bodyText != null && !bodyText.isEmpty()) {
            try {
                List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles);
                for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) {
                    Element el = iterator.next();
                    if (!(el instanceof Image)) {
                        // bodyPar.add(el);
                        if (isForward) {
                            c.add(el);
                        } else {
                            bodyPar.add(el);
                        }
                    }
                }
            } catch (Exception e) {
                logger.warn("Cannot generate pdf from html body use plain text instead", e);
                // bodyPar.add(fwdCm.getBody().getPlain());
                if (isForward) {
                    Chunk t = new Chunk(fwdCm.getBody().getPlain());
                    t.setFont(fnormal);
                    c.add(t);
                } else {
                    bodyPar.add(fwdCm.getBody().getPlain());
                }
            }
        } else {
            if (isForward) {
                Chunk t = new Chunk(fwdCm.getBody().getPlain());
                t.setFont(fnormal);
                c.add(t);
            } else {
                bodyPar.add(fwdCm.getBody().getPlain());
            }
        }

        if (isForward) {
            // c.add(bodyPar);
            Table t = new Table(1);
            t.setPadding(5);
            t.setBackgroundColor(new Color(242, 242, 242));
            t.addCell(c);
            d.add(t);
        } else {
            bodyPar.setIndentationLeft(15.0f);
            d.add(bodyPar);
        }

        if (fwdCm.getFwdMessages() != null) {
            this.exportMessage(fwdCm.getFwdMessages(), d, true);
        }
        d.add(hr);
    }

}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlag() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalic)) {
        style |= Font.ITALIC;/*from  w ww  .java 2 s  .co m*/
    }
    if (Boolean.TRUE.equals(fontBold)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlagAsian() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalicAsian)) {
        style |= Font.ITALIC;//from   ww w  . j a  va  2 s.  c  o  m
    }
    if (Boolean.TRUE.equals(fontBoldAsian)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlagComplex() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalicComplex)) {
        style |= Font.ITALIC;/*from   ww  w.  j  a  v  a 2s  .  c om*/
    }
    if (Boolean.TRUE.equals(fontBoldComplex)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}