Lasso Soft Inc. > Home

  • Articles

Using Fonts in PDFs

The tip of the week from March 9, 2007 includes a discussion of how to use fonts when creating PDF files through Lasso. The tip includes information about built-in fonts, True Type fonts, and conversion utilities which can be used for other font types.

Introduction

PDF files created through Lasso can use any True Type fonts which are available on your system in addition to the fonts that are built-in to Acrobat. This tip includes instructions for locating and using True Type fonts with the [PDF_Font] tag and also includes instructions for converting Macintosh dfont files to True Type so you can use them in your PDF files.

Important - This tip includes information about a font conversion utility which can unpack a dfont file into individual True Type font files. You should consult with the license for your fonts to see whether this type of conversion is allowed.

Built-In Fonts

Acrobat and most PDF readers include five built-in fonts. These fonts do not need to be embedded into PDF files that you generated. Using these fonts can decrease the size of your PDF file. Unless you need to use a specific font you should consider using one of the built-in fonts.

The built-in fonts include the following fonts and styles:

Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique

Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique

Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic

Symbol

ZapfDingbats

These fonts can be named directly in the [PDF_Font] tag's -Face parameter. The font can then be used in one or more [PDF_Text] objects.

For example, the following code creates a [PDF_Font] object for Times-Bold and stores it in a variable named $myTimesBoldFont. This variable is then used to add some text to a PDF.

[Var: 'myTimesBoldFont' = (PDF_Font: -Face='Times-Bold')]

[Var: 'myPDF' = (PDF_Doc: -Size='letter')]

[$myPDF->(Add: (PDF_Text: 'The quick brown fox', -Font=$myTimesBoldFont))]

[$myPDF->Close]

[PDF_Serve: $myPDF, -Inline]

Note - These "built-in" fonts many not literally be included with a PDF reader. However, the reader should ensure that these fonts are rendered using an equivalent font if the particular font is not available.

True Type Fonts

True type fonts can be used by specifying the path to a .ttf file in the -File parameter of the [PDF_Font] object. Fonts can be read directly from the system Fonts folder by specifying the full path to a font file.

Note - The PDF library used with Lasso is compatible with most True Type fonts. However, you should check each font that you want to use to make sure that you don't encounter an error. Some True Type fonts include a flag which will not allow them to be embedded in a PDF.

For example, the following code creates a [PDF_Font] object for Chalkboard on Mac OS X and stores it in a variable named $myChalkboardFont. This variable is then used to add some text to a PDF.

[Var: 'myChalkboardFont' = (PDF_Font: -File='///Library/Fonts/Chalkboard.ttf')]

[Var: 'myPDF' = (PDF_Doc: -Size='letter')]

[$myPDF->(Add: (PDF_Text: 'The quick brown fox', -Font=$myChalkboardFont))]

[$myPDF->Close]

[PDF_Serve: $myPDF, -Inline]

The following code creates a [PDF_Font] object for the Comic Sans font on Windows and stores it in a variable named $myComicFont. This variable is then used to add some text to a PDF.

[Var: 'myComicFont' = (PDF_Font: -File='C://WINDOWS/Fonts/comic.ttf')]

[Var: 'myPDF' = (PDF_Doc: -Size='letter')]

[$myPDF->(Add: (PDF_Text: 'The quick brown fox', -Font=$myComicFont))]

[$myPDF->Close]

[PDF_Serve: $myPDF, -Inline]

Accessing fonts out of the Web server roots requires that Lasso's built-in file permissions be configured. It may be easier to copy .ttf files that you intend to use through Lasso into your Web server root, e.g. into a /Fonts/ folder. These fonts can then be specified using an absolute path.

For example, if the Chalkboard.ttf file was copied into a /Fonts/ folder in the Web server root then the following code could be used to create a PDF file using that font.

[Var: 'myChalkboardFont' = (PDF_Font: -File='/Fonts/Chalkboard.ttf')]

[Var: 'myPDF' = (PDF_Doc: -Size='letter')]

[$myPDF->(Add: (PDF_Text: 'The quick brown fox', -Font=$myChalkboardFont))]

[$myPDF->Close]

[PDF_Serve: $myPDF, -Inline]

Open Type Fonts

Since this tip has been written I have been informed that users have also successfully used Open type fonts with Lasso. Open type fonts can be used by specifying the path to a .otf file in the -File parameter of the [PDF_Font] object. Fonts can be read directly from the system Fonts folder by specifying the full path to a font file.

Note - The PDF library used with Lasso should be compatible with most Open Type fonts. However, you should check each font that you want to use to make sure that you don't encounter an error. Some Open Type fonts include a flag which will not allow them to be embedded in a PDF.

Other Files

Mac OS X includes many fonts in dfont format. This file type is used as a wrapper around many different font formats including True Type. Lasso cannot use a dfont file directly, but can use any True Type fonts which are embedded within. A utility like "fondu" or Extensis FontDoctor can pull the True Type fonts out of a dfont file. Once the .ttf files have been extracted they can be used like any True Type fonts.

Fondu is free and can be found at the following URL. The Mac OS/X package in the downloads section includes a Mac OS X installer for all the command line utilities included in the package.

Once fondu has been installed the following commands will extract all of the fonts from all the dfont files in the standard system Fonts folder.

mkdir /Library/WebServer/Documents/Fonts

cd /Library/WebServer/Documents/Fonts

/usr/local/bin/fondu /Library/Fonts/*.dfont

It might be possible to use other font files with Lasso's PDF tags provided those files can be converted to True Type format.

Important - You should consult with the license for your fonts to see whether this type of conversion is allowed.

More Information

More information about all of the tags used in this example can be found in the Lasso 8.5 Language Guide or in the online Lasso Reference .
 

Author: Fletcher Sandbeck
Created: 30 Nov 2007
Last Modified: 16 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft