How to Set the Font Name, Size, Style and Colour In Pdf using itext in java


In this core java tutorial we will learn How to Set the Font Name, Size, Style and Colour In Pdf using itext in java using iText library - in Java with program and examples.


Create Chunk In Pdf in java - iText java tutorial program

how to Create Paragraph In Pdf - iText java tutorial program

Create Left, center and right aligned Paragraph In Pdf - iText java tutorial

How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial

Convert Html To Pdf in java using iText - iText java tutorial

How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial




Download all jars required to execute program >

Or, you may download jars from here


Program/Example to How to Set the Font Name, Size, Style and Colour In Pdf using itext in java - Using iText library - core java tutorial

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* Set the Font Name, Size, Style and Colour In Pdf
* Using the Itext Example - iText library - core java tutorial
*
*/
public class FontNameSizeStyleColourInPdfUsingItextExample {
   public static void main(String[] args) {
          try {
                 String pdfFilePath = "e:/Font Name Size Style Colour of font - in Pdf Using Itext Example.pdf";
                 OutputStream fos = new FileOutputStream(new File(pdfFilePath));
                 Document document = new Document();
                                    
                 PdfWriter.getInstance(document, fos);
                 document.open();
             //FONT NAME
                 Font fontname_Times =  FontFactory.getFont(FontFactory.TIMES);
                 Font fontname_Helvetica =  FontFactory.getFont(FontFactory.HELVETICA);
                 Font fontname_Courier =  FontFactory.getFont(FontFactory.COURIER);
                 Font fontname_ZapfDingbats =  FontFactory.getFont(FontFactory.ZAPFDINGBATS);
                 document.add(new Paragraph("This is fontname_Times", fontname_Times));
                 //FONT SIZE
                 Font fontSize_10 =  FontFactory.getFont(FontFactory.TIMES, 10f);
                 Font fontSize_12 =  FontFactory.getFont(FontFactory.TIMES, 12f);
                 Font fontSize_14 =  FontFactory.getFont(FontFactory.TIMES, 14f);
                 Font fontSize_16 =  FontFactory.getFont(FontFactory.TIMES, 16f);
                 document.add(new Paragraph("This is fontSize_16", fontSize_16));
                 //FONT STYLE
                 Font fontStyle_Normal =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.NORMAL);
                 Font fontStyle_Bold =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.BOLD);
                 Font fontStyle_Italic =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.ITALIC);
             Font fontStyle_Underline =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.UNDERLINE);
                 document.add(new Paragraph("This is fontStyle_Underline", fontStyle_Underline));
                 //FONT COLOUR - color
                 Font fontColour_Red =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.BOLD, BaseColor.RED);
                 Font fontColour_Yellow =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.BOLD, BaseColor.YELLOW);
                 Font fontColour_Blue =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.BOLD, BaseColor.BLUE);
                 Font fontColour_Green =  FontFactory.getFont(FontFactory.TIMES, 10f, Font.BOLD, BaseColor.GREEN);
                 document.add(new Paragraph("This is fontColour_Red", fontColour_Red));
                 document.close(); //close document
                 fos.close();
                
                 System.out.println("PDF created in >> "+ pdfFilePath);
          } catch (Exception e) {
                 e.printStackTrace();
          }
   }
}
/* Output of above program
PDF created in >> e:/Font Name Size Style Colour of font - in Pdf Using Itext Example.pdf
*/


PDF formed after executing above java program (How to Set the Font Name, Size, Style and Colour In Pdf using itext in java) will look like this >

Summary -

So in this core java tutorial we learned How to Set the Font Name, Size, Style and Colour In Pdf using itext in java using iText library - in Java with program and examples.





Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

References >



RELATED LINKS>

iText library tutorial in java - How to Create and work with PDF files in java


Creating IMAGES in pdf in java - iText tutorial >

Adding the Images In Pdf in java example using iText - iText java tutorial

How to Add And Rotate Images In Pdf in java - iText java tutorial example

How can you Add the Images from URL In Pdf in java program





Adding WATERMARK in pdf in java - iText tutorial >

How to add TEXT as Watermark In Pdf in java - iText java tutorial

How to add IMAGE as Watermark In Pdf in iText in java example



Creating CHAPTER, SECTION, CHUNK, PARAGRAPH AND PHRASE in pdf in java - iText tutorial >

Create Chapter And Section In Pdf in java - iText java tutorial

Create Chunk In Pdf in java - iText java tutorial program

how to Create Paragraph In Pdf - iText java tutorial program

Create Left, center and right aligned Paragraph In Pdf - iText java tutorial

Create Phrase In Pdf (with lead) Using Itext - iText java tutorial example



Set FONT NAME, SIZE, STYLE, COLOUR in pdf in java - iText tutorial >

How to Set the Font Name, Size, Style and Colour In Pdf using itext in java


Create ANCHOR (HYPERLINK), SUPERSCRIPT, SUBSCRIPT, UNDERLINE AND STRIKETHROUGH in pdf in java - iText tutorial >

How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial

How To Set SuperScript And SubScript In Pdf in java - iText java tutorial

UnderLine Text In Pdf in java - iText java tutorial example

Strikethrough Text In Pdf in java - iText java tutorial program


HTML to PDF in java - iText tutorial >

Convert Html To Pdf in java using iText - iText java tutorial


Create new page, set page height and width in java - iText tutorial >

How To Create New Pages In Pdf Using Itext - iText java tutorial example

How to Find Pdf Page Height And Width in java - iText java tutorial program



HEADER and FOOTER in pdf in java - iText tutorial >

How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial



BAR AND PIE CHARTS in pdf in java - iText tutorial >

How to create Bar Chart In Pdf in java - iText java tutorial

Create Pie Chart In Pdf in java using itext - iText java tutorial



MODIFY/ EDIT pdf in java - iText tutorial >

How to Modify - Add Text To Existing PDF in java - iText java tutorial example

How To Read And Add Image To Existing Pdf in java Example - iText java tutorial



Solve common Exceptions in itext in java - iText tutorial >

How to solve the Document Has No Pages IOException in iText in java


Alternates to itext in java - iText tutorial >

What are alternatives to iText library for creating Pdf in java?




No comments:

Post a Comment