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

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

Introduction

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

Prototype

String TIMES_ROMAN

To view the source code for com.lowagie.text.pdf BaseFont TIMES_ROMAN.

Click Source Link

Document

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

Usage

From source file:ch.gpb.elexis.cst.view.CstResultPart.java

License:Open Source License

private void makeActions(final Control viewer) {

    actionScreenshot = new Action() {
        public void run() {
            if (profile == null) {
                SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden");
                return;
            }// w w w.ja va 2s.c o  m

            GC gc = null;
            Image image = null;
            try {

                String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null);
                if (latestPath == null) {
                    latestPath = System.getProperty("user.home");
                }

                FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE);
                fd.setText("Save");
                fd.setFilterPath(latestPath);
                String[] filterExt = { "*.png", "*.*" };
                fd.setFilterExtensions(filterExt);
                fd.setFileName(CstService.generateFilename(patient));
                String selected = fd.open();

                if (selected == null) {
                    return;
                }

                File selFile = new File(selected);

                CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH,
                        selFile.getParentFile().getAbsolutePath());

                //if (profile.getAnzeigeTyp().toLowerCase().equals("effektiv")) {
                if (profile.getAnzeigeTyp().toLowerCase().equals(CstProfile.ANZEIGETYP_EFFEKTIV)) {

                    if (profile.getAusgabeRichtung()) {
                        image = new Image(viewer.getDisplay(), 1123, viewer.getBounds().height);

                    } else {
                        image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height);

                    }
                } else {
                    image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height);

                }

                ImageLoader loader = new ImageLoader();

                gc = new GC(image);
                viewer.print(gc);

                gc.dispose();

                loader.data = new ImageData[] { image.getImageData() };
                loader.save(selected, SWT.IMAGE_PNG);

            } catch (Exception e) {
                log.error("Error saving png: " + e.toString());
                showMessage("Error while saving PNG", e.getMessage());
            } finally {
                if (image != null) {
                    image.dispose();
                }
                if (gc != null) {
                    gc.dispose();
                }
            }

        }
    };
    actionScreenshot.setText(Messages.Cst_Text_Save_as_png);
    actionScreenshot.setToolTipText(Messages.Cst_Text_Save_as_png);
    actionScreenshot.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
    actionScreenshot.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PNG_PATH));

    // TODO: die pdf ausgabe ist eine ziemliche Baustelle - berarbeiten
    actionPdf = new Action() {
        public void run() {

            //////////////////////////
            if (profile == null) {
                SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden");
                return;
            }

            GC gc = null;
            Image image = null;
            try {
                String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null);
                if (latestPath == null) {
                    latestPath = System.getProperty("user.home");
                }

                FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE);
                fd.setText("Save");
                fd.setFilterPath(latestPath);
                String[] filterExt = { "*.pdf", "*.*" };
                fd.setFilterExtensions(filterExt);
                fd.setFileName(CstService.generateFilename(patient));
                String selected = fd.open();

                if (selected == null) {
                    return;
                }
                File selFile = new File(selected);

                CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH,
                        selFile.getParentFile().getAbsolutePath());

                int printHeigth = 1123;
                int printWidth = 794;
                if (profile.getAusgabeRichtung()) {
                    printHeigth = 794;
                    printWidth = 1123;

                }

                // get the image from the viewport
                image = new Image(viewer.getDisplay(), printWidth, viewer.getBounds().height);
                ImageLoader loader = new ImageLoader();

                gc = new GC(image);
                viewer.print(gc);
                gc.dispose();

                // prepare title data
                //Date date = new Date();
                //SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy  HH:mm");

                Patient patient = Patient.load(profile.getKontaktId());
                //String sTitle = "Gemeinschaftspraxis Brunnmatt Dr. Beat Knzi ";
                String sTitle;
                sTitle = profile.getOutputHeader() == null ? "No header configured!"
                        : profile.getOutputHeader();

                if (sTitle == null || sTitle.length() == 0) {
                    sTitle = "No header configured!";
                }
                sTitle = sTitle + " Datum: " + CstService.getReadableDateAndTime();

                // get option (paging to A4/ in one piece)
                int pdfOutputOption = 0;
                boolean onePage = true;

                PdfOptionsDialog dialog = new PdfOptionsDialog(baseComposite.getShell());
                dialog.create();

                if (dialog.open() == Window.OK) {
                    pdfOutputOption = dialog.getPdfOutputOption();
                    if (pdfOutputOption == PdfOptionsDialog.OPTION_ONE_PAGE) {
                        onePage = true;
                    } else {

                        onePage = false;
                    }
                }

                float docHeight = viewer.getBounds().height;
                docHeight = docHeight / 7.5f;

                float fontSize = 12f;

                if (docHeight < 360f) {
                    docHeight = 360f;
                }

                BufferedImage bimage = ImageUtils.convertToAWT(image.getImageData());

                // create an Itextt Image from AWT BufferedImage
                com.lowagie.text.Image itextImage = null;
                java.awt.Image awtImage = null;

                try {
                    awtImage = Toolkit.getDefaultToolkit().createImage(bimage.getSource());
                    itextImage = com.lowagie.text.Image.getInstance(awtImage, null);

                } catch (Exception e) {
                    log.error("Error on image loading: " + e.toString());
                    e.printStackTrace();
                }

                // only for debugging

                //loader.data = new ImageData[] { image.getImageData() };
                //loader.save("C:\\Users\\daniel\\tmp\\debug.png", SWT.IMAGE_PNG);

                Rectangle pagesize = new Rectangle(595f, itextImage.getHeight() * 0.75f);

                // is it a4 quer?
                if (profile.getAusgabeRichtung()) {
                    pagesize = new Rectangle(842f, itextImage.getHeight() * 0.75f);

                }

                //System.out.println("pagesize: " + pagesize.toString());

                Document document;
                if (onePage) {
                    document = new Document(pagesize);

                } else {
                    document = new Document(PageSize.A4);
                    if (profile.getAusgabeRichtung()) {
                        document = new Document(PageSize.A4.rotate());
                    }

                }

                document.addCreationDate();

                try {
                    // creation of the different writers
                    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selected));

                    // various fonts
                    BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", true);
                    BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                    BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", true);

                    com.lowagie.text.Font fontHelv12 = new com.lowagie.text.Font(bf_helv, fontSize);

                    com.lowagie.text.Font fontTimes = new com.lowagie.text.Font(bf_times, fontSize);

                    fontTimes.setSize(fontSize);
                    fontTimes.setStyle(com.lowagie.text.Font.ITALIC);

                    Chunk chunkHeader = new Chunk(sTitle, FontFactory.getFont(FontFactory.HELVETICA, fontSize,
                            com.lowagie.text.Font.NORMAL, new java.awt.Color(255, 0, 0)));

                    com.lowagie.text.Phrase phraseHeader = new com.lowagie.text.Phrase(chunkHeader);

                    // headers and footers must be added before the document
                    // is opened

                    Chunk chunkFooter = new Chunk("Seite: ", FontFactory.getFont(FontFactory.HELVETICA,
                            fontSize, com.lowagie.text.Font.BOLD, new java.awt.Color(0, 0, 0)));

                    Phrase phraseFooter = new Phrase(chunkFooter);
                    phraseFooter.setFont(fontHelv12);

                    HeaderFooter footer = new HeaderFooter(phraseFooter, true);
                    footer.setBorder(Rectangle.NO_BORDER);
                    footer.setAlignment(Element.ALIGN_CENTER);

                    document.setFooter(footer);

                    Phrase headerPhrase = new Phrase(sTitle);
                    headerPhrase.setFont(fontTimes);

                    HeaderFooter header = new HeaderFooter(phraseHeader, false);
                    header.setBorder(Rectangle.BOTTOM);
                    header.setBorderWidth(0.5f);
                    header.setAlignment(Element.ALIGN_LEFT);
                    document.setHeader(header);

                    document.open();

                    //System.out.println("itext image w: " + itextImage.getWidth() + " h:" + itextImage.getHeight());

                    if (onePage) {

                        int scale = 66;
                        itextImage.scalePercent(scale);

                        document.add(itextImage);

                    } else {

                        BufferedImage[] imageChunks = ImageUtils.splitImageByHeigth(bimage, printHeigth);

                        for (int i = 0; i < imageChunks.length; i++) {

                            com.lowagie.text.Image itextImage2 = com.lowagie.text.Image.getInstance(
                                    Toolkit.getDefaultToolkit().createImage(imageChunks[i].getSource()), null);

                            // width becomes typically 523 (595 - 72) for a4Hoch or 770 (842 - 72) for A4Quer
                            float imgWidth = document.getPageSize().getWidth() - document.leftMargin()
                                    - document.rightMargin();
                            float imgHeigth = itextImage.getHeight() * 0.75f;

                            itextImage2.setAbsolutePosition(30, 20);
                            int scale = 66;
                            itextImage2.scalePercent(scale);

                            document.add(itextImage2);
                            document.newPage();

                        }

                    }

                    // we're done!
                    document.close();

                    ///////////////////////////////

                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    showMessage("Error while generating PDF", ex.getMessage());
                }

            } finally {
                if (image != null) {
                    image.dispose();
                }
                if (gc != null) {
                    gc.dispose();
                }
                /*
                image.dispose();
                gc.dispose();
                */
            }

        }
    };

    actionPdf.setText(Messages.Cst_Text_Save_as_pdf);
    actionPdf.setToolTipText(Messages.Cst_Text_Save_as_pdf);
    /*
     * actionPdf.setImageDescriptor(PlatformUI.getWorkbench() .getSharedImages()
     * .getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
     */
    actionPdf.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PDF_PATH));

}

From source file:com.geek.tutorial.itext.acroform.RadioCheckBoxForm.java

License:Open Source License

public RadioCheckBoxForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("RadioCheckBoxForm.pdf"));
    document.open();//  w  w w .j av a  2 s . c o m
    PdfContentByte cb = writer.getDirectContent();

    BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    Rectangle rect;

    // Code 1 create radio button
    String[] radios = { "Radio1", "Radio2", "Radio3" };
    PdfFormField radioField = PdfFormField.createRadioButton(writer, true);
    radioField.setFieldName("radioField");
    radioField.setValueAsName(radios[0]);
    for (int i = 0; i < radios.length; i++) {
        rect = new Rectangle(40, 815 - i * 30, 60, 797 - i * 30);
        addRadioButton(writer, rect, radioField, radios[i], i == 0);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(Element.ALIGN_LEFT, radios[i], 70, 802 - i * 30, 0);
        cb.endText();
    }
    writer.addAnnotation(radioField);

    // Code 2 create checkbox button
    String[] options = { "Check1", "Check2", "Check3" };
    for (int i = 0; i < options.length; i++) {
        rect = new Rectangle(160, 815 - i * 30, 180, 797 - i * 30);
        addCheckbox(writer, rect, options[i]);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(Element.ALIGN_LEFT, options[i], 190, 802 - i * 30, 0);
        cb.endText();
    }

    // Code 3 add function and button for showing state 
    writer.addJavaScript(
            "function showState(){" + "app.alert('Radio:'+ this.getField('radioField').value +'\\n\\n'+"
                    + "'Check1:'+this.getField('Check1').value +'\\n'+"
                    + "'Check2:'+this.getField('Check2').value +'\\n'+"
                    + "'Check3:'+this.getField('Check3').value);" + "}");
    PushbuttonField push = new PushbuttonField(writer, new Rectangle(80, 710, 150, 730), "pushAction");
    push.setBackgroundColor(Color.LIGHT_GRAY);
    push.setBorderColor(Color.GRAY);
    push.setText("Show State");
    push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    push.setTextColor(Color.BLACK);
    PdfFormField pushbutton = push.getField();
    pushbutton.setAction(PdfAction.javaScript("showState()", writer));
    writer.addAnnotation(pushbutton);

    document.close();
}

From source file:com.moss.pdf.template.core.Renderer.java

License:Open Source License

public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception {

    PdfReader reader = new PdfReader(in);

    Document document = new Document(reader.getPageSizeWithRotation(1));

    PdfWriter writer = PdfWriter.getInstance(document, out);

    document.open();/*ww w.  j  a v a2s.  c  o  m*/

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

        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage customPage = writer.getImportedPage(reader, i);

        /*
         * add the page to our new document, turning this page to its 
         * original rotation
         */
        int pageRotation = reader.getPageRotation(i);

        if (pageRotation > 0) {

            System.out.println("page rotation found: " + pageRotation);

            double angle = -((2 * Math.PI) * pageRotation / 360);
            //         double angle = -(Math.PI / 2);

            cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle),
                    (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x
                    document.top() + document.topMargin() // y
            );
        } else {
            cb.addTemplate(customPage, 0f, 0f);
        }

        Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>();

        for (PropertyMapping field : fields) {

            if (field.getPageNumber() != i) {
                continue;
            }

            /*
             * Only builtin fonts are supported at the moment
             */
            BaseFont font;
            int fontSize;
            int alignment;
            String text;
            float x, y;
            float rotation;

            {
                font = fonts.get(field.getFontName());

                if (font == null) {

                    FontName e = field.getFontName();
                    String name = null;

                    if (FontName.COURIER == e) {
                        name = BaseFont.COURIER;
                    } else if (FontName.COURIER_BOLD == e) {
                        name = BaseFont.COURIER_BOLD;
                    } else if (FontName.COURIER_BOLD_OBLIQUE == e) {
                        name = BaseFont.COURIER_BOLDOBLIQUE;
                    } else if (FontName.COURIER_OBLIQUE == e) {
                        name = BaseFont.COURIER_OBLIQUE;
                    } else if (FontName.HELVETICA == e) {
                        name = BaseFont.HELVETICA;
                    } else if (FontName.HELVETICA_BOLD == e) {
                        name = BaseFont.HELVETICA_BOLD;
                    } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) {
                        name = BaseFont.HELVETICA_BOLDOBLIQUE;
                    } else if (FontName.HELVETICA_OBLIQUE == e) {
                        name = BaseFont.HELVETICA_OBLIQUE;
                    } else if (FontName.TIMES_BOLD == e) {
                        name = BaseFont.TIMES_BOLD;
                    } else if (FontName.TIMES_BOLD_ITALIC == e) {
                        name = BaseFont.TIMES_BOLDITALIC;
                    } else if (FontName.TIMES_ITALIC == e) {
                        name = BaseFont.TIMES_ITALIC;
                    } else if (FontName.TIMES_ROMAN == e) {
                        name = BaseFont.TIMES_ROMAN;
                    }

                    if (name == null) {
                        throw new RuntimeException("Unknown font type: " + e);
                    }

                    font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                    fonts.put(field.getFontName(), font);
                }

                fontSize = field.getFontSize();

                if (TextAlignment.LEFT == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_LEFT;
                } else if (TextAlignment.CENTER == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_CENTER;
                } else if (TextAlignment.RIGHT == field.getAlignment()) {
                    alignment = PdfContentByte.ALIGN_RIGHT;
                } else {
                    alignment = PdfContentByte.ALIGN_LEFT;
                }

                Object value = p.eval(field.getExpr());

                if (value == null) {
                    text = "";
                } else {
                    text = value.toString();
                }

                x = field.getX() * POINTS_IN_A_CM;
                y = field.getY() * POINTS_IN_A_CM;

                rotation = 0;
            }

            cb.beginText();

            cb.setFontAndSize(font, fontSize);

            cb.showTextAligned(alignment, text, x, y, rotation);

            cb.endText();
        }

        document.newPage();
    }

    reader.close();
    document.close();
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

public PdfExporter(SongNodeLoader loader) {
    this.loader = loader;

    // Load fonts
    FontFactory.registerDirectories();/*from   w  ww . j  a v a 2 s.c o  m*/
    BaseFont timesFont = null;
    try {
        timesFont = BaseFont.createFont("C:/Windows/Fonts/times.ttf", BaseFont.CP1250, true);
        logger.info("Embedded TTF fonts from C:/Windows/Fonts");
    } catch (Exception ex) {
        try {
            timesFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, true);
            logger.info("Embedded default fonts");
        } catch (Exception ex1) {
            logger.error("Failed to load fonts ...");
        }
    }

    // Initialize fonts
    if (timesFont != null) {
        songTitleFont = new Font(timesFont, 14f, Font.BOLD);
        textFont = new Font(timesFont, 11f, Font.NORMAL);
        chordFont = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, 11f, Font.BOLD);
    } else {
        songTitleFont = null;
        textFont = null;
        chordFont = null;
    }

    verseSpacing = new Paragraph(" ");
    verseSpacing.setLeading(5f, 0.5f);
}

From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFFontRegistry.java

License:Open Source License

@Override
protected String resolveFamilyName(String familyName, int style) {
    boolean bold = isBold(style);
    boolean italic = isItalic(style);

    if (COURRIER_NEW_FONT_FAMILY_NAME.equals(familyName)) {
        if (bold && italic) {
            return BaseFont.COURIER_BOLDOBLIQUE;
        } else if (bold) {
            return BaseFont.COURIER_BOLD;
        } else if (italic) {
            return BaseFont.COURIER_OBLIQUE;
        }//ww w.jav  a  2 s. co m
        return BaseFont.COURIER;
    }

    if (TIMES_NEW_ROMAN_FONT_FAMILY_NAME.equals(familyName)) {
        if (bold && italic) {
            return BaseFont.TIMES_BOLDITALIC;
        } else if (bold) {
            return BaseFont.TIMES_BOLD;
        } else if (italic) {
            return BaseFont.TIMES_ITALIC;
        }
        return BaseFont.TIMES_ROMAN;
    }

    return familyName;
}

From source file:org.areasy.common.doclet.document.DocumentEventHandler.java

License:Open Source License

/**
 * Constructs an event handler for a given PDF writer.
 *
 * @param pdfWriter The writer used to create the document.
 * @throws Exception//from   ww  w.ja v a2 s  .co m
 */
public DocumentEventHandler(PdfWriter pdfWriter) throws Exception {
    cb = pdfWriter.getDirectContent();
    bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    template = cb.createTemplate(bf.getWidthPoint("Page 999 of 999", 8), 250);

    leftHeader = DefaultConfiguration.getString(ARG_HEADER_LEFT, "");
    centerHeader = DefaultConfiguration.getString(ARG_HEADER_CENTER, "");
    rightHeader = DefaultConfiguration.getString(ARG_HEADER_RIGHT, "");

    String pageNumberTypeValue = DefaultConfiguration.getString(ARG_PGN_TYPE, ARG_VAL_FULL);

    if (pageNumberTypeValue.equalsIgnoreCase(ARG_VAL_FULL))
        pageNumberType = PAGE_NUMBER_FULL;
    else
        pageNumberType = PAGE_NUMBER_SIMPLE;

    String pageNumberAlignValue = DefaultConfiguration.getString(ARG_PGN_ALIGNMENT, ARG_VAL_SWITCH);

    if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_LEFT))
        pageNumberAlign = PAGE_NUMBER_ALIGN_LEFT;

    if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_CENTER))
        pageNumberAlign = PAGE_NUMBER_ALIGN_CENTER;

    if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_RIGHT))
        pageNumberAlign = PAGE_NUMBER_ALIGN_RIGHT;

    if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_SWITCH))
        pageNumberAlign = PAGE_NUMBER_ALIGN_SWITCH;
}

From source file:org.openconcerto.erp.core.finance.accounting.report.PdfGenerator.java

License:Open Source License

private void init() throws FileNotFoundException {

    // we create a reader for a certain document
    PdfReader reader = null;/*from  ww  w . j  a  v a2  s . c  om*/
    PdfWriter writer = null;
    try {
        reader = new PdfReader(getStreamStatic(this.fileNameIn));

        // we retrieve the total number of pages
        int n = reader.getNumberOfPages();
        // we retrieve the size of the first page
        Rectangle psize = reader.getPageSize(1);

        psize.setRight(psize.getRight() - this.templateOffsetX);
        psize.setTop(psize.getTop() - this.templateOffsetY);

        this.width = (int) psize.getWidth();
        float height = psize.getHeight();

        // step 1: creation of a document-object
        int MARGIN = 32;
        this.document = new Document(psize, MARGIN, MARGIN, MARGIN, MARGIN);
        // step 2: we create a writer that listens to the document
        if (!this.directoryOut.exists()) {
            this.directoryOut.mkdirs();
        }
        System.err.println("Directory out " + this.directoryOut.getAbsolutePath());
        File f = new File(this.directoryOut, this.fileNameOut);
        if (f.exists()) {
            f.renameTo(new File(this.directoryOut, "Old" + this.fileNameOut));
            f = new File(this.directoryOut, this.fileNameOut);
        }

        System.err.println("Creation du fichier " + f.getAbsolutePath());

        writer = PdfWriter.getInstance(this.document, new FileOutputStream(f));

        this.document.open();
        // step 4: we add content
        this.cb = writer.getDirectContent();

        System.out.println("There are " + n + " pages in the document.");

        this.document.newPage();

        PdfImportedPage page1 = writer.getImportedPage(reader, 1);

        this.cb.addTemplate(page1, -this.templateOffsetX, -this.templateOffsetY);

        this.bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
        this.bfb = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED);

    } catch (FileNotFoundException fE) {
        throw fE;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:org.opentestsystem.delivery.testreg.rest.view.PdfReportPageEventHelper.java

License:Open Source License

public PdfReportPageEventHelper(final PdfWriter writer) {
    template = writer.getDirectContent().createTemplate(100, 100);
    template.setBoundingBox(new Rectangle(-20, -20, 100, 100));
    try {//from   w w w .ja v  a2  s  .  c o  m
        helv = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1257, BaseFont.NOT_EMBEDDED);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.pentaho.reporting.libraries.fonts.itext.ITextBuiltInFontRegistry.java

License:Open Source License

private FontFamily createTimesFamily() {
    final DefaultFontFamily fontFamily = new DefaultFontFamily("Times");
    fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_ROMAN, false, false, false));
    fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_BOLD, true, false, false));
    fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_ITALIC, false, true, false));
    fontFamily.addFontRecord(//from w  w w.j  av a 2  s .c o m
            new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_BOLDITALIC, true, true, false));
    return fontFamily;
}

From source file:org.pz.platypus.plugin.html.HtmlFont.java

License:Open Source License

/**
 * Creates an iText Font object based on the class fields
 * @param f the PdfFont containing the parameters for the font
 * @return the iText Font object/*  w w  w .ja  va  2 s.c  om*/
 */
Font createFont(final HtmlFont f) {
    int style = 0;
    //       Color col  = new Color( color.getR(), color.getG(), color.getB() );
    Font font;

    String iTextFontName = createItextFontName(f);
    if (!isBase14Font(f.typeface)) {
        style = computeItextStyle();
    }

    try {
        font = FontFactory.getFont(iTextFontName, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    } catch (Exception ex) {
        System.out.println("Exception in PdfFont.createFont() for FontFactory.getFont() for " + iTextFontName);
        font = null;
    }

    if (font == null || font.getBaseFont() == null) {
        gdd.logWarning("iText could not find font for: " + iTextFontName + ". Using Times-Roman");
        font = FontFactory.getFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    }

    return (font);
}