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

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

Introduction

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

Prototype

String IDENTITY_H

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

Click Source Link

Document

The Unicode encoding with horizontal writing.

Usage

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

public static InterviewCandidateMaterial pdf(HttpServletRequest request, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf ");
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    //Font myAdobeTypekit = FontFactory.getFont(request.getRealPath(File.separator)+"resources"+File.separator+"HDZB_35.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

    try {/*w w w .j ava2  s . c o m*/
        //String fontPath = "C:/Windows/Fonts";

        String fontPath = request.getRealPath("/") + "resources" + File.separator + "hxb-meixinti";
        File f2 = new File(fontPath + "/hxb-meixinti.ttf");
        BaseFont bf1 = null;
        if (f2.exists()) {
            bf1 = BaseFont.createFont(fontPath + "/hxb-meixinti.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        } else {
            f2 = new File(fontPath + "/hxb-meixinti.ttf");

            if (f2.exists()) {
                System.out.println("File existed");
                bf1 = BaseFont.createFont(fontPath + "hxb-meixinti.ttf", BaseFont.IDENTITY_V,
                        BaseFont.EMBEDDED);
            } else {
                bf1 = BaseFont.createFont(FontManager.getFontPath(true) + "/hxb-meixinti.ttf",
                        BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            }
        }

        Font normalFontCH = new Font(bf1, 15);

        String fileName = request.getRealPath("/") + "resources" + File.separator + "upload" + File.separator;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = new Date();
        String time = (d1.getTime() + "").trim();
        String str = df.format(new Date()) + time;

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(fileName + "ApplicationForm_" + str + ".pdf"));
        InterviewCandidateMaterial material = new InterviewCandidateMaterial();
        material.setMaterialFileName("ApplicationForm_" + str + ".pdf");
        material.setCandidateCode(Integer.parseInt(request.getParameter("candidateCode")));
        material.setInterviewCode(Integer.parseInt(request.getParameter("interviewCode")));

        // PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E://applicatonForm2.pdf"));
        document.open();

        addTitle(document, writer, "formHeaderTitle", "Application Form");
        document = personalInformation(document, writer, addressbook, normalFontCH);
        document = familyInformation(document, writer, addressbook);
        document = workExperience(document, writer, addressbook);
        document = Education(document, writer, addressbook);
        document = personalCertification(document, writer, addressbook);
        document = ESingnature(document, writer, addressbook);

        document.close();

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        File file = new File(fileName + "ApplicationForm_" + str + ".pdf");
        FileInputStream fis = new FileInputStream(file);
        byte[] buf = new byte[1024];
        for (int readNum; (readNum = fis.read(buf)) != -1;) {
            bos.write(buf, 0, readNum); //no doubt here is 0
        }
        material.setFormContent(bos.toByteArray());
        material.setCreatedDate(new Date());
        material.setMaterialDescrption("AppicationForm");

        //  applicationForm.setFormContent(bos.toByteArray());

        return material;
    } catch (Exception e) {
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf --> Exception  " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return null;

}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getFooterFont() {
    if (footerFont == null) {
        Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.5f,
                Font.NORMAL, BaseColor.BLACK);
        footerFont = font.getBaseFont();
    }/*from   www  .  ja v  a2  s.  c o m*/
    return footerFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineFont() {
    if (lineFont == null) {
        Font font = FontFactory.getFont("/" + LINE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.NORMAL, BaseColor.BLACK);
        lineFont = font.getBaseFont();/*from   w ww .j  av  a 2  s.c  o  m*/
    }
    return lineFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineItalicFont() {
    if (lineItalicFont == null) {
        Font font = FontFactory.getFont("/" + LINE_FONT_ITALIC_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.ITALIC, BaseColor.BLACK);
        lineItalicFont = font.getBaseFont();
    }/*w w w. j  a  v  a2s  .co  m*/
    return lineItalicFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineFontBold() {
    if (lineBoldFont == null) {
        Font font = FontFactory.getFont("/" + LINE_BOLD_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.BOLD, BaseColor.BLACK);
        lineBoldFont = font.getBaseFont();
    }//from   w  w  w. j ava  2 s  .  com
    return lineBoldFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getTitleFont() {
    if (titleFont == null) {
        Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.NORMAL, BaseColor.BLACK);
        titleFont = font.getBaseFont();//from w ww .j  a v  a2s  .c  o m
    }
    return titleFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getSubtitleFont() {
    if (tableSubtitleFont == null) {
        Font font = FontFactory.getFont("/" + TABLE_SUBTITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.ITALIC, BaseColor.BLACK);
        tableSubtitleFont = font.getBaseFont();
    }//from w ww  .  j a v  a2  s.  c  om
    return tableSubtitleFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getHandwrittingFont() {
    if (handwrittingFont == null) {
        Font font = FontFactory.getFont("/" + HANDWRITTING_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.NORMAL, BaseColor.BLACK);
        handwrittingFont = font.getBaseFont();
    }//from  w  w w .j a  v a 2 s.  c o m
    return handwrittingFont;
}

From source file:com.stee.emer.util.PdfGenerator.java

License:Open Source License

public static byte[] generate(Map<String, String> map) throws IOException, DocumentException {
    URL classPath = PdfGenerator.class.getClassLoader().getResource("");
    PdfReader pdfReader = new PdfReader(classPath + "com/stee/emer/model/model.pdf");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfStamper pdfStamper = new PdfStamper(pdfReader, os);
    AcroFields acroFields = pdfStamper.getAcroFields();
    BaseFont baseFont = BaseFont.createFont(classPath + "MSYH.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    ArrayList<BaseFont> list = new ArrayList<BaseFont>();
    list.add(baseFont);/*from ww  w  . j av  a2  s. c  o m*/
    acroFields.setSubstitutionFonts(list);
    Iterator<Entry<String, String>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> next = iterator.next();
        acroFields.setField(next.getKey(), next.getValue());
    }

    pdfStamper.setFormFlattening(true);
    pdfStamper.close();

    // File file = new File("e:/temp.pdf");
    // FileOutputStream fileOutputStream = new FileOutputStream(file);
    // fileOutputStream.write(os.toByteArray());
    // fileOutputStream.flush();
    // fileOutputStream.close();
    return os.toByteArray();
}

From source file:com.swayam.bhasha.engine.io.writers.impl.PDFGenerator.java

License:Apache License

private Paragraph getParagraph(Para para) throws DocumentException, IOException, DocGenerationException {

    int align = para.getAlignment();
    int pdfAlign;

    switch (align) {
    case Para.CENTER:
        pdfAlign = Paragraph.ALIGN_CENTER;
        break;/*from  w w  w .j  a va2  s .  co m*/

    case Para.RIGHT:
        pdfAlign = Paragraph.ALIGN_RIGHT;
        break;

    case Para.JUSTIFIED:
        pdfAlign = Paragraph.ALIGN_JUSTIFIED;
        break;

    case Para.LEFT:
    default:
        pdfAlign = Paragraph.ALIGN_LEFT;
        break;
    }

    List<ParaText> paraTextList = para.getParaTextList();
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(pdfAlign);

    for (ParaText paraText : paraTextList) {

        int fontStyle = Font.NORMAL;

        if (paraText.isBold()) {
            fontStyle |= Font.BOLD;
        }

        if (paraText.isUnderline()) {
            fontStyle |= Font.UNDERLINE;
        }

        if (paraText.isItalic()) {
            fontStyle |= Font.ITALIC;
        }

        Font font = FontFactory.getFont(paraText.getFontFamily(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                paraText.getFontSize(), fontStyle, new BaseColor(paraText.getColor().getRGB()));

        // its very important to set the leading every time the font is set
        // otherwise, the chunks/phrases overlap.
        // paragraph.setLeading(font.getSize() * 1.5f);

        paragraph.add(new Phrase(paraText.getText(), font));
    }

    return paragraph;

}