Java Code Examples for com.itextpdf.text.Font#NORMAL

The following examples show how to use com.itextpdf.text.Font#NORMAL . 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: PdfTableExcel.java    From excel2pdf with Apache License 2.0 6 votes vote down vote up
protected Font getFontByExcel(CellStyle style) {
    Font result = new Font(Resource.BASE_FONT_CHINESE , 8 , Font.NORMAL);
    Workbook wb = excel.getWorkbook();

    short index = style.getFontIndex();
    org.apache.poi.ss.usermodel.Font font = wb.getFontAt(index);

    if(font.getBoldweight() == org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD){
        result.setStyle(Font.BOLD);
    }

    HSSFColor color = HSSFColor.getIndexHash().get(font.getColor());

    if(color != null){
        int rbg = POIUtil.getRGB(color);
        result.setColor(new BaseColor(rbg));
    }

    FontUnderline underline = FontUnderline.valueOf(font.getUnderline());
    if(underline == FontUnderline.SINGLE){
        String ulString = Font.FontStyle.UNDERLINE.getValue();
        result.setStyle(ulString);
    }
    return result;
}
 
Example 2
Source File: StampHeader.java    From testarea-itext5 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
    * <a href="http://stackoverflow.com/questions/29977927/table-header-in-pdf-getting-displayed-using-itextpdf5-1-1-but-not-in-itextpdf5-5">
    * table header in pdf getting displayed using itextpdf5.1.1 but not in itextpdf5.5.3
    * </a>
    * <p>
    * Indeed, the code as presented by the OP does not show the header table. This makes sense, though:
    * </p>
    * <p>
    * The OP has cells with default padding (i.e. 2) and height 10, and he tries to insert text at height 7.
    * But 2 (top margin) + 7 (text height) + 2 (bottom margin) = 11, i.e. more than fits into the cell height 10.
    * Thus, the text does not fit and is not displayed.
    * </p>
    * <p>
    * You can fix this by either
    * <ul>
    * <li>using a smaller font, e.g. 6, or
    * <li>using a higher cell, e.g. 11, or
    * <li>using a smaller padding, e.g. 1, see below-
    * </p>
    */
@Test
public void testSandeepSinghHeaderTable() throws DocumentException, IOException
{
	byte[] strIntermediatePDFFile = createSampleDocument();
	String header1 = "Header 1";
	String header2 = "Header 2";
	String header3 = "Header 3";
	String header5 = "Header 5";
	

	Document document = new Document(PageSize.A4.rotate(), 20, 20, 75, 20);
	PdfCopy copy = new PdfCopy(document, new FileOutputStream(new File(RESULT_FOLDER, "stampTableHeader.pdf")));

	document.open();
	PdfReader pdfReaderIntermediate = new PdfReader(strIntermediatePDFFile);
	int numberOfPages = pdfReaderIntermediate.getNumberOfPages();
	Font ffont = new Font(Font.FontFamily.UNDEFINED, 7, Font.NORMAL);
	System.out.println("###### No. of Pages: " + numberOfPages);
	for (int j = 0; j < numberOfPages; )
	{
	    PdfImportedPage page = copy.getImportedPage(pdfReaderIntermediate, ++j);
	    PageStamp stamp = copy.createPageStamp(page);
	    Phrase footer = new Phrase(String.format("%d of %d", j, numberOfPages), ffont);
	    ColumnText.showTextAligned(stamp.getUnderContent(),
	                               Element.ALIGN_CENTER, footer,
	                               (document.right() - document.left()) /
	                               2 + document.leftMargin(),
	                               document.bottom() - 10, 0);
	    if (j != 1)
	    {
	    	PdfPTable headerTable = new PdfPTable(2);
	        headerTable.setTotalWidth(700);
	        headerTable.getDefaultCell().setFixedHeight(10);
	        headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	        headerTable.getDefaultCell().setPadding(1); // Added!
	        headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	        headerTable.addCell(new Phrase(String.format(header1), ffont));
	        headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
	        headerTable.addCell(new Phrase(String.format(header2), ffont));
	        headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	        headerTable.addCell(new Phrase(String.format(header3), ffont));
	        headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	        headerTable.addCell(new Phrase(String.format(header5, j), ffont));
	        headerTable.completeRow();
	        headerTable.writeSelectedRows(0, 5, 60.5f, 550, stamp.getUnderContent());
	    }

	    stamp.alterContents();
	    copy.addPage(page);
	}
	document.close();
}
 
Example 3
Source File: AsianFontProvider.java    From xiaoyaoji with GNU General Public License v3.0 4 votes vote down vote up
public Font getFont(final String fontname, final String encoding,
                    final boolean embedded, final float size, final int style,
                    final BaseColor color) {
    return new Font(BaseInfo.cjkFont, 10.5f, Font.NORMAL, BaseColor.BLACK);
}