OpenFont
内容
[
隐藏
]OpenFont(Stream, FontTypes)
使用指定的字体流打开字体。
public static Font OpenFont(Stream fontStream, FontTypes fontType)
范围 | 类型 | 描述 |
---|---|---|
fontStream | Stream | 字体流。 |
fontType | FontTypes | 字体类型值。 |
返回值
字体对象。
例子
示例演示如何打开字体并替换第一页文本的字体。
// 打开字体
using (FileStream fontStream = File.OpenRead(@"C:\WINDOWS\Fonts\arial.ttf"))
{
Font font = FontRepository.OpenFont(fontStream, , FontTypes.TTF);
// 打开文档
Document doc = new Document(@"D:\Tests\input.pdf");
// 创建 TextFragmentAbsorber 对象以查找所有“hello world”文本出现
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
// 接受第一页的吸收器
doc.Pages[1].Accept(absorber);
// 更改第一个文本出现的字体
absorber.TextFragments[1].TextState.Font = font;
// 保存文档
doc.Save(@"D:\Tests\output.pdf");
}
也可以看看
- class Font
- enum FontTypes
- class FontRepository
- 命名空间 Aspose.Pdf.Text
- 部件 Aspose.PDF
OpenFont(string)
使用指定的字体文件路径打开字体。
public static Font OpenFont(string fontFilePath)
范围 | 类型 | 描述 |
---|---|---|
fontFilePath | String | 字体文件路径。 |
返回值
字体对象。
例子
示例演示如何打开字体并替换第一页文本的字体。
// 打开字体
Font font = FontRepository.OpenFont(@"C:\WINDOWS\Fonts\arial.ttf");
// 打开文档
Document doc = new Document(@"D:\Tests\input.pdf");
// 创建 TextFragmentAbsorber 对象以查找所有“hello world”文本出现
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
// 接受第一页的吸收器
doc.Pages[1].Accept(absorber);
// 更改第一个文本出现的字体
absorber.TextFragments[1].TextState.Font = font;
// 保存文档
doc.Save(@"D:\Tests\output.pdf");
也可以看看
- class Font
- class FontRepository
- 命名空间 Aspose.Pdf.Text
- 部件 Aspose.PDF
OpenFont(string, string)
使用指定的字体文件路径和度量文件路径打开字体。
public static Font OpenFont(string fontFilePath, string metricsFilePath)
范围 | 类型 | 描述 |
---|---|---|
fontFilePath | String | 字体文件路径。 |
metricsFilePath | String | 字体度量文件路径。 |
返回值
字体对象。
例子
示例演示如何打开Type1 字体,并替换第一页文本的字体。
// 打开字体
Font font = FontRepository.OpenFont("courier.pfb", "courier.afm");
// 打开文档
Document doc = new Document(@"D:\Tests\input.pdf");
// 创建 TextFragmentAbsorber 对象以查找所有“hello world”文本出现
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
// 接受第一页的吸收器
doc.Pages[1].Accept(absorber);
// 更改第一个文本出现的字体
absorber.TextFragments[1].TextState.Font = font;
// 保存文档
doc.Save(@"D:\Tests\output.pdf");
也可以看看
- class Font
- class FontRepository
- 命名空间 Aspose.Pdf.Text
- 部件 Aspose.PDF