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

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

Introduction

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

Prototype

boolean EMBEDDED

To view the source code for com.itextpdf.text.pdf BaseFont EMBEDDED.

Click Source Link

Document

if the font has to be embedded

Usage

From source file:naprawa.praca.PracaController.java

public PdfPCell getNewCell(String nazwa) {
    BaseFont bf = null;//  w ww. j  av  a  2s  .c  o  m
    try {
        bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    } catch (DocumentException ex) {
        Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
    }
    PdfPCell cell = new PdfPCell(new Paragraph(nazwa, new com.itextpdf.text.Font(bf, 10)));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setVerticalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(PdfPCell.NO_BORDER);
    return cell;
}

From source file:net.ionescu.jhocr2pdf.Jhocr2pdf.java

License:Open Source License

public Jhocr2pdf(PdfStamper stamper, boolean visible, String fontPath) throws DocumentException, IOException {
    this.stamper = stamper;
    this.visible = visible;
    if (fontPath != null) {
        bf = BaseFont.createFont(fontPath, BaseFont.WINANSI, BaseFont.EMBEDDED);
    } else {/*from   w w w.ja  va2  s. co m*/
        bf = BaseFont.createFont();
    }
}

From source file:oop.nhom5.de3.model.IOFilePDF.java

public static boolean writePDF(String text, String fileName) {
    try {/*from   w  ww .  ja va 2s . c o  m*/
        // create a new document
        Document document = new Document();
        Font font = new Font(
                BaseFont.createFont("C:\\Windows\\Fonts\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
        PdfWriter.getInstance(document, new FileOutputStream(fileName));

        document.open();
        // create lines of text
        String[] lines = text.split("\n");
        //create Paragraph
        for (String line : lines) {
            document.add(new Paragraph(line, font));
        }

        document.close();
        return true;
    } catch (FileNotFoundException | DocumentException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(IOFilePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}

From source file:Operaciones.ResponsablesOP.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from   w w  w  . ja  va  2  s .c om

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText()));
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        Date fecha1 = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);

        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/PlantillaHojaAsignacion.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

        cb.beginText();
        fdfDoc.setField("orden", String.valueOf(ord.getIdOrden()));

        if (ord.getCompania() != null)
            fdfDoc.setField("compania", ord.getCompania().getNombre());
        else
            fdfDoc.setField("compania", "");

        if (ord.getSiniestro() != null)
            fdfDoc.setField("siniestro", ord.getSiniestro());
        else
            fdfDoc.setField("siniestro", "");

        if (ord.getPoliza() != null)
            fdfDoc.setField("poliza", ord.getPoliza());
        else
            fdfDoc.setField("poliza", "");
        if (ord.getFecha() != null)
            fdfDoc.setField("apertura", ord.getFecha().toString());
        else
            fdfDoc.setField("apertura", "");
        if (ord.getFechaSiniestro() != null)
            fdfDoc.setField("f_siniestro", ord.getFechaSiniestro().toString());
        else
            fdfDoc.setField("f_siniestro", "");
        if (ord.getInciso() != null)
            fdfDoc.setField("inciso", ord.getInciso());
        else
            fdfDoc.setField("inciso", "");

        if (ord.getTipo() != null)
            fdfDoc.setField("unidad", ord.getTipo().getTipoNombre());
        else
            fdfDoc.setField("unidad", "");
        if (ord.getModelo() != null)
            fdfDoc.setField("modelo", ord.getModelo().toString());
        else
            fdfDoc.setField("modelo", "");
        if (ord.getMarca() != null)
            fdfDoc.setField("marca", ord.getMarca().getMarcaNombre());
        else
            fdfDoc.setField("marca", "");
        if (ord.getNoEconomico() != null)
            fdfDoc.setField("economico", ord.getNoEconomico());
        else
            fdfDoc.setField("economico", "");
        if (ord.getNoMotor() != null)
            fdfDoc.setField("no_motor", ord.getNoMotor());
        else
            fdfDoc.setField("no_motor", "");
        if (ord.getNoSerie() != null)
            fdfDoc.setField("no_serie", ord.getNoSerie());
        else
            fdfDoc.setField("no_serie", "");

        //tabla 
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("HOJALATERIA", ord.getEmpleadoByRHojalateria().getIdEmpleado().toString());
        else
            fdfDoc.setField("HOJALATERIA", "");
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("R_H", ord.getEmpleadoByRHojalateria().getNombre().toString());
        else
            fdfDoc.setField("R_H", "");

        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("MECANICA", ord.getEmpleadoByRMecanica().getIdEmpleado().toString());
        else
            fdfDoc.setField("MECANICA", "");
        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("R_M", ord.getEmpleadoByRMecanica().getNombre().toString());
        else
            fdfDoc.setField("R_M", "");

        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("SUSPENSIN", ord.getEmpleadoByRSuspension().getIdEmpleado().toString());
        else
            fdfDoc.setField("SUSPENSIN", "");
        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("R_S", ord.getEmpleadoByRSuspension().getNombre().toString());
        else
            fdfDoc.setField("R_S", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("ELECTRICO", ord.getEmpleadoByRElectrico().getIdEmpleado().toString());
        else
            fdfDoc.setField("ELECTRICO", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("R_E", ord.getEmpleadoByRElectrico().getNombre().toString());
        else
            fdfDoc.setField("R_E", "");

        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("PINTURA", ord.getEmpleadoByRPintura().getIdEmpleado().toString());
        else
            fdfDoc.setField("PINTURA", "");
        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("R_P", ord.getEmpleadoByRPintura().getNombre().toString());
        else
            fdfDoc.setField("R_P", "");

        //FECHAS
        String valor1 = "";
        if (ord.getRHojalateriaFecha() != null) {
            fecha1 = ord.getRHojalateriaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H", valor1);
        } else {
            fdfDoc.setField("F_H", valor1);
        }
        if (ord.getRMecanicaFecha() != null) {
            fecha1 = ord.getRMecanicaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M", valor1);
        } else {
            fdfDoc.setField("F_M", valor1);
        }
        if (ord.getRSuspensionFecha() != null) {
            fecha1 = ord.getRSuspensionFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S", valor1);
        } else {
            fdfDoc.setField("F_S", valor1);
        }
        if (ord.getRElectricoFecha() != null) {
            fecha1 = ord.getRElectricoFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E", valor1);
        } else {
            fdfDoc.setField("F_E", valor1);
        }
        if (ord.getRPinturaFecha() != null) {
            fecha1 = ord.getRPinturaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P", valor1);
        } else {
            fdfDoc.setField("F_P", valor1);
        }
        //ASIGNO OPERARIO
        if (ord.getUsuarioByRHojalateriaAsigno() != null)
            fdfDoc.setField("A_H", ord.getUsuarioByRHojalateriaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_H", "");

        if (ord.getUsuarioByRMecanicaAsigno() != null)
            fdfDoc.setField("A_M", ord.getUsuarioByRMecanicaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_M", "");
        if (ord.getUsuarioByRSuspensionAsigno() != null)
            fdfDoc.setField("A_S", ord.getUsuarioByRSuspensionAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_S", "");
        if (ord.getUsuarioByRElectricoAsigno() != null)
            fdfDoc.setField("A_E", ord.getUsuarioByRElectricoAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_E", "");

        if (ord.getUsuarioByRPinturaAsigno() != null)
            fdfDoc.setField("A_P", ord.getUsuarioByRPinturaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_P", "");
        //LIMITE
        if (ord.getHojalateriaLimite() != null) {
            fecha1 = ord.getHojalateriaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H_L", valor1);
        } else {
            fdfDoc.setField("F_H_L", "");
        }
        if (ord.getMecanicaLimite() != null) {
            fecha1 = ord.getMecanicaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M_L", valor1);
        } else {
            fdfDoc.setField("F_M_L", "");
        }
        if (ord.getSuspensionLimite() != null) {
            fecha1 = ord.getSuspensionLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S_L", valor1);
        } else {
            fdfDoc.setField("F_S_L", "");
        }
        if (ord.getElectricoLimite() != null) {
            fecha1 = ord.getElectricoLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E_L", valor1);
        } else {
            fdfDoc.setField("F_E_L", "");
        }
        if (ord.getPinturaLimite() != null) {
            fecha1 = ord.getPinturaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P_L", valor1);
        } else {
            fdfDoc.setField("F_P_L", "");
        }

        Foto[] fotos = (Foto[]) ord.getFotos().toArray(new Foto[0]);
        for (int k = 0; k < fotos.length - 1; k++) {
            for (int f = 0; f < (fotos.length - 1) - k; f++) {
                if (fotos[f].getFecha().after(fotos[f + 1].getFecha()) == true) {
                    Foto aux;
                    aux = fotos[f];
                    fotos[f] = fotos[f + 1];
                    fotos[f + 1] = aux;
                }
            }
        }
        if (fotos.length > 0) {
            try {
                Image img;
                img = Image
                        .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + fotos[0].getDescripcion());
                img.setAbsolutePosition(30, 495);
                img.scaleAbsoluteWidth(124);
                img.scaleAbsoluteHeight(80);
                cb.addImage(img, true);
            } catch (Exception e) {
                //e.printStackTrace();
            }
        } else {
        }

        cb.endText();
        stamp.close();

        PDF reporte = new PDF();
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf");
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:org.alfresco.extension.pdftoolkit.repo.action.executer.PDFWatermarkActionExecuter.java

License:Apache License

/**
 * Applies a text watermark (current date, user name, etc, depending on
 * options)//  w  ww .j a v  a2  s .c o m
 * 
 * @param reader
 * @param writer
 * @param options
 */
private void textAction(Action ruleAction, NodeRef actionedUponNodeRef, ContentReader actionedUponContentReader,
        Map<String, Object> options) {

    PdfStamper stamp = null;
    File tempDir = null;
    ContentWriter writer = null;
    String watermarkText;
    StringTokenizer st;
    Vector<String> tokens = new Vector<String>();

    try {
        // get a temp file to stash the watermarked PDF in before moving to
        // repo
        File alfTempDir = TempFileProvider.getTempDir();
        tempDir = new File(alfTempDir.getPath() + File.separatorChar + actionedUponNodeRef.getId());
        tempDir.mkdir();
        File file = new File(tempDir,
                serviceRegistry.getFileFolderService().getFileInfo(actionedUponNodeRef).getName());

        // get the PDF input stream and create a reader for iText
        PdfReader reader = new PdfReader(actionedUponContentReader.getContentInputStream());
        stamp = new PdfStamper(reader, new FileOutputStream(file));
        PdfContentByte pcb;

        // get the PDF pages and position
        String pages = (String) options.get(PARAM_PAGE);
        String position = (String) options.get(PARAM_POSITION);
        String depth = (String) options.get(PARAM_WATERMARK_DEPTH);

        // create the base font for the text stamp
        BaseFont bf = BaseFont.createFont((String) options.get(PARAM_WATERMARK_FONT), BaseFont.CP1250,
                BaseFont.EMBEDDED);

        // get watermark text and process template with model
        String templateText = (String) options.get(PARAM_WATERMARK_TEXT);
        Map<String, Object> model = buildWatermarkTemplateModel(actionedUponNodeRef);
        StringWriter watermarkWriter = new StringWriter();
        freemarkerProcessor.processString(templateText, model, watermarkWriter);
        watermarkText = watermarkWriter.getBuffer().toString();

        // tokenize watermark text to support multiple lines and copy tokens
        // to vector for re-use
        st = new StringTokenizer(watermarkText, "\r\n", false);
        while (st.hasMoreTokens()) {
            tokens.add(st.nextToken());
        }

        // stamp each page
        int numpages = reader.getNumberOfPages();
        for (int i = 1; i <= numpages; i++) {
            Rectangle r = reader.getPageSizeWithRotation(i);

            // if this is an under-text stamp, use getUnderContent.
            // if this is an over-text stamp, use getOverContent.
            if (depth.equals(DEPTH_OVER)) {
                pcb = stamp.getOverContent(i);
            } else {
                pcb = stamp.getUnderContent(i);
            }

            // set the font and size
            float size = Float.parseFloat((String) options.get(PARAM_WATERMARK_SIZE));
            pcb.setFontAndSize(bf, size);

            // only apply stamp to requested pages
            if (checkPage(pages, i, numpages)) {
                writeAlignedText(pcb, r, tokens, size, position);
            }
        }

        stamp.close();

        // Get a writer and prep it for putting it back into the repo
        //can't use BasePDFActionExecuter.getWriter here need the nodeRef of the destination
        NodeRef destinationNode = createDestinationNode(file.getName(),
                (NodeRef) ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER), actionedUponNodeRef);
        writer = serviceRegistry.getContentService().getWriter(destinationNode, ContentModel.PROP_CONTENT,
                true);
        writer.setEncoding(actionedUponContentReader.getEncoding());
        writer.setMimetype(FILE_MIMETYPE);

        // Put it in the repo
        writer.putContent(file);

        // delete the temp file
        file.delete();
    } catch (IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    } catch (DocumentException e) {
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    } finally {
        if (tempDir != null) {
            try {
                tempDir.delete();
            } catch (Exception ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }

        if (stamp != null) {
            try {
                stamp.close();
            } catch (Exception ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }
    }
}

From source file:org.alfresco.repo.content.transform.ITextPDFWorker.java

License:Apache License

/**
 * Obtains the base arial unicode font, contained in the war.
 *
 * @return the created and registered base font
 *///from   ww w .  ja v  a  2  s.  c o m
private static BaseFont getBaseFont() {
    try {
        InputStream resourceAsStream = ITextPDFWorker.class.getResourceAsStream(ARIAL_TTF);
        File tempDir = TempFileProvider.getSystemTempDir();
        File tempFontFile = new File(tempDir, ARIAL_TTF);
        if (!tempFontFile.exists() || !tempFontFile.canRead()) {
            FileOutputStream fileOutputStream = new FileOutputStream(tempFontFile.getAbsoluteFile());
            IOUtils.copy(resourceAsStream, fileOutputStream);
            IOUtils.closeQuietly(fileOutputStream);
        }
        FontFactory.register(tempFontFile.getAbsolutePath());
        return BaseFont.createFont(tempFontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    } catch (Exception e) {
        e.printStackTrace();
        try {
            return BaseFont.createFont();
        } catch (Exception e1) {
            // shouldn't occur ever
            e1.printStackTrace();
        }
    }
    return null;
}

From source file:org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer.java

License:Open Source License

private static void registerTTF(final File f, final _ITextRenderer renderer) {
    if (f.isDirectory()) {
        final File[] list = f.listFiles();
        if (list != null) {
            for (int i = 0; i < list.length; i++) {
                CHtmlToPdfFlyingSaucerTransformer.registerTTF(list[i], renderer);
            }/*from  w  w  w.j a v  a 2  s.  co  m*/
        }
    } else if (CHtmlToPdfFlyingSaucerTransformer.accept(f.getParentFile(), f.getName())) {
        if (!renderer.isKnown(f.getAbsolutePath())) {
            /*InputStream in = null;
            try {
               in = f.toURI().toURL().openStream();
               GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(Font.createFont(Font.TRUETYPE_FONT, in));
            } catch (final Throwable ignore) {
            } finally {
               try {
                  if (in != null) {
             in.close();
                  }
               } catch (final Exception ignore) {
               }
            }*/
            try {
                renderer.getFontResolver().addFont(f.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                renderer.addKnown(f.getAbsolutePath());
            } catch (final Throwable ignore) {
            }
        }
    }
}

From source file:org.cherchgk.actions.tournament.result.show.GetPDFTournamentResultAction.java

License:Apache License

private BaseFont getBaseFont(String fontFileName) {
    String realPath = ActionContextHelper.getRequest().getSession().getServletContext().getRealPath("");
    String realFontFileName = realPath + File.separator + "WEB-INF" + File.separator + "fonts" + File.separator
            + fontFileName;/*  w  ww.j  av  a2  s .c  om*/
    try {
        return BaseFont.createFont(realFontFileName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    } catch (DocumentException e) {
        log.log(Level.SEVERE, "Can't read " + realFontFileName, e);
        return null;
    } catch (IOException e) {
        log.log(Level.SEVERE, "Can't read " + realFontFileName, e);
        return null;
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

public PdfStreamSource(FossaApplication app, LebData lebData, LebCreator lebCreator)
        throws DocumentException, IOException, PdfFormatierungsException {
    this.lebData = lebData;
    this.lebCreator = lebCreator;
    BaseFont fontNormal = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeNormalFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);
    BaseFont fontBold = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeBoldFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);/*from   w ww. j  ava 2 s.c o m*/
    BaseFont fontThin = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeThinFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);

    lernentwicklungsberichtUeberschriftFont = new Font(fontThin, 22, Font.NORMAL);
    standardTextFont = new Font(fontNormal, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    standardTextBoldFont = new Font(fontBold, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    headerFont = new Font(fontNormal, 12, Font.NORMAL);
    footerFont = new Font(fontNormal, 10, Font.NORMAL);
    fusszeilenFont = new Font(fontNormal, 8, Font.NORMAL);
    zeilenabstandsfaktor = KlassenstufenUtils.getLebZeilenabstandAsFactor(lebData.getKlassenname());
    document = null;
    try {
        document = new Document(PageSize.A4, 100, 90, topMargin, bottomMargin);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        LebPageHelper event = new LebPageHelper(lebData,
                Image.getInstance(app.getContext().getBaseDirectory() + Config.getRelativeLogoPath()),
                fusszeilenFont);
        writer.setPageEvent(event);
        document.open();
        addContent(writer);
        addFooter(lebData, writer);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:org.ganttproject.impex.htmlpdf.fonts.TTFontCache.java

License:Open Source License

private void registerFontFile(final File fontFile) throws FontFormatException, IOException {
    // FontFactory.register(fontFile.getAbsolutePath());
    Font awtFont = createAwtFont(fontFile);
    GPLogger.getLogger(getClass()).fine("Trying font file: " + fontFile.getAbsolutePath());

    final String family = awtFont.getFontName().toLowerCase();
    AwtFontSupplier awtSupplier = myMap_Family_RegularFont.get(family);

    try {/*from  w  ww.  j ava  2  s.  c o m*/
        myMap_Family_ItextFont.put(family, createFontSupplier(fontFile, BaseFont.EMBEDDED));
    } catch (DocumentException e) {
        if (e.getMessage().indexOf("cannot be embedded") < 0) {
            GPLogger.logToLogger(e);
            return;
        }
    }
    try {
        myMap_Family_ItextFont.put(family, createFontSupplier(fontFile, BaseFont.NOT_EMBEDDED));
    } catch (DocumentException e) {
        GPLogger.logToLogger(e);
        return;
    }
    GPLogger.getLogger(getClass()).fine("registering font: " + family);
    if (awtSupplier == null) {
        awtSupplier = new AwtFontSupplier();
        myMap_Family_RegularFont.put(family, awtSupplier);
    }
    awtSupplier.addFile(fontFile);
}