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

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

Introduction

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

Prototype

public static BaseFont createFont(String name, String encoding, boolean embedded)
        throws DocumentException, IOException 

Source Link

Document

Creates a new font.

Usage

From source file:papertoolkit.pattern.output.PDFPatternGenerator.java

License:BSD License

/**
 * @return the tahoma font from disk.//w  w w .  j a v  a2  s  .  co  m
 * TODO: What happened? It used to work... Where does BaseFont Look?
 */
private static BaseFont createBaseFontTahoma() {
    // TODO RON YEH xxxx
    DebugUtils.println(new File(".").getAbsolutePath());

    try {
        return BaseFont.createFont(PaperToolkit.getDataFile("fonts/tahoma.ttf").getAbsolutePath(),
                BaseFont.CP1252, BaseFont.EMBEDDED);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:papertoolkit.pattern.output.PDFPatternGenerator.java

License:BSD License

/**
 * @return/*from  w  ww  . j  a  va2 s.c  o m*/
 */
private static BaseFont createBaseFontZapfDingbats() {
    try {
        return BaseFont.createFont(BaseFont.ZAPFDINGBATS, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:pl.exsio.ca.app.report.terraincard.view.TerrainCardsView.java

License:Open Source License

private Font getFont() throws Exception {
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    Font f = new Font(bf, 10, Font.NORMAL);
    return f;//from   w w w .  ja  va2 s  .  co  m
}

From source file:questions.compression.CompressionLevelsFonts.java

public static void createPdf(int compressionLevel) {
    try {// w w w .  j av  a 2 s . c o  m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1]));
        writer.setCompressionLevel(compressionLevel);
        document.open();
        BaseFont bf = BaseFont.createFont(RESOURCE, BaseFont.WINANSI, BaseFont.EMBEDDED);
        bf.setCompressionLevel(compressionLevel);
        Font f = new Font(bf, 12);
        document.add(new Paragraph("0123456789", f));
        document.add(new Paragraph("abcdefghijklmnopqrstuvwxyz", f));
        document.add(new Paragraph("ABCDEFGHIJKLMNOPQRSTUVWXYZ", f));
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:questions.directcontent.InterpretOCR.java

public static void main(String[] args) throws IOException, DocumentException {
    Document document = new Document(PageSize.LETTER);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    document.open();/*from  ww  w .  j a  v a 2  s .  co m*/
    PdfContentByte cb = writer.getDirectContent();
    BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    cb.beginText();
    cb.setFontAndSize(font, 12);
    String line;
    String word;
    @SuppressWarnings("unused")
    float llx, lly, urx, ury;
    StringTokenizer tokenizer;
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(RESOURCE)));
    while ((line = reader.readLine()) != null) {
        tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            tokenizer.nextToken();
            word = tokenizer.nextToken();
            llx = Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            lly = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            urx = Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            ury = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            cb.showTextAligned(Element.ALIGN_LEFT, word, (llx + urx) / 2, lly, 0);
        }
    }
    cb.endText();
    document.close();
}

From source file:questions.forms.RadioButtonsOnDifferentPages.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from   w w w.  ja  v  a  2 s.c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        String[] languages = { "English", "French", "Dutch" };
        Rectangle rect;

        // create radio button field and its kids
        PdfFormField language = PdfFormField.createRadioButton(writer, true);
        language.setFieldName("language");
        language.setValueAsName(languages[0]);
        for (int i = 0; i < languages.length; i++) {
            rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40);
            addRadioButton(writer, rect, language, languages[i], i == 0, writer.getPageNumber() + i);
        }
        writer.addAnnotation(language);

        // add the page content
        for (int i = 0; i < languages.length; i++) {
            cb.beginText();
            cb.setFontAndSize(bf, 18);
            cb.showTextAligned(Element.ALIGN_LEFT, languages[i], 70, 790 - i * 40, 0);
            cb.endText();
            document.newPage();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // step 5: we close the document
    document.close();

}

From source file:questions.graphics2D.ArabicText.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {//w w  w  .  ja  va  2 s . co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        String text1 = "\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631";
        String text2 = "\u0634";
        java.awt.Font font = new java.awt.Font("arial", 0, 12);
        PdfContentByte cb = writer.getDirectContent();

        java.awt.Graphics2D g2Shapes = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        g2Shapes.setFont(font);
        g2Shapes.drawString("text1, expected to render RTL", 50, 100);
        g2Shapes.drawString(text1, 50, 120);
        g2Shapes.drawString("text2, expected to match right-most glyph above", 50, 140);
        g2Shapes.drawString(text2, 50, 160);
        g2Shapes.dispose();

        ColumnText text = new ColumnText(cb);
        Font f = new Font(
                BaseFont.createFont("c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED),
                12);
        text.setSimpleColumn(50, 620, 545, 50);
        text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
        text.setText(new Phrase(text1, f));
        text.go();
        text.setText(new Phrase(text2, f));
        text.go();

        FontMapper arialuni = new FontMapper() {
            public BaseFont awtToPdf(java.awt.Font font) {
                try {
                    return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H,
                            BaseFont.EMBEDDED);
                } catch (DocumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }

            public java.awt.Font pdfToAwt(BaseFont font, int size) {
                return null;
            }

        };
        java.awt.Graphics2D g = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight(), arialuni);
        g.setFont(null);
        g.drawString("text1, not expected to render RTL", 50, 180);
        g.drawString(text1, 50, 200);
        g.drawString("text2, not expected to match right-most glyph above", 50, 220);
        g.drawString(text2, 50, 240);
        g.drawString("to your right you see what it SHOULD look like:", 50, 260);
        g.drawString("If it doesn't, the problem is in the JDK, it's not an iText problem.", 50, 280);
        g.dispose();
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.graphics2D.SwingForceArialUni.java

public static void main(String[] args) {
    Document document = new Document(new Rectangle(210, 25));
    try {// www.j  a v a2  s.c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        FontMapper arialuni = new FontMapper() {
            public BaseFont awtToPdf(Font font) {
                try {
                    return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H,
                            BaseFont.EMBEDDED);
                } catch (DocumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }

            public Font pdfToAwt(BaseFont font, int size) {
                return null;
            }

        };
        Graphics2D g2 = cb.createGraphics(200, 50, arialuni);
        g2.setFont(null);
        g2.drawString("Greek mu: \u03bc - \u039c; degree symbol: \u00b0", 0, 40);
        g2.dispose();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}

From source file:questions.importpages.NameCard.java

public static void createOneCard() throws DocumentException, IOException {
    Rectangle rect = new Rectangle(Utilities.millimetersToPoints(86.5f), Utilities.millimetersToPoints(55));
    Document document = new Document(rect);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(CARD));
    writer.setViewerPreferences(PdfWriter.PrintScalingNone);
    document.open();/* ww w.j a  v a2s .  co  m*/
    PdfReader reader = new PdfReader(LOGO);
    Image img = Image.getInstance(writer.getImportedPage(reader, 1));
    img.scaleToFit(rect.getWidth() / 1.5f, rect.getHeight() / 1.5f);
    img.setAbsolutePosition((rect.getWidth() - img.getScaledWidth()) / 2,
            (rect.getHeight() - img.getScaledHeight()) / 2);
    document.add(img);
    document.newPage();
    BaseFont bf = BaseFont.createFont(FONT, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    Font font = new Font(bf, 12);
    font.setColor(new CMYKColor(1, 0.5f, 0, 0.467f));
    ColumnText column = new ColumnText(writer.getDirectContent());
    Paragraph p;
    p = new Paragraph("Bruno Lowagie\n1T3XT\nbruno@1t3xt.com", font);
    p.setAlignment(Element.ALIGN_CENTER);
    column.addElement(p);
    column.setSimpleColumn(0, 0, rect.getWidth(), rect.getHeight() * 0.75f);
    column.go();
    document.close();
}

From source file:questions.separators.PositionedMarks.java

public PositionedMarks(boolean start) throws DocumentException, IOException {
    this.start = start;
    bf = BaseFont.createFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}