Java Code Examples for org.apache.pdfbox.pdmodel.font.PDType1Font#TIMES_ROMAN

The following examples show how to use org.apache.pdfbox.pdmodel.font.PDType1Font#TIMES_ROMAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfTools.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static PDFont getFont(PDDocument document, String name) {
        PDFont font = PDType1Font.HELVETICA;
        try {
            String fontFile = null;
            switch (name) {
                case "宋体":
                    fontFile = FileTools.getFontFile("simsun");
                    break;
                case "幼圆":
                    fontFile = FileTools.getFontFile("SIMYOU");
                    break;
                case "仿宋":
                    fontFile = FileTools.getFontFile("simfang");
                    break;
                case "隶书":
                    fontFile = FileTools.getFontFile("SIMLI");
                    break;
                case "Helvetica":
                    return PDType1Font.HELVETICA;
                case "Courier":
                    return PDType1Font.COURIER;
                case "Times New Roman":
                    return PDType1Font.TIMES_ROMAN;
            }
            if (fontFile != null) {
//                logger.debug(fontFile);
                font = PDType0Font.load(document, new File(fontFile));
            }
        } catch (Exception e) {
        }
//        logger.debug(font.getName());
        return font;
    }
 
Example 2
Source File: PdfBoxFontMapper.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static PDType1Font getPDFont(Font javaFont) {
	switch (javaFont.getFamily()) {
		case Font.SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.TIMES_ROMAN;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.TIMES_BOLD_ITALIC;
				} else {
					return PDType1Font.TIMES_BOLD;
				}
			} else {
				return PDType1Font.TIMES_ITALIC;
			}
		case Font.SANS_SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.HELVETICA;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.HELVETICA_BOLD_OBLIQUE;
				} else {
					return PDType1Font.HELVETICA_BOLD;
				}
			} else {
				return PDType1Font.HELVETICA_OBLIQUE;
			}
		case Font.MONOSPACED:
			if (javaFont.isPlain()) {
				return PDType1Font.COURIER;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.COURIER_BOLD_OBLIQUE;
				} else {
					return PDType1Font.COURIER_BOLD;
				}
			} else {
				return PDType1Font.COURIER_OBLIQUE;
			}
		case Font.DIALOG:
		case Font.DIALOG_INPUT:
			return PDType1Font.SYMBOL;
		default:
			throw new DSSException("The font is not supported! Please use DSSFileFont implementation for custom fonts.");
		}
}