com.jk.framework.pdf.PDFUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.jk.framework.pdf.PDFUtil.java

Source

/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jk.framework.pdf;

import java.io.File;
import java.io.IOException;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;

/**
 * The Class PDFUtil.
 *
 * @author Jalal Kiswani
 */
public class PDFUtil {

    /** The Constant DEFAULT_SIZE. */
    public static final int DEFAULT_SIZE = 10;

    /** The Constant DEFAULT_ARIAL. */
    public static final String DEFAULT_ARIAL = "arial";

    /**
     * Creates the font.
     *
     * @return the font
     * @throws DocumentException
     *             the document exception @1.1
     */
    public static Font createFont() throws DocumentException {
        return createFont(DEFAULT_SIZE, false);
    }

    /**
     * Creates the font.
     *
     * @param size
     *            the size
     * @param fontStyle
     *            the font style
     * @return the font
     * @throws DocumentException
     *             the document exception @1.1
     */
    public static Font createFont(final int size, final boolean fontStyle) throws DocumentException {
        return createFont(DEFAULT_ARIAL, size, fontStyle);
    }

    /**
     * Creates the font.
     *
     * @param fontName
     *            the font name
     * @param size
     *            the size
     * @param fontStyle
     *            the font style
     * @return the font
     * @throws DocumentException
     *             the document exception @1.1
     */
    public static Font createFont(final String fontName, final int size, final boolean fontStyle)
            throws DocumentException {
        BaseFont baseFont;
        Font font = null;
        try {
            baseFont = BaseFont.createFont("c:/windows/fonts/" + fontName + ".ttf", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            if (fontStyle == true) {
                font = new Font(baseFont, size, Font.BOLD);
            } else {
                font = new Font(baseFont, size, Font.NORMAL);
            }
            // return new Font(baseFont, size);
            return font;
        } catch (final IOException e) {
            throw new DocumentException(e);
        }
    }

    /**
     * Rotate PDF file.
     *
     * @param file
     *            the file
     */
    public static void rotatePDFFile(final File file) {
        // TODO Auto-generated method stub

    }

}