Java Code Examples for com.itextpdf.text.Font

The following are top voted examples for showing how to use com.itextpdf.text.Font. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NICON   File: ExporOnlyViagemPdf.java   Source Code and License 10 votes vote down vote up
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
    Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
    PdfPTable pTable = new PdfPTable(1);
    pTable.setWidthPercentage(100f);
    PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
    if(l){cellValue.setBorderWidthLeft(0);}
    if(r){cellValue.setBorderWidthRight(0);}
   switch (align) 
   {
       case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
       case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
       case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
       default:break;
   }
    pTable.addCell(cellValue);
    return pTable;
}
 
Example 2
Project: ureport   File: PageHeaderFooterEvent.java   Source Code and License 8 votes vote down vote up
private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){
	PdfPCell cell=new PdfPCell();
	cell.setPadding(0);
	cell.setBorder(Rectangle.NO_BORDER);
	Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline());
	String fontColor=phf.getForecolor();
	if(StringUtils.isNotEmpty(fontColor)){
		String[] color=fontColor.split(",");
		font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));			
	}
	Paragraph graph=new Paragraph(text,font);
	cell.setPhrase(graph);
	switch(type){
	case 1:
		cell.setHorizontalAlignment(Element.ALIGN_LEFT);
		break;
	case 2:
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		break;
	case 3:
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
		break;
	}
	cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	return cell;
}
 
Example 3
Project: NICON   File: ExportMapaProducao__.java   Source Code and License 7 votes vote down vote up
private Phrase funcaoTitulo(int i) {
    String txt;
    Font fontcabecatable =  FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
    switch (i)
    {
        case 0:txt="Nr. Factura";break;
        case 1:txt="Nome do Segurado"; break;
        case 2:txt="Prémio";break;
        case 3:txt="Imposto 6%";break;
        case 4:txt="Imposto 5%";break;
        case 5:txt="FGA 2.6%";break;
        default:txt="TOTAL";break;
    }
    
    a=com.itextpdf.text.Element.ALIGN_CENTER;
    Phrase rt = new Phrase(txt,fontcabecatable);
    return rt; 
}
 
Example 4
Project: bdf2   File: PdfReportPageNumber.java   Source Code and License 7 votes vote down vote up
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 页   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("页",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
Example 5
Project: NICON   File: ExporOnlyViagemPdf.java   Source Code and License 7 votes vote down vote up
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
    Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
    PdfPTable pTable = new PdfPTable(1);
    pTable.setWidthPercentage(100f);
    PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
    if(l){cellValue.setBorderWidthLeft(0);}
    if(r){cellValue.setBorderWidthRight(0);}
   switch (align) 
   {
       case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
       case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
       case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
       default:break;
   }
    pTable.addCell(cellValue);
    return pTable;
}
 
Example 6
Project: testarea-itext5   File: UseColumnText.java   Source Code and License 7 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
 * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
 * </a>
 * <p>
 * Indeed, the coordinates do not line up. The y coordinate of 
 * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
 * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
 * the text to come.
 * </p>
 */
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
    document.open();

    Font fontQouteItems = new Font(BaseFont.createFont(), 12);
    PdfContentByte canvas = writer.getDirectContent();

    // Item Number
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);

    // Estimated Qty
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);

    // Item Description
    ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
    ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
    ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
    ct.go();

    document.close();
}
 
Example 7
Project: gutenberg   File: PygmentsAdapter.java   Source Code and License 7 votes vote down vote up
private int calculateStyle(Style style) {
    int s = Font.NORMAL;
    if (style.isBold()) {
        s |= Font.BOLD;
    }
    if (style.isItalic()) {
        s |= Font.ITALIC;
    }
    if (style.isStrikethrough()) {
        s |= Font.STRIKETHRU;
    }
    if (style.isUnderline()) {
        s |= Font.UNDERLINE;
    }
    return s;
}
 
Example 8
Project: CoECI-OPM-Service-Credit-Redeposit-Deposit-Application   File: ReportServiceHelper.java   Source Code and License 7 votes vote down vote up
/**
 * Adds the report title for balanced report.
 *
 * @param document
 *         the report document.
 * @param reportName
 *         the report name.
 * @param fiscalYear
 *         the fiscal year.
 * @param quarter
 *         the quarter.
 * @param startDate
 *         the start date.
 * @param endDate
 *         the end date.
 * @throws com.itextpdf.text.DocumentException
 *         if any error occurs.
 */
static void addBalancedReportTitle(com.itextpdf.text.Document document, String reportName, Integer fiscalYear,
                                   Integer quarter, Date startDate, Date endDate)
        throws com.itextpdf.text.DocumentException {
    com.itextpdf.text.Paragraph title = new com.itextpdf.text.Paragraph(reportName,
            new Font(FontFamily.HELVETICA, 16, Font.BOLD));
    title.setAlignment(PDF_ALIGN_CENTER);
    document.add(title);
    if (fiscalYear != null && quarter != null) {
        com.itextpdf.text.Paragraph subTitle1 = new com.itextpdf.text.Paragraph("Fiscal Year " + fiscalYear +
                " - Quarter" + quarter, new Font(FontFamily.HELVETICA, 14, Font.BOLD));
        subTitle1.setAlignment(PDF_ALIGN_CENTER);
        document.add(subTitle1);
    }
    if (startDate != null && endDate != null) {
        com.itextpdf.text.Paragraph subTitle2 = new com.itextpdf.text.Paragraph("Processed between " +
                "" + REPORT_DATE_FORMAT.format(startDate) + " and " +
                "" + REPORT_DATE_FORMAT.format(endDate),
                new Font(FontFamily.HELVETICA, 12, Font.BOLD));
        subTitle2.setAlignment(PDF_ALIGN_CENTER);
        document.add(subTitle2);
    }
}
 
Example 9
Project: lexml-renderer-pdf   File: LexmlFontFactory.java   Source Code and License 7 votes vote down vote up
public Font getFont(int _style, final float size) {
	final int style;
	if(!allowUnderline) {
		style = _style & (~(Font.UNDERLINE));
	} else {
		style = _style;
	}
	String key = style + "," + size;
	return getFont(key, new FontBuilder() {
		@Override
		public Font createFont() {
	    	int baseStyle = style & Font.BOLDITALIC;
			BaseFont bf = baseFontMap.get(baseStyle);
	        return new Font(bf, size, style);
		}
	});    	
}
 
Example 10
Project: JavaGraph   File: ExploreConfigDialog.java   Source Code and License 6 votes vote down vote up
@Override
public void refresh() {
    ExploreConfig config = extractConfig();
    String commandLine = config.toCommandLine();
    if (commandLine.isEmpty()) {
        setForeground(Color.GRAY);
        setFont(getFont().deriveFont(Font.ITALIC));
        setText("No parameters");
        setEnabled(false);
    } else {
        setForeground(Color.BLACK);
        setFont(getFont().deriveFont(Font.NORMAL));
        setText(commandLine);
        setEnabled(true);
    }
}
 
Example 11
Project: NICON   File: ExporOnlyViagemPdf.java   Source Code and License 6 votes vote down vote up
private Phrase funcaoTitulo(int i) {
        String txt;
        Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
       switch (i) 
       {
           case 0:txt="S/N";break;
           case 1:txt="DATA";break;
           case 2:txt="APOLICE";break;
           case 3:txt="DATA INICIO";break;
           case 4:txt="DATA FIM";break;
           case 5:txt="NO. DIAS";break;
           case 6:txt="NOME";break;
           case 7:txt="RECEIPT NO.";break;
           case 8:txt="EA PREM";break;
           case 9:txt="NICON COMISSÃO";break;
           case 10:txt="5% IMPOSTO";break;
           case 11:txt="0.60% SELO";break;
//           case 12:txt="NET OUT OF TAX";break;
           default:txt="TOTAL"/*"NET OUT OF TAX"*/;break;
       }
        
        Phrase rt = new Phrase(txt,fontcabecatable);
        return rt; 
    }
 
Example 12
Project: DWSurvey   File: ItextpdfTest.java   Source Code and License 6 votes vote down vote up
public static void writeSimplePdf() throws Exception{
			//1.新建document对象
			//第一个参数是页面大小。接下来的参数分别是左、右、上和下页边距。
			Document document = new Document(PageSize.A4, 50, 50, 50, 50);
			//2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
			//创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
			PdfWriter writer = PdfWriter.getInstance(document, 	new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
			//3.打开文档
			document.open();		
			//4.向文档中添加内容
			//通过 com.lowagie.text.Paragraph 来添加文本。可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落
			BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
			
			document.add(new Paragraph("sdfsdfsd全是中文显示了没.fsdfsfs",fontChinese));
			document.add(new Paragraph("Some more text on the 	first page with different color and font type.",
					FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
			Paragraph pragraph=new Paragraph("你这里有中亠好", fontChinese);
			document.add(pragraph);
			
			//图像支持格式 GIF, Jpeg, PNG, wmf
			Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
			gif.setBorder(5);
			gif.scaleAbsolute(30,30);
			gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
			document.add(gif);
			Paragraph pragraph11=new Paragraph("你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好", fontChinese);
			document.add(pragraph11);
			
			Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
//			gif15.setBorder(50);
			gif15.setBorder(Image.BOX);
			gif15.setBorderColor(BaseColor.RED);
//			gif15.setBorderColorBottom(borderColorBottom)
			gif15.setBorderWidth(1);
			gif15.scalePercent(50);
			document.add(gif15);
			//5.关闭文档
			document.close();
		}
 
Example 13
Project: hotel   File: ResidenceService.java   Source Code and License 6 votes vote down vote up
private void addOfferInstances(List<OfferInstance> offerInstances, Document document, BaseFont bf)
		throws DocumentException {

	if(offerInstances.isEmpty()) {
		return;
	}

	document.add(new Paragraph("Wybrane oferty: ", new Font(bf, 12)));

	PdfPTable offerInstancesTable = new PdfPTable(3);
	offerInstancesTable.setWidthPercentage(100);
	offerInstancesTable.setSpacingBefore(18f);
	offerInstancesTable.setSpacingAfter(18f);
	createofferInstancesTableHeaders(offerInstancesTable);
	createofferInstancesTableContent(offerInstances, offerInstancesTable);
	document.add(offerInstancesTable);
}
 
Example 14
Project: NICON   File: ExporOnlyViagemPdf.java   Source Code and License 6 votes vote down vote up
private Phrase funcaoTitulo(int i) {
        String txt;
        Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
       switch (i) 
       {
           case 0:txt="S/N";break;
           case 1:txt="DATA";break;
           case 2:txt="APOLICE";break;
           case 3:txt="DATA INICIO";break;
           case 4:txt="DATA FIM";break;
           case 5:txt="NO. DIAS";break;
           case 6:txt="NOME";break;
           case 7:txt="RECEIPT NO.";break;
           case 8:txt="EA PREM";break;
           case 9:txt="NICON COMISSÃO";break;
           case 10:txt="5% IMPOSTO";break;
           case 11:txt="0.60% SELO";break;
//           case 12:txt="NET OUT OF TAX";break;
           default:txt="TOTAL"/*"NET OUT OF TAX"*/;break;
       }
        
        Phrase rt = new Phrase(txt,fontcabecatable);
        return rt; 
    }
 
Example 15
Project: NICON   File: ExportMapaProducao__.java   Source Code and License 6 votes vote down vote up
private Phrase funcaoTitulo(int i) {
    String txt;
    Font fontcabecatable =  FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
    switch (i)
    {
        case 0:txt="Nr. Factura";break;
        case 1:txt="Nome do Segurado"; break;
        case 2:txt="Prémio";break;
        case 3:txt="Imposto 6%";break;
        case 4:txt="Imposto 5%";break;
        case 5:txt="FGA 2.6%";break;
        default:txt="TOTAL";break;
    }
    
    a=com.itextpdf.text.Element.ALIGN_CENTER;
    Phrase rt = new Phrase(txt,fontcabecatable);
    return rt; 
}
 
Example 16
Project: ArasuiteIta   File: HeaderFooter.java   Source Code and License 6 votes vote down vote up
/**
      * Increase the page number.
      * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
      *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
      */
     @Override
public void onStartPage(PdfWriter writer, Document document) {
         pagenumber++;
         System.out.println("ON Start Page PDF");
Rectangle rect = writer.getBoxSize("art");
         
         /* header     
         ColumnText.showTextAligned(writer.getDirectContent(),                		
             		com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
                     rect.getRight(), rect.getTop(), 0);
          */  
		  Font font = new Font();
		  font.setSize(8);
         if (G.licensePDF) {
          ColumnText.showTextAligned(writer.getDirectContent(),
          		com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")),font),
                  (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
          ColumnText.showTextAligned(writer.getDirectContent(),
	          		com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")),font),
	                  (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
         }
         
         
     }
 
Example 17
Project: ExcelToBarcode   File: MainController.java   Source Code and License 6 votes vote down vote up
private Font findFont(org.apache.poi.ss.usermodel.Cell cell) {
    if(cell == null) return new Font(Font.FontFamily.HELVETICA, 10);
    if(xSSFWorkbook == null)
        throw new NullPointerException("workbook was null!");
    final org.apache.poi.ss.usermodel.Font f = xSSFWorkbook.getFontAt(cell.getCellStyle().getFontIndex());
    

    final Font.FontFamily family;
    final String fontName = f.getFontName().toLowerCase();
    if(fontName.contains("times")) family = Font.FontFamily.TIMES_ROMAN;
    else if(fontName.contains("courier")) family = Font.FontFamily.COURIER;
    else if(fontName.contains("symbol")) family = Font.FontFamily.SYMBOL;
    else family = Font.FontFamily.HELVETICA;
    
    //final Font result = new Font(family, size);
    // the font height value is 20 * the font size in points
    final Font result = new Font(family, (float) f.getFontHeight() / 20);
    
    if(f.getBold()) result.setStyle(Font.BOLD);
    if(f.getItalic()) result.setStyle(Font.ITALIC);
    return result;
}
 
Example 18
Project: OpenSongTablet   File: ExportPreparer.java   Source Code and License 6 votes vote down vote up
private static void makePDF(Bitmap bmp, File file) {
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.addAuthor(FullscreenActivity.mAuthor.toString());
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.addCreator("OpenSongApp");
        if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
            document.setPageSize(PageSize.A4.rotate());
        } else {
            document.setPageSize(PageSize.A4);
        }
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
        BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
        Font TitleFontName  = new Font(urName, 14);
        Font AuthorFontName = new Font(urName, 10);
        document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
        document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
        addImage(document,bmp);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 19
Project: testarea-itext5   File: StampUnicodeText.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader. With a different starting file, though, it doesn't, cf.
 * {@link #testAddUnicodeStampEg_01()}.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampSampleOriginal() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("sampleOriginal.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "sampleOriginal-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);
        
        stamper.close();
    }
}
 
Example 20
Project: testarea-itext5   File: StampUnicodeText.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader, cf. {@link #testAddUnicodeStampSampleOriginal()}. With
 * a different starting file, though, it doesn't as this test shows.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampEg_01() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("eg_01.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "eg_01-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);

        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);
        
        stamper.close();
    }
}
 
Example 21
Project: testarea-itext5   File: StampUnicodeText.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader, cf. {@link #testAddUnicodeStampSampleOriginal()}. With
 * a different starting file, though, it doesn't, cf.
 * {@link #testAddUnicodeStampEg_01()}. This test creates a new PDF with the same
 * font and chunk as stamped by the OP. Adobe Reader has no problem with it either.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testCreateUnicodePdf() throws DocumentException, IOException
{
    Document document = new Document();
    try (   OutputStream result  = new FileOutputStream(new File(RESULT_FOLDER, "unicodePdf.pdf")) )
    {
        PdfWriter.getInstance(document, result);
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

        document.open();
        
        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        document.add(p);
        
        document.close();
    }
}
 
Example 22
Project: testarea-itext5   File: DoubleSpace.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/35699167/double-space-not-being-preserved-in-pdf">
 * Double space not being preserved in PDF
 * </a>
 * <p>
 * Indeed, the double space collapses into a single one when copying&pasting from the
 * generated PDF displayed in Adobe Reader. On the other hand the gap for the double
 * space is twice as wide as for the single space. So this essentially is a quirk of
 * copy&paste of Adobe Reader (and some other PDF viewers, too).
 * </p>
 */
@Test
public void testDoubleSpace() throws DocumentException, IOException
{
    try (   OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "DoubleSpace.pdf")))
    {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorderWidth(0.5f);
        table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);

        table.addCell(new Phrase("SINGLE SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("DOUBLE  SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("TRIPLE   SPACED", new Font(BaseFont.createFont(), 36)));

        Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter.getInstance(pdfDocument, pdfStream);
        pdfDocument.open();
        pdfDocument.add(table);
        pdfDocument.close();
    }
}
 
Example 23
Project: testarea-itext5   File: UseRowspan.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/44005834/changing-rowspans">
 * Changing rowspans
 * </a>
 * <p>
 * Helper method of the OP.
 * </p>
 * @see #testUseRowspanLikeUser7968180()
 * @see #testUseRowspanLikeUser7968180Fixed()
 * @see #createPdf(String)
 * @see #createPdfFixed(String)
 */
private static void addCellToTableCzech(PdfPTable table, int horizontalAlignment,
        int verticalAlignment, String value, int colspan, int rowspan,
        String fontType, float fontSize) {
    BaseFont base = null;
    try {
        base = BaseFont.createFont(fontType, BaseFont.CP1250, BaseFont.EMBEDDED);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Font font = new Font(base, fontSize);
    PdfPCell cell = new PdfPCell(new Phrase(value, font));
    cell.setColspan(colspan);
    cell.setRowspan(rowspan);
    cell.setHorizontalAlignment(horizontalAlignment);
    cell.setVerticalAlignment(verticalAlignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
}
 
Example 24
Project: testarea-itext5   File: ImportPageWithoutFreeSpace.java   Source Code and License 6 votes vote down vote up
/**
 * This method creates a PDF with a single styled paragraph.
 */
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Phrase("Beware: ", new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC)));
    paragraph.add(new Phrase("The implementation of ", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    paragraph.add(new Phrase("MarginFinder", new Font(FontFamily.COURIER, 12, Font.ITALIC)));
    paragraph.add(new Phrase(" is far from optimal. It is not even correct as it includes all curve control points which is too much. Furthermore it ignores stuff like line width or wedge types. It actually merely is a proof-of-concept.", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    document.add(paragraph);

    document.close();

    return baos.toByteArray();
}
 
Example 25
Project: testarea-itext5   File: DynamicFooter.java   Source Code and License 6 votes vote down vote up
public PdfPTable generateFooter() {
    try {
        BaseFont baseFont = BaseFont.createFont(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf", BaseFont.IDENTITY_H, true);
        footerTable = new PdfPTable(1);
        footerTable.setTotalWidth(440);
        footerTable.setLockedWidth(true);

        Font pageNumberFont = new Font(baseFont, 9, Font.BOLD);
        Paragraph pageNumberP = new Paragraph(titleIndex+"-"+ pageNumber, pageNumberFont);
        PdfPCell pageNumberCell = new PdfPCell(pageNumberP);
        pageNumberCell.setBorder(0);
        pageNumberCell.setPaddingTop(20);
        footerTable.addCell(pageNumberCell);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return footerTable;
}
 
Example 26
Project: MountainQuest-PL   File: TableOfContentsPageGenerator.java   Source Code and License 6 votes vote down vote up
private void generateSectionTitle(PdfPTable table, Data data) throws IOException, DocumentException {
    if (!this.currentSection.equals(data.mountains)) {
        currentSection = data.mountains;
        currentBackgroundColor = backgroundColorGenerator.generate(data);

        PdfPCell cellSeparator = new PdfPCell(PhraseUtil.phrase(" "));
        cellSeparator.setBorder(0);
        cellSeparator.setPadding(10);
        cellSeparator.setColspan(4);
        table.addCell(cellSeparator);

        PdfPCell cell = new PdfPCell(PhraseUtil.phrase(currentSection, 14, Font.BOLD));
        cell.setBorder(0);
        cell.setPadding(10);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setColspan(4);
        cell.setBackgroundColor(currentBackgroundColor);
        table.addCell(cell);
    }
}
 
Example 27
Project: weplantaforest   File: PdfHelper.java   Source Code and License 6 votes vote down vote up
public static void createCircleAndText(PdfContentByte cb, String text, float xCoord, float yCoord, float radius, Font textFont, int circleColorRed, int circleColorGreen, int circleColorBlue)
        throws DocumentException, IOException {
    cb.saveState();
    cb.setRGBColorFill(circleColorRed, circleColorGreen, circleColorBlue);
    cb.circle(xCoord, yCoord, radius);
    cb.fill();
    cb.stroke();
    cb.restoreState();

    PdfPTable table = new PdfPTable(1);
    float[] rows = { 595f };
    table.setTotalWidth(rows);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setFixedHeight(radius * 2);
    table.addCell(new Phrase(new Chunk(text, textFont)));
    table.writeSelectedRows(0, 1, 0, yCoord + radius, cb);
}
 
Example 28
Project: OLE-INST   File: OlePrintSlip.java   Source Code and License 6 votes vote down vote up
public void populateFontMap() {

        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.BOLD).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.BOLDITALIC).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.DEFAULTSIZE).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.STRIKETHRU).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.NORMAL).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.UNDEFINED).getBaseFont()));
        fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.UNDERLINE).getBaseFont()));

       /* fontMap.put("COURIER", new Font(Font.COURIER));
        fontMap.put("BOLD", new Font(Font.BOLD));
        fontMap.put("BOLDITALIC", new Font(Font.BOLDITALIC));
        fontMap.put("DEFAULTSIZE", new Font(Font.DEFAULTSIZE));
        fontMap.put("HELVETICA", new Font(Font.HELVETICA));
        fontMap.put("ITALIC", new Font(Font.ITALIC));
        fontMap.put("NORMAL", new Font(Font.NORMAL));
        fontMap.put("STRIKETHRU", new Font(Font.STRIKETHRU));
        fontMap.put("SYMBOL", new Font(Font.SYMBOL));
        fontMap.put("TIMES_ROMAN", new Font(Font.TIMES_ROMAN));
        fontMap.put("UNDEFINED", new Font(Font.UNDEFINED));
        fontMap.put("UNDERLINE", new Font(Font.UNDERLINE));
        fontMap.put("ZAPFDINGBATS", new Font(Font.ZAPFDINGBATS));*/

    }
 
Example 29
Project: NLB   File: PDFFont.java   Source Code and License 6 votes vote down vote up
public PDFFont(float size, Style style, RGBColor color) throws HTDocumentException {
    try {
        BaseFont baseFont = (
                BaseFont.createFont("fonts/ttf/dejavu/DejaVuSans.ttf", "cp1251", BaseFont.EMBEDDED)
        );
        int iStyle;
        switch (style) {
            case BOLD:
                iStyle = Font.BOLD;
                break;
            case ITALIC:
                iStyle = Font.ITALIC;
                break;
            case UNDERLINE:
                iStyle = Font.UNDERLINE;
                break;
            default:
                iStyle = Font.NORMAL;
                break;
        }
        m_font = new Font(
                baseFont,
                size,
                iStyle,
                new BaseColor(color.getRed(), color.getGreen(), color.getBlue())
        );
    } catch (DocumentException | IOException e) {
        throw new HTDocumentException("Error while creating PDF font", e);
    }
}
 
Example 30
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildHeaderNameLine(String schuelername, Font headerFont) throws DocumentException {
	PdfPCell labelCell = new PdfPCell(new Phrase("Name", headerFont));
	labelCell.setBorder(Rectangle.BOTTOM);
	labelCell.setBorderWidth(1f);

	PdfPCell nameCell = new PdfPCell(new Phrase(schuelername, headerFont));
	nameCell.setBorder(Rectangle.BOTTOM);
	nameCell.setBorderWidth(1f);
	nameCell.setColspan(5);
	
	PdfPTable table = prebuildHeaderTable();
	table.addCell(labelCell);
	table.addCell(nameCell);
	
	return table;
}
 
Example 31
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterVersetzungsvermerkLine(String versetzungsvermerk, Font footerFont) throws DocumentException {
	PdfPCell labelCell = new PdfPCell(new Phrase("Versetzungsvermerk", footerFont));
	labelCell.setBorder(Rectangle.BOTTOM);
	labelCell.setBorderWidth(1f);

	PdfPCell nameCell = new PdfPCell(new Phrase(versetzungsvermerk, footerFont));
	nameCell.setBorder(Rectangle.BOTTOM);
	nameCell.setBorderWidth(1f);
	
	PdfPTable table = new PdfPTable(2);
	table.setHorizontalAlignment(Element.ALIGN_LEFT);
	table.setWidthPercentage(100f);
	table.addCell(labelCell);
	table.addCell(nameCell);
	table.setWidths(new float[] {0.3f, 0.7f});
	return table;
}
 
Example 32
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterDatumLine(String datumString, Font footerFont) throws DocumentException {
	PdfPCell labelCell = new PdfPCell(new Phrase("Datum", footerFont));
	labelCell.setBorder(Rectangle.BOTTOM);
	labelCell.setBorderWidth(1f);

	PdfPCell nameCell = new PdfPCell(new Phrase(datumString, footerFont));
	nameCell.setBorder(Rectangle.BOTTOM);
	nameCell.setBorderWidth(1f);
	
	PdfPTable table = new PdfPTable(2);
	table.setHorizontalAlignment(Element.ALIGN_LEFT);
	table.setWidthPercentage(100f);
	table.addCell(labelCell);
	table.addCell(nameCell);
	table.setWidths(new float[] {0.3f, 0.7f});
	return table;
}
 
Example 33
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException {
	PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont));
	leftCell.setBorder(Rectangle.NO_BORDER);
	leftCell.setBorderWidth(1f);
	
	PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont));
	centerCell.setBorder(Rectangle.NO_BORDER);
	centerCell.setBorderWidth(1f);
	centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

	PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont));
	rightCell.setBorder(Rectangle.NO_BORDER);
	rightCell.setBorderWidth(1f);
	
	PdfPTable table = new PdfPTable(3);
	table.setHorizontalAlignment(Element.ALIGN_MIDDLE);
	table.setWidthPercentage(100f);
	table.addCell(leftCell);
	table.addCell(centerCell);
	table.addCell(rightCell);
	table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
	return table;
}
 
Example 34
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterUnterschriftenLine(Font footerFont) throws DocumentException {
	PdfPCell leftCell = new PdfPCell(new Phrase("Schulleiter(in)", footerFont));
	leftCell.setBorder(Rectangle.TOP);
	leftCell.setBorderWidth(1f);
	leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
	centerCell.setBorder(Rectangle.TOP);
	centerCell.setBorderWidth(1f);
	centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

	PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont));
	rightCell.setBorder(Rectangle.TOP);
	rightCell.setBorderWidth(1f);
	rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100f);
	table.addCell(leftCell);
	table.addCell(centerCell);
	table.addCell(rightCell);
	table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
	return table;
}
 
Example 35
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterHalbjahrDatumLine(String datumString, Font footerFont) throws DocumentException {
	PdfPCell leftCell = new PdfPCell(new Phrase(datumString, footerFont));
	leftCell.setBorder(Rectangle.NO_BORDER);
	leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
	centerCell.setBorder(Rectangle.NO_BORDER);
	centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

	PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont));
	rightCell.setBorder(Rectangle.NO_BORDER);
	rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100f);
	table.addCell(leftCell);
	table.addCell(centerCell);
	table.addCell(rightCell);
	table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
	return table;
}
 
Example 36
Project: rolp   File: PdfFormatHelper.java   Source Code and License 6 votes vote down vote up
public static PdfPTable buildFooterHalbjahrDatumKlassenleiterLine(Font footerFont) throws DocumentException {
	PdfPCell leftCell = new PdfPCell(new Phrase("Datum", footerFont));
	leftCell.setBorder(Rectangle.TOP);
	leftCell.setBorderWidth(1f);
	leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
	centerCell.setBorder(Rectangle.TOP);
	centerCell.setBorderWidth(1f);
	centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

	PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont));
	rightCell.setBorder(Rectangle.TOP);
	rightCell.setBorderWidth(1f);
	rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100f);
	table.addCell(leftCell);
	table.addCell(centerCell);
	table.addCell(rightCell);
	table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
	return table;
}
 
Example 37
Project: gutenberg   File: Styles.java   Source Code and License 6 votes vote down vote up
public Styles initDefaults() {
    FontDescriptor defaultFont = fontDescriptor(defaultFontName(), defaultFontSize(), Font.NORMAL, BaseColor.BLACK);

    registeredColors.put(DEFAULT_COLOR, BaseColor.BLACK);
    registeredFonts.put(DEFAULT_FONT, defaultFont);

    registeredFonts.put(CODE_FONT, fontDescriptor(verbatimBaseFont(), defaultFontSize(), Font.NORMAL, BaseColor.BLACK));
    registeredFonts.put(INLINE_CODE_FONT, fontDescriptor(verbatimBaseFont(), defaultFontSize(), Font.NORMAL, BaseColor.BLACK));
    registeredColors.put(INLINE_CODE_BACKGROUND, Colors.VERY2_LIGHT_GRAY);

    registeredFonts.put(H1_FONT, fontDescriptor(defaultFontName(), 18.0f, Font.BOLD, BaseColor.BLACK));
    registeredFonts.put(H2_FONT, fontDescriptor(defaultFontName(), 16.0f, Font.BOLD, BaseColor.DARK_GRAY));
    registeredFonts.put(H3_FONT, fontDescriptor(defaultFontName(), 14.0f, Font.BOLD, BaseColor.DARK_GRAY));
    registeredFonts.put(H4_FONT, fontDescriptor(defaultFontName(), 14.0f, Font.ITALIC, BaseColor.DARK_GRAY));

    registeredColors.put(TABLE_ALTERNATE_BACKGROUND, Colors.VERY2_LIGHT_GRAY);
    registeredFonts.put(TABLE_HEADER_FONT, fontDescriptor(defaultFontName(), 14.0f, Font.ITALIC, BaseColor.WHITE));
    registeredColors.put(TABLE_HEADER_BACKGROUD, BaseColor.BLACK);
    registeredFonts.put(TABLE_BODY_FONT, defaultFont);
    registeredColors.put(TABLE_BODY_CELL_BORDER_COLOR, Colors.LIGHT_GRAY);

    registeredColors.put(BLOCKQUOTE_COLOR, Colors.LIGHT_GRAY);

    return this;
}
 
Example 38
Project: gutenberg   File: HeaderFooter.java   Source Code and License 6 votes vote down vote up
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (pageInfos.getRawPageNumber() == 1 && !footerOnFirstPage)
        return;

    if (drawLine) {
        BaseColor lineColor = styles.getColorOrDefault(HEADER_LINE_COLOR);
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText(pageInfos);
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Font footerFont = styles.getFontOrDefault(FOOTER_FONT);

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
 
Example 39
Project: gutenberg   File: ExpLinkNodeProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void process(int level, Node node, InvocationContext context) {
    ExpLinkNode linkNode = (ExpLinkNode) node;
    String url = context.variableResolver().resolve(linkNode.url);

    Font anchorFont = new FontCopier(context.peekFont())
            .style(Font.UNDERLINE)
            .color(Colors.DARK_RED)
            .get();

    context.pushFont(anchorFont);
    List<Element> subs = context.collectChildren(level, node);
    context.popFont();

    Phrase p = new Phrase();
    p.addAll(subs);

    Anchor anchor = new Anchor(p);
    anchor.setReference(url);
    context.append(anchor);
}
 
Example 40
Project: gutenberg   File: HeaderNodeProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public void process(int level, Node node, InvocationContext context) {
    HeaderNode hNode = (HeaderNode) node;
    int hLevel = hNode.getLevel();

    Sections sections = context.iTextContext().sections();

    Font font = sections.sectionTitlePrimaryFont(hLevel);
    context.pushFont(font);
    List<Element> subs = context.collectChildren(level, node);
    context.popFont();

    Paragraph p = new Paragraph();
    p.setFont(font);
    p.addAll(subs);

    Element element = sections.newSection(p, hLevel);
    context.append(element);
}