True Type Fonts and Custom Fonts (Fixed)


#1

Hi all,

1. Please check the latest hot fix to support custom fonts in your pdf documents.

2. Like all other features of Aspose.Pdf, custom fonts can be used in XML, API or combined XML and API. Click this link to retrieve the latest xml schema. Currently, a new API Reference is not yet available since we’re enhancing xml examples for each class. Please consult the examples below to use custom fonts in your vb/c# code.

3. We use Jonathan Paterson’s Pipe-Dream font to demostrate how to use custom fonts. Below are the examples in Xml, Visual Basic and C#. Please note:

(1). For TrueType fonts, although it is not necessary to assign FontOutlineFile, you need to make sure the necessary TrueType fonts are installed on the machine you are using to create your Pdf documents. To assign the “FontName”, choose the Family Name when you double click the TrueType font in the Fonts of the Control Panel (instead of the Full Name displayed at the first line). Generally each TrueType font has two versions: Bold and Italic. You can use “IsTrueTypeFontBold” and “IsTrueTypeFontItalic” to choose which version you want to use.

(2). For PostScript custom fonts, you need to assign either “FontAfmFile” or “FontPfmFile”. If both are assigned, AFM file will be evaluated first. Also you need to assign “FontEncoding” and “FontEncodingFile”. “FontEncodingFile” can be obtained from http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/ and http://www.unicode.org/Public/MAPPINGS/ISO8859/. Generally “FontEncoding” is the name of the “FontEncodingFile”, excluding the extension.

(3). Set “IsFontEmbedded” to True if you want to embed TrueType fonts or PostScript custom fonts into your pdf documents. For PostScript custom fonts, you need to set “FontOutlineFile”.


[Xml]
<?xml version="1.0" encoding="utf-8" ?>




this is text content



<Segment FontSize=“20” FontName=“Arial Narrow”
IsTrueTypeFontBold=“true” IsTrueTypeFontItalic=“true”>
This is TrueType font ‘Arial Narrow Bold Italic’.



<Segment FontSize=“20” FontName=“Pipe-Dream” FontEncoding=“cp1250”
IsFontEmbedded=“true” FontAfmFile=“d:/fonts/PIPED___.AFM”
FontOutlineFile=“d:/fonts/PIPED___.PFB” FontEncodingFile=“d:/fonts/cp1250.txt”>
CUSTOM PIPE DREAM FONT





[Visual Basic]

Imports Aspose.Pdf

Public Class TextInfoExamples
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pdf As Pdf = New Pdf()

Dim section As Section = New Section(pdf)
pdf.Sections = New Sections()
pdf.Sections.Add(section)

Dim text1 As Text = New Text(section)
text1.Margin.Top = 30
text1.TextInfo.BackgroundColor = New Aspose.Pdf.Color()
text1.TextInfo.BackgroundColor.ColorSpaceType = ColorSpaceType.Rgb
text1.TextInfo.BackgroundColor.RgbColorSpace = System.Drawing.Color.Beige
section.Paragraphs = New Paragraphs()
section.Paragraphs.Add(text1)

Dim segment1 As Segment = New Segment(text1)
text1.Segments = New Segments()
text1.Segments.Add(segment1)
segment1.Content = “this is text content”
segment1.TextInfo.Alignment = AlignmentType.Center
Dim color1 As Aspose.Pdf.Color = New Aspose.Pdf.Color()
color1.ColorSpaceType = ColorSpaceType.Rgb
color1.RgbColorSpace = System.Drawing.Color.Red
segment1.TextInfo.Color = color1
segment1.TextInfo.FontSize = 16
segment1.TextInfo.IsUnderline = True

'TrueType font example
Dim text2 As Text = New Text(section)
text2.Margin.Top = 30
section.Paragraphs.Add(text2)

Dim segment2 As Segment = New Segment(text2)
text2.Segments = New Segments()
text2.Segments.Add(segment2)
segment2.Content = “This is TrueType font ‘Arial Narrow Bold Italic’.”
segment2.TextInfo.FontSize = 20
segment2.TextInfo.FontName = “Arial Narrow”
segment2.TextInfo.IsTrueTypeFontBold = True
segment2.TextInfo.IsTrueTypeFontItalic = True

'Embeded custom postscript font example
Dim text3 As Text = New Text(section)
text3.Margin.Top = 30
section.Paragraphs.Add(text3)

Dim segment3 As Segment = New Segment(text3)
text3.Segments = New Segments()
text3.Segments.Add(segment3)
segment3.Content = “CUSTOM PIPE DREAM FONT”
segment3.TextInfo.FontSize = 20
segment3.TextInfo.FontName = “Pipe-Dream”
segment3.TextInfo.FontAfmFile = “d:/fonts/PIPED___.AFM”
segment3.TextInfo.FontOutlineFile = “d:/fonts/PIPED___.PFB”
segment3.TextInfo.FontEncodingFile = “d:/fonts/cp1250.txt”
segment3.TextInfo.FontEncoding = “cp1250”
segment3.TextInfo.IsFontEmbedded = True

pdf.Save(Response)
Response.End()


End Sub

End Class


[C#]

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Aspose.Pdf;

namespace Examples_CS
{
///


/// Summary description for TextInfoExamples.
///

public class TextInfoExamples : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Pdf pdf = new Pdf();

Section section = new Section(pdf);
pdf.Sections = new Sections();
pdf.Sections.Add(section);

Text text1 = new Text(section);
text1.Margin.Top = 30;
text1.TextInfo.BackgroundColor = new Aspose.Pdf.Color();
text1.TextInfo.BackgroundColor.ColorSpaceType = ColorSpaceType.Rgb;
text1.TextInfo.BackgroundColor.RgbColorSpace = System.Drawing.Color.Beige;
section.Paragraphs = new Paragraphs();
section.Paragraphs.Add(text1);

Segment segment1 = new Segment(text1);
text1.Segments = new Segments();
text1.Segments.Add(segment1);
segment1.Content = “this is text content”;
segment1.TextInfo.Alignment = AlignmentType.Center;
Aspose.Pdf.Color color1 = new Aspose.Pdf.Color();
color1.ColorSpaceType = ColorSpaceType.Rgb;
color1.RgbColorSpace = System.Drawing.Color.Red;
segment1.TextInfo.Color = color1;
segment1.TextInfo.FontSize = 16;
segment1.TextInfo.IsUnderline = true;

//TrueType font example
Text text2 = new Text(section);
text2.Margin.Top = 30;
section.Paragraphs.Add(text2);

Segment segment2 = new Segment(text2);
text2.Segments = new Segments();
text2.Segments.Add(segment2);
segment2.Content = “This is TrueType font ‘Arial Narrow Bold Italic’.”;
segment2.TextInfo.FontSize = 20;
segment2.TextInfo.FontName = “Arial Narrow”;
segment2.TextInfo.IsTrueTypeFontBold = true;
segment2.TextInfo.IsTrueTypeFontItalic = true;

//Embeded custom postscript font example
Text text3 = new Text(section);
text3.Margin.Top = 30;
section.Paragraphs.Add(text3);

Segment segment3 = new Segment(text3);
text3.Segments = new Segments();
text3.Segments.Add(segment3);
segment3.Content = “CUSTOM PIPE DREAM FONT”;
segment3.TextInfo.FontSize = 20;
segment3.TextInfo.FontName = “Pipe-Dream”;
segment3.TextInfo.FontAfmFile = “d:/fonts/PIPED___.AFM”;
segment3.TextInfo.FontOutlineFile = “d:/fonts/PIPED___.PFB”;
segment3.TextInfo.FontEncodingFile = “d:/fonts/cp1250.txt”;
segment3.TextInfo.FontEncoding = “cp1250”;
segment3.TextInfo.IsFontEmbedded = true;

pdf.Save(Response);
Response.End();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}