Example usage for com.itextpdf.io.font FontConstants COURIER

List of usage examples for com.itextpdf.io.font FontConstants COURIER

Introduction

In this page you can find the example usage for com.itextpdf.io.font FontConstants COURIER.

Prototype

String COURIER

To view the source code for com.itextpdf.io.font FontConstants COURIER.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java

public void createPdf(String dest, FicheSecurite fs)
            throws IOException, FileNotFoundException, java.io.IOException {
        //Initialize PDF writer
        PdfWriter writer = new PdfWriter(dest);

        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(writer);

        // Initialize document
        Document document = new Document(pdf);
        //Add paragraph to the document
        document.add(new Paragraph(fs.getSite()));
        // Add content
        Text title1 = new Text("The Strange Case of ").setFontColor(Color.BLUE);
        Text title2 = new Text("Dr. Jekyll SIIMMOONN").setStrokeColor(Color.GREEN)
                .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE);
        Text title3 = new Text(" and ");
        Text title4 = new Text("Mr. Hyde").setStrokeColor(Color.RED).setStrokeWidth(0.5f)
                .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
        Paragraph p = new Paragraph().setFontSize(24).add(title1).add(title2).add(title3).add(title4);
        document.add(p);/*from  w w  w  .  ja  va  2  s  . c  o m*/

        Style normal = new Style();
        PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        normal.setFont(font).setFontSize(14);
        Style code = new Style();
        PdfFont monospace = PdfFontFactory.createFont(FontConstants.COURIER);
        code.setFont(monospace).setFontColor(Color.RED).setBackgroundColor(Color.LIGHT_GRAY);
        Paragraph p2 = new Paragraph();
        p2.add(new Text("The Strange Case of ").addStyle(normal));
        p2.add(new Text("Dr. Jekyll").addStyle(code));
        p2.add(new Text(" and ").addStyle(normal));
        p2.add(new Text("Mr. Hyde").addStyle(code));
        p2.add(new Text(".").addStyle(normal));
        document.add(p2);

        //Close document
        document.close();
        //        PageSize ps = PageSize.A4.rotate();
        //        PdfPage page = pdf.addNewPage(ps);
        //        PdfCanvas canvas = new PdfCanvas(page);
        //        canvas.concatMatrix(1, 0, 0, 1, ps.getWidth() / 2, ps.getHeight() / 2);
        ////Draw X axis
        //        canvas.moveTo(-(ps.getWidth() / 2 - 15), 0)
        //                .lineTo(ps.getWidth() / 2 - 15, 0)
        //                .stroke();
        ////Draw X axis arrow
        //        canvas.setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND)
        //                .moveTo(ps.getWidth() / 2 - 25, -10)
        //                .lineTo(ps.getWidth() / 2 - 15, 0)
        //                .lineTo(ps.getWidth() / 2 - 25, 10).stroke()
        //                .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.MITER);
        ////Draw Y axis
        //        canvas.moveTo(0, -(ps.getHeight() / 2 - 15))
        //                .lineTo(0, ps.getHeight() / 2 - 15)
        //                .stroke();
        ////Draw Y axis arrow
        //        canvas.saveState()
        //                .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND)
        //                .moveTo(-10, ps.getHeight() / 2 - 25)
        //                .lineTo(0, ps.getHeight() / 2 - 15)
        //                .lineTo(10, ps.getHeight() / 2 - 25).stroke()
        //                .restoreState();
        ////Draw X serif
        //        for (int i = -((int) ps.getWidth() / 2 - 61);
        //                i < ((int) ps.getWidth() / 2 - 60); i += 40) {
        //            canvas.moveTo(i, 5).lineTo(i, -5);
        //        }
        ////Draw Y serif
        //        for (int j = -((int) ps.getHeight() / 2 - 57);
        //                j < ((int) ps.getHeight() / 2 - 56); j += 40) {
        //            canvas.moveTo(5, j).lineTo(-5, j);
        //        }
        //        canvas.stroke();
        ////        pdf.close();
        ////        PdfPage page = pdf.addNewPage();
        ////        Rectangle rectangle = new Rectangle(x, y, 100, 100);
        ////        Canvas canvas = new Canvas(pdfCanvas, pdf, rectangle);
        //        float llx = 0;
        //        float lly = 0;
        //        float urx = 100;
        //        float ury = 100;
        //        for (Palanque palanque : fs.getPalanques()) {
        //            llx=llx+5;
        //            lly=lly+70;
        //            Rectangle rectangle = new Rectangle(llx, lly, urx-llx, ury-lly);
        ////            PdfCanvas canvas = new PdfCanvas(page);
        //            canvas = new PdfCanvas(page);
        ////            PdfCanvas canvas = new PdfCanvas(pdf.addNewPage());
        ////            pdfCanvas.rectangle(rectangle);
        //            canvas.setStrokeColor(Color.RED).setLineWidth(0.5f).rectangle(rectangle).stroke();
        ////            canvas = new Canvas(pdfCanvas, pdf, rectangle);
        ////            pdfCanvas.stroke();
        //            PdfFont fontRoman = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        //            PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
        //            Text title = new Text("GUIDE palanque:"+palanque.getNomCompletGuide()).setFont(bold);
        //            Text author = new Text("PLONGEUR 1 palanque:"+palanque.getNomCompletPlongeur1()).setFont(fontRoman);
        //            Paragraph p3 = new Paragraph().add(title).add(" by ").add(author);
        //            new Canvas(canvas,pdf,rectangle).add(p3);
        ////            canvas.add(p3);
        //        }
        //Close document
        pdf.close();

    }

From source file:com.Models.Services.PdfBuilderService.java

private PdfFont adjustFont() throws IOException {
    return PdfFontFactory.createFont(FontConstants.COURIER);
}