Class PdfFontCollection
Namespace: IronPdf.Fonts
Assembly: IronPdf.dll
Syntax
public class PdfFontCollection : PdfClientAccessor, IPdfFontCollection
Properties
Count
Gets the total number of fonts referenced inside the PDF document.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 | Number of fonts referenced inside the PDF document |
Item[String]
Declaration
public IEnumerable<FontInfo> this[string fontName] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | fontName |
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<FontInfo> |
Item[UInt32]
Declaration
public FontInfo this[uint objNum] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | objNum |
Property Value
Type | Description |
---|---|
FontInfo |
Items
Gets a copy of System.Collections.Generic.List<> of FontInfo from the underlying PDF document.
Declaration
public List<FontInfo> Items { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<FontInfo> | System.Collections.Generic.List<> of FontInfo as a copy from the backing collection. |
ItemsReadOnly
Gets System.Collections.ObjectModel.ReadOnlyCollection<> whose elements are as of FontInfo from a backing collection.
Declaration
public ReadOnlyCollection<FontInfo> ItemsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<FontInfo> | System.Collections.ObjectModel.ReadOnlyCollection<> whose elements are as of FontInfo directly referenced from the backing collection. Thus returned collection reflects changes if the backing collection changed |
Methods
Add(StandardFont)
Adds a font into a PDF document from the specified standard font enumeration
Declaration
public FontInfo Add(StandardFont font)
Parameters
Type | Name | Description |
---|---|---|
StandardFont | font | Standard font enuemration StandardFont |
Returns
Type | Description |
---|---|
FontInfo | FontInfo if succeed, otherwise exception thrown. |
Add(Byte[], UInt32)
Adds, and embeds a font into a PDF document from the specified font's byte array.
Declaration
public FontInfo Add(byte[] fontData, uint size)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | fontData | Font data in byte array |
System.UInt32 | size | Size in bytes of font's byte array data |
Returns
Type | Description |
---|---|
FontInfo | FontInfo if succeed, otherwise exception thrown. |
Add(Stream)
Adds, and embeds a font into a PDF document from the specified font's System.IO.Stream.
Declaration
public FontInfo Add(Stream fontStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | Font stream |
Returns
Type | Description |
---|---|
FontInfo | FontInfo if succeed, otherwise exception thrown. |
Add(String)
Adds a font into a PDF document from the specified standard font name.
Declaration
public FontInfo Add(string standardFontName)
Parameters
Type | Name | Description |
---|---|---|
System.String | standardFontName | Standard font name |
Returns
Type | Description |
---|---|
FontInfo | FontInfo if succeed, otherwise an exception thrown. |
AddFromFilePath(String)
Adds, and embeds a font into a PDF document from the specified font's filepath.
Declaration
public FontInfo AddFromFilePath(string fontFilePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | fontFilePath | Font filepath |
Returns
Type | Description |
---|---|
FontInfo | FontInfo if succeed, otherwise exception thrown. |
Embed(FontInfo, Byte[], UInt32)
Embeds a font with the font's langword_csharp_byte[].
Declaration
public FontInfo Embed(FontInfo font, byte[] fontData, uint size)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | font | Target font to embed |
System.Byte[] | fontData | Font's data as byte array |
System.UInt32 | size | Size in byte of the byte array |
Returns
Type | Description |
---|---|
FontInfo | FontInfo object just embedded if succeed, otherwise an exception thrown. |
Remarks
This requires that there is an existing font referenced which used as a target in order to successfully embed a font.
Embed(FontInfo, Stream)
Embeds a font with the font's System.IO.Stream.
Declaration
public FontInfo Embed(FontInfo font, Stream fontStream)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | font | Target font to embed |
System.IO.Stream | fontStream | Font stream |
Returns
Type | Description |
---|---|
FontInfo | FontInfo object just embedded if succeed, otherwise an exception thrown. |
Remarks
This requires that there is an existing font referenced which used as a target in order to successfully embed a font.
Embed(FontInfo, String)
Embeds a font with the font's filepath.
Declaration
public FontInfo Embed(FontInfo font, string path)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | font | Target FontInfo to embed |
System.String | path | Font's filepath for using as a font data to embed |
Returns
Type | Description |
---|---|
FontInfo | FontInfo object just embedded if succeed, otherwise an exception thrown. |
Remarks
This requires that there is an existing font referenced which used as a target in order to successfully embed a font.
Find(String)
Declaration
public List<FontInfo> Find(string regexFontName)
Parameters
Type | Name | Description |
---|---|---|
System.String | regexFontName |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<FontInfo> |
GetEnumerator()
Gets System.Collections.Generic.IEnumerator<>System.Collections.Generic.List<>.
Declaration
public IEnumerator<FontInfo> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<FontInfo> |
GetStandardFontName(StandardFont)
Gets a direct mapping of standard font name from the specified StandardFont.
Declaration
public string GetStandardFontName(StandardFont font)
Parameters
Type | Name | Description |
---|---|---|
StandardFont | font | Font enumeration as of type StandardFont. |
Returns
Type | Description |
---|---|
System.String | Always correct standard font name. Returned value won't never be null. |
Replace(FontInfo, StandardFont)
Replaces a font referenced from a PDF document with the specified StandardFont. Supports replacing a target font which is either a simple font, or a composite font.
Declaration
public FontInfo Replace(FontInfo targetFont, StandardFont newFont)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | targetFont | Target FontInfo to replace |
StandardFont | newFont | StandardFont representing a standard font used to replace the target font |
Returns
Type | Description |
---|---|
FontInfo | FontInfo representing a replaced font if succeed, otherwise an exception thrown. |
Remarks
This method won't embed the font.
Replace(FontInfo, Byte[], UInt32)
Replaces a font referenced from a PDF document with the specified font's langword_csharp_byte[]. Supports replacing a target font which is either a simple font, or a composite font.
Declaration
public FontInfo Replace(FontInfo targetFont, byte[] newFontData, uint size)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | targetFont | Target FontInfo to replace |
System.Byte[] | newFontData | Font's filepath as langword_csharp_byte[] |
System.UInt32 | size | Size in bytes for the font data |
Returns
Type | Description |
---|---|
FontInfo | FontInfo representing a replaced font if succeed, otherwise an exception thrown. |
Remarks
This method will also embed the font into a PDF document.
Replace(FontInfo, Stream)
Replaces a font referenced from a PDF document with the specified font's System.IO.Stream. Supports replacing a target font which is either a simple font, or a composite font.
Declaration
public FontInfo Replace(FontInfo targetFont, Stream newFontStream)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | targetFont | Target FontInfo to replace |
System.IO.Stream | newFontStream | Font's System.IO.Stream |
Returns
Type | Description |
---|---|
FontInfo | FontInfo representing a replaced font if succeed, otherwise an exception thrown. |
Remarks
This method will also embed the font into a PDF document.
Replace(FontInfo, String)
Replaces a font referenced from a PDF document with the specified standard font name. Supports replacing a target font which is either a simple font, or a composite font.
Declaration
public FontInfo Replace(FontInfo targetFont, string newFontName)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | targetFont | Target FontInfo to replace |
System.String | newFontName | Standard font name which will be used to replace the target font |
Returns
Type | Description |
---|---|
FontInfo | FontInfo representing a replaced font if succeed, otherwise an exception thrown. |
Remarks
This method won't embed the font.
ReplaceFromFilePath(FontInfo, String)
Replaces a font referenced from a PDF document with the specified font's filepath. Supports replacing a target font which is either a simple font, or a composite font.
Declaration
public FontInfo ReplaceFromFilePath(FontInfo targetFont, string path)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | targetFont | Target FontInfo to replace |
System.String | path | Font's filepath |
Returns
Type | Description |
---|---|
FontInfo | FontInfo representing a replaced font if succeed, otherwise an exception thrown. |
Remarks
This method will also embed the font into a PDF document.
ResolveStandardFontName(String)
Resolves a standard font name from the arbitrary standard font name that user expects to use.
Declaration
public string ResolveStandardFontName(string arbitraryStandardFontName)
Parameters
Type | Name | Description |
---|---|---|
System.String | arbitraryStandardFontName | Expected to use standard font name string |
Returns
Type | Description |
---|---|
System.String | Resolved standard font name, or null if it cannot resolve to the correct one. |
Remarks
There are 14 Standard fonts that are guaranteed to be available when working with any PDF document via any PDF document reader tools.
UnEmbed(FontInfo)
UnEmbeds a font from the font object.
Declaration
public FontInfo UnEmbed(FontInfo font)
Parameters
Type | Name | Description |
---|---|---|
FontInfo | font | Font object to un-embed |
Returns
Type | Description |
---|---|
FontInfo | FontInfo just un-embedded if succeed, otherwise an exception thrown. |
Remarks
UnEmbeds a font means that its font content would be deleted from the PDF document, but the other data structure or information of the font itself is still there. Uses this method to reduce file size of PDF document.
UnEmbed(String)
UnEmbeds a font from the regular expression string matching a font name. It will only perform on the first match.
Declaration
public FontInfo UnEmbed(string regexFontName)
Parameters
Type | Name | Description |
---|---|---|
System.String | regexFontName | Regular expression string matching a font name |
Returns
Type | Description |
---|---|
FontInfo | FontInfo just un-embedded if succeed, otherwise an exception thrown. |
Remarks
This method is mostly useful if font names are mostly unique within the PDF document. Alternatively use Find(String).
UnEmbeds a font means that its font content would be deleted from the PDF document, but the other data structure or information of the font itself is still there. Uses this method to reduce file size of PDF document.