Embeds a font into the document.

 

   

Syntax
 

[C#]
int EmbedFont(string name)
int EmbedFont(string name, LanguageType language)
int EmbedFont(string name, LanguageType language, bool vertical)
int EmbedFont(string name, LanguageType language, bool vertical, bool subset)
int EmbedFont(string name, LanguageType language, bool vertical, bool subset, bool force)

[Visual Basic]
Function EmbedFont(name As String) As Integer
Function EmbedFont(name As String, language As LanguageType) As Integer
Function EmbedFont(name As String, language As LanguageType, vertical As Boolean) As Integer
Function EmbedFont(name As String, language As LanguageType, vertical As Boolean, subset As Boolean) As Integer
Function EmbedFont(name As String, language As LanguageType, vertical As Boolean, subset As Boolean, force As Boolean) As Integer

 

   

Params
 
Name Description
name The name of the font typeface.
language

The language type to use. The LanguageType enumeration may take the following values:

  • Latin
  • Unicode
  • Korean
  • Japanese
  • ChineseS
  • ChineseT

See the Fonts and Languages section for details on language types. The default language type is LanguageType.Latin.

vertical

Whether the text direction should be vertical.

See the Fonts and Languages section for details on writing directions. The default is false to indicate standard left to right layout.

subset

Whether to subset the font.

See the Fonts and Languages section for details on subsetting. The default is false to indicate that the font should not be subsetted.

force

Whether to override permissions on the font.

Fonts often contain embedded licensing information. By default ABCpdf will prevent you from embedding fonts which indicate that embedding is not permitted.

You can force the font to be embedded by passing true for this value.

return The Object ID of the newly embedded Font Object.

 

   

Notes
 

Embeds a font into the document.

The font name, a description of the font style and the the font glyph descriptions themselves are placed into the document. This ensures that the document will always display perfectly on every system and that font substitutions will never need to be made.

There are a number of reasons you may not wish to embed fonts and instead use the AddFont method. Embedding fonts can increase the size of your PDF considerably. Additionally by distributing a PDF with an embedded font you are actually redistributing the font itself. You should check with your font supplier or legal department that you have permission to do this.

For information on how to specify font names see the AddFont method.

The EmbedFont function returns the Object ID of the newly added Font Object. Typically you will want to assign this return value to the document Font property using code of the form.

theDoc.Font = theDoc.AddFont("Courier");

If the specified font could not be found then you will get an Object ID of zero returned. You may wish to check for this possibility otherwise a default font will be used.

Fonts are cached so newly added fonts will not be available to ABCpdf until the application is restarted. If you need to dynamically load a font you can pass this method a path to your font file. This will add the font to the cache and make it available for use. You should not move, rename or delete a font file which has been dynamically loaded using this technique.

Why is my language a string?

In older versions of ABCpdf the language parameter was a string. So you might find code of this form.

theDoc.EmbedFont("Courier", "Unicode")

In more recent releases the language parameter has been changed to a true enumeration. This is a safer way of coding as it allows the compiler to ensure that the values you are using are valid. Your new code should look like this.

theDoc.EmbedFont("Courier", LanguageType.Unicode)

The names of the items in the LanguageType enumeration are the same as the values of the strings used in previous versions. So changing your code should be a simple search and replace operation. If you see a language of "" this equates to LanguageType.Latin.

 

 

   

Example
 

The following code embeds the font 'Comic Sans MS' into the document and then adds some text.

[C#]
Doc theDoc = new Doc();
theDoc.FontSize = 216;
string theFont = "Comic Sans MS";
theDoc.Font = theDoc.EmbedFont(theFont);
theDoc.AddText(theFont);
theDoc.Save(Server.MapPath("docembedfont.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.FontSize = 216
Dim theFont As String = "Comic Sans MS"
theDoc.Font = theDoc.EmbedFont(theFont)
theDoc.AddText(theFont)
theDoc.Save(Server.MapPath("docembedfont.pdf"))
theDoc.Clear()


docembedfont.pdf