Example usage for com.itextpdf.text.pdf BaseFont setPostscriptFontName

List of usage examples for com.itextpdf.text.pdf BaseFont setPostscriptFontName

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BaseFont setPostscriptFontName.

Prototype

public abstract void setPostscriptFontName(String name);

Source Link

Document

Sets the font name that will appear in the pdf font dictionary.

Usage

From source file:me.Aron.Heinecke.fbot.lib.Converter.java

License:Apache License

/***
 * Add a note to the bottom of a pdf file in italic font
 * @param rfile file to be read from//from  w w  w  .  ja  v a2 s . c  o  m
 * @param wfile file to be written to
 * @param text text to add
 * @return path to the resulting pdf, null if it failed
 */
private String addPDFNote(File rfile, File wfile, String text) {
    try {
        PdfReader pdfReader = new PdfReader(rfile.getAbsolutePath());

        PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(wfile));

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {

            PdfContentByte cb = pdfStamper.getUnderContent(i);

            BaseFont bf = BaseFont.createFont();
            bf.setPostscriptFontName("ITALIC");
            cb.beginText();
            cb.setFontAndSize(bf, 12);
            cb.setTextMatrix(10, 20);
            cb.showText(text);
            cb.endText();
        }

        pdfStamper.close();
        return wfile.getAbsolutePath();
    } catch (IOException | DocumentException e) {
        fbot.getLogger().exception("converter", e);
        return null;
    }
}