PDFOne (for Java)
Create, edit, view, print & enhance PDF documents and forms in Java SE/EE
J2SE J2EE Windows Linux Mac (OS X)

Using Fonts With PDFOne (for Java)

Learn about the many ways you can use fonts in PDF documents.
By V. Subhash

One of the things that have contributed greatly to the success of PDF is its support for fonts. Text on a PDF document looks a lot smooth and clean than on a Word document or a spreadsheet. Font support in PDF is a very big topic but here is the minimum you need to know if you are using a tool such as PDFOne.

Standard 14 Fonts

These are a set of standard "Type 1" fonts that you can use in any PDF document. You do not have to have these fonts installed in your computer nor do you have to embed them in the document. These fonts are variations of Helvetica, Times, Courier and some other fonts.

  1. Times−Roman
  2. Times−Bold
  3. Times−Italic
  4. Times−BoldItalic
  5. Helvetica
  6. Helvetica−Bold
  7. Helvetica−Oblique
  8. Helvetica−BoldOblique
  9. Courier
  10. Courier−Bold
  11. Courier−Oblique
  12. Courier−BoldOblique
  13. Symbol
  14. ZapfDingbats

You can use any of these fonts in a PDF document and never worry about fidelity on any platform or output medium. All PDF rendering applications will have built-in support for these fonts.

If you are using PDFOne, you can use these fonts in your PDF documents by creating a PdfFont object. When doing this, you need to refer to the name of the font exactly as listed above.

static void Demo_Standard_14_Fonts() throws IOException, PdfException {

   // Create "Standard Type 1" fonts objects
   PdfFont fntHelvetica = 
         PdfFont.create("Helvetica", 20, PdfEncodings.WINANSI);
   PdfFont fntTimesRoman = 
         PdfFont.create("Times-Roman", 20, PdfEncodings.WINANSI);
   PdfFont fntCourier = 
         PdfFont.create("Courier", 20, PdfEncodings.WINANSI);          
   PdfFont fntHelveticaBold = 
         PdfFont.create("Helvetica-Bold", 20, PdfEncodings.WINANSI);
   PdfFont fntTimesItalic = 
         PdfFont.create("Times-Italic", 20, PdfEncodings.WINANSI);
   PdfFont fntCourierBoldItalic = 
         PdfFont.create("Courier-BoldOblique", 20, PdfEncodings.WINANSI);          
   PdfFont fntSymbol = 
         PdfFont.create("Symbol", 20, PdfEncodings.WINANSI);
   PdfFont fntZapfDingbats = 
         PdfFont.create("ZapfDingbats", 20, PdfEncodings.WINANSI);
   // Create a new PDF document 
   PdfDocument doc = new PdfDocument();
   // Render text using the fonts
   doc.writeText("Helvetica", fntHelvetica, 100, 20);
   doc.writeText("Times", fntTimesRoman, 100, 50);
   doc.writeText("Courier", fntCourier, 100, 80);
   doc.writeText("Helvetica Bold", fntHelveticaBold, 100, 110);
   doc.writeText("Times Italic", fntTimesItalic, 100, 140);
   doc.writeText("Courier Bold Italic", fntCourierBoldItalic, 100, 170);
   doc.writeText("ABCDEFGabcdefg123456~!@#$%^&*()", fntSymbol, 50, 200);
   doc.writeText("ABCDEFGabcdefg123456~!@#$%^&*()", fntZapfDingbats, 50, 230);      

   // Save the document to file
   // Close the PDF document 

The above code snippet creates Standard 14 font objects

Non-Standard Fonts

Standard 14 fonts are okay for simple documents. If you are an graphic artist or even a simple office executive, you would want to use other great fonts that are available on your computer.

When using such non-standard fonts, you need to be sure if all end-users of the PDF document will have those fonts installed on their computer. If not, you may need to "embed" the fonts in the PDF document. Otherwise, the document will not be rendered exactly as you had intended it to.

You can embed PDF fonts in three ways - full embedding, subset embedding and no embedding. Full embedding will embed the entire font file in the PDF document. With subset embedding, only those glyphs that are used in the document are embedded in the PDF document. Ostensibly, subset embedding is the better option as you can economize on the file size. Full embedding can make PDF documents prohibitively heavy.

You can also take the other extreme option of not embedding the fonts. When these fonts are not installed, PDF rendering application will substitute with a standard font. Of course, fidelity will not be there in such cases.

When using PDFOne, you can specify the embedding option when you create the PDF font object.

static void Demo_Embedded_Fonts() throws IOException, PdfException {
   // Create font objects
   PdfFont fntGentium =    // Subset embedding 
      PdfFont.create("Input_Docs\\GenR102.TTF", 20, PdfEncodings.WINANSI, PdfFont.EMBED_SUBSET); 
   PdfFont fntGentiumItalic =    // Full embedding
      PdfFont.create("Input_Docs\\GenI102.TTF", 20, PdfEncodings.WINANSI, PdfFont.EMBED_FULL);  
   PdfFont fntCourierNew =    // No embedding 
      PdfFont.create("C:\\WINDOWS\\Fonts\\COUR.TTF", 20, PdfEncodings.WINANSI);
   // Open a PDF document 
   PdfDocument doc = new PdfDocument();
   // Render text using the fonts
   doc.writeText("Full Embedding (Gentium Regular)", fntGentium, 50, 50);       
   doc.writeText("Subset Embedding (Gentium Italic)", fntGentiumItalic, 50, 100);
   doc.writeText("No Embedding (Courier New Regular)", fntCourierNew, 50, 150);       

   // Save the document to file
   // Close the PDF document

In the above code snippet, we create three font objects. Gentium is a font that I am pretty sure is not pre-installed on all computers. So, we created a PDF font object for fully embedding and another one for subset embedding. The Courier New font object did not use embedding because almost all Windows computers have this font. (On a Linux or Mac computer, Courier New would have been substituted with a suitable font that is available on that computer.)

Non-standard fonts look fine so long as they are installed or embedded

You can use Adobe Reader's Document Property dialog (press Ctrl+D) to check how fonts are used in a PDF document.

Adobe Reader's Document Property dialog


Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.