Forum Stats

  • 3,853,774 Users
  • 2,264,266 Discussions
  • 7,905,444 Comments

Discussions

How Assign font to some texts through iText1.3

Hello Experts,
I am writing a following progarm to create a PDF. It is creating successfully with other fonts. And now i want to assign a different font i.e. Shivaji01 font but Its gives error like "Shivaji01" not found or as like this. Is there any method to store a font in that and then will use in our program. Or any different way.
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Font;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class GeneratePDF
{
	public BaseFont helv;

	public static void main(String[] args)
	{
		try
		{
			OutputStream file = new FileOutputStream(new File("C:\\Test.pdf"));
			Document document = new Document();
			PdfWriter.getInstance(document, file);
			document.open();
			document.add(new Paragraph("Hello .."));
			document.add(new Paragraph(new Date().toString()));

			/*BaseFont bfmarathi = BaseFont.createFont("Shivaji01", BaseFont.CP1252,BaseFont.EMBEDDED);
			Font font = new Font(bfmarathi, 14);

			document.add(new Paragraph("maI yaa p`maaNap~avdaro ASaI hmaI dotao kI sana ",font));*/

			Font f = new Font(Font.COURIER);
			document.add(new Paragraph("ssssssss",f));

			document.close();
			file.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

 }
Please help me out.
This discussion has been closed.