Aspose.Pdf

Use PostScript Type1 Fonts

Adobe's PostScript Type 1 fonts are stored in two common formats, .PFA (PostScript Font ASCII) and .PFB (PostScript Font Binary). These contain descriptions of the character shapes, with each character being generated by a small program that calls on other small programs to compute common parts of the characters in the font. In both cases, the character descriptions are encrypted.

 

Aspose.Pdf supports all common formats for PostScript Type1 fonts. Let's see in the below sub-topics that how Aspose.Pdf allows developers to use these fonts.

 

Font Metrics

 

In Aspose.Pdf , two types of font metrics are supported:

 

 

The TextInfo.FontAfmFile and TextInfo.FontPfmFile are used to set font metric files. It is not needed to set both font metrics, AFM and PFM together. If both are set, AFM will be used first. The following example shows how to use PFM.

 

Code Snippet

 

[C#]

 

//Create a text object in a section

Text t1 = new Aspose.Pdf.Text(sec1,"Arial Bold MT");

 

//Set the font name of a segment in the text object

t1.Segments[0].TextInfo.FontName = "Arial-BoldMT";

 

//Set the PFM file for the text segment

t1.Segments[0].TextInfo.FontPfmFile = "_AB_____.PFM";

 

//Set the font encoding file for the text segment

t1.Segments[0].TextInfo.FontEncodingFile = @"CP1250.txt";

 

//Set the font encoding name of the text segment

t1.Segments[0].TextInfo.FontEncoding = "cp1250";

 

[VB.NET]

 

'Create a text object in a section

Dim t1 As Aspose.Pdf.Text = New Aspose.Pdf.Text(sec1, "Arial Bold MT")

 

'Set the font name of a segment in the text object

t1.Segments(0).TextInfo.FontName = "Arial-BoldMT"

 

'Set the PFM file for the text segment

t1.Segments(0).TextInfo.FontPfmFile = "Font\PFM\_AB_____.PFM"

 

'Set the font encoding file for the text segment

t1.Segments(0).TextInfo.FontEncodingFile = "CP1250.txt"

 

'Set the font encoding name of the text segment

t1.Segments(0).TextInfo.FontEncoding = "cp1250"  

 

[XML]

 

<Text>

    <Segment FontName="Arial-BoldMT" FontEncodingFile="CP1250.txt"

        FontPfmFile="_AB_____.PFM"         FontEncoding="cp1250">

                Arial Bold MT

    </Segment>

</Text>

 

Font Embedding and Font Outline

 

Aspose.Pdf also supports embedding font descriptions into the generated output PDF document. If a font is not embedded in a PDF document, Acrobat will take it from the operating system if available, or construct a substitute font according to the font descriptor in the PDF.

 

TextInfo.IsFontEmbedded is used to set Font Embedding. If the TextInfo.IsFontEmbedded is set to true then TextInfo.FontOutlineFile property must be set too. For the font outline information, platform-independent PFA (Printer Font ASCII) and the Windows-specific PFB (Printer Font Binary) formats are supported.

 

The following example shows how to embed font with PFB outline.

 

Code Snippet

 

[C#]

 

//Create a text object in a section

Text t1 = new Aspose.Pdf.Text(sec1,"Arial Bold MT");

 

//Set the font name of a segment in the text object

t1.Segments[0].TextInfo.FontName = "Arial-BoldMT";

 

//Set the PFM file for the text segment

t1.Segments[0].TextInfo.FontPfmFile = "_AB_____.PFM";

 

//Set the font encoding file for the text segment

t1.Segments[0].TextInfo.FontEncodingFile = "CP1250.txt";

 

//Set the font encoding name of the text segment

t1.Segments[0].TextInfo.FontEncoding = "cp1250";

 

//Set the font outline file for the text segment

t1.Segments[0].TextInfo.FontOutlineFile = "_AB_____.PFB";

 

//Set IsFontEmbedded to true

t1.Segments[0].TextInfo.IsFontEmbedded = true;

 

[VB.NET]

 

'Create a text object in a section

Dim t1 As Aspose.Pdf.Text = New Aspose.Pdf.Text(sec1, "Arial Bold MT")

 

'Set the font name of a segment in the text object

t1.Segments(0).TextInfo.FontName = "Arial-BoldMT"

 

'Set the PFM file for the text segment

t1.Segments(0).TextInfo.FontPfmFile = "_AB_____.PFM"

 

'Set the font encoding file for the text segment

t1.Segments(0).TextInfo.FontEncodingFile = "CP1250.txt"

 

'Set the font encoding name of the text segment

t1.Segments(0).TextInfo.FontEncoding = "cp1250"

 

'Set the font outline file for the text segment

t1.Segments[0].TextInfo.FontOutlineFile = "_AB_____.PFB"

 

'Set IsFontEmbedded to true

t1.Segments[0].TextInfo.IsFontEmbedded = true

 

[XML]

 

<Text>

    <Segment FontName="Arial-BoldMT" FontEncodingFile="CP1250.txt"

        FontPfmFile="_AB_____.PFM"         FontEncoding="cp1250"

        FontOutlineFile="_AB_____.PFB" IsFontEmbedded="true">

                Arial Bold MT

    </Segment>

</Text>

 

PostScript Font Names

 

When using PostScript fonts, you MUST set correct font name. If you don't know the exact font name, you should open the font metric or outline files with a text editer and find the font name. The following figures show how to find font name in AFM, PFB and PFB files:

 

 

Figure 1: Finding font name in AFM file

 

 

Figure 2: Finding font name in PFM file

 

 

Figure 3: Finding font name in PFB file

 

Note: PostScript font name may differ substantially from the Windows font menu name.