FontRepository

遗产: java.lang.Object

public final class FontRepository

执行字体搜索。搜索系统安装的字体和标准 Pdf 字体。还提供打开自定义字体的功能。


The example demonstrates how to find font and replace the font of text of first page.
 
  
  //查找字体
  Font font = FontRepository.findFont("Arial");
  
  //打开文档
  Document doc = new Document("D:\\Tests\\input.pdf");
  //创建 TextFragmentAbsorber 对象以查找所有出现的“hello world”文本
  TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
  
  //接受第一页的吸收器
  doc.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont(font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

构造函数

构造函数描述
FontRepository()

方法

方法描述
addLocalFontPath(String path)再添加一条字体路径。
addSystemFont(Font font)添加指定字体的系统字体。
clear()
equals(Object arg0)
findFont(String fontName)搜索并返回具有指定字体名称的字体。
findFont(String fontName, boolean ignoreCase)搜索并返回具有指定字体名称的字体,忽略或区分大小写。
findFont(String fontFamilyName, int stl)搜索并返回具有指定字体名称和字体样式的字体。
findFont(String fontFamilyName, int stl, boolean ignoreCase)搜索并返回具有指定字体名称和字体样式的字体,忽略或区分大小写。
getClass()
getLocalFontPaths()带有实际字体目录的列表副本。
getSources()获取字体源集合。
getSubstitutions()获取字体替换策略集合。
hashCode()
isReplaceNotFoundFonts()未找到的字体将替换为标准字体。
isThreadStaticConfigEnabled()返回字体源存储配置的状态。
loadFonts()加载系统安装的字体和标准 Pdf 字体。
notify()
notifyAll()
openFont(InputStream fontStream, int fontType)使用指定的字体流打开字体。
openFont(String fontFilePath)打开具有指定字体文件路径的字体。
openFont(String fontFilePath, String metricsFilePath)打开具有指定字体文件路径和规格文件路径的字体。
reloadFonts()重新加载属性 Sources (#getSources.getSources)
restoreLocalFontPath()默认恢复标准字体目录列表。
setLocalFontPaths(List newFontPathsList)使用字体路径设置用户列表
setReplaceNotFoundFonts(boolean value)如果需要用默认字体替换未找到的字体,请设置为 TRUE。
setThreadStaticConfigEnabled(boolean isTheadLocal)用于设置字体源存储配置的选项。
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

FontRepository()

public FontRepository()

addLocalFontPath(String path)

public static void addLocalFontPath(String path)

再添加一条字体路径。

参数:

范围类型描述
pathjava.lang.String字符串值

addSystemFont(Font font)

public static void addSystemFont(Font font)

添加指定字体的系统字体。


The example demonstrates how to add system font.

  InputStream fontStream = new FileInputStream("C:\\WINDOWS\\Fonts\\arial.ttf"))

  Font font = FontRepository.openFont(fontStream, FontTypes.TTF);

  FontRepository.addSystemFont(font);

参数:

范围类型描述
fontFont字体实例

clear()

public static void clear()

equals(Object arg0)

public boolean equals(Object arg0)

参数:

范围类型描述
arg0java.lang.Object

退货: 布尔值

findFont(String fontName)

public static Font findFont(String fontName)

搜索并返回具有指定字体名称的字体。


The example demonstrates how to find font and replace the font of text of first page.
 
  //查找字体
  Font font = FontRepository.findFont("Arial");
  
  //打开文档
  Document doc = new Document("D:\\Tests\\input.pdf");
  //创建 TextFragmentAbsorber 对象以查找所有出现的“hello world”文本
  TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
  
  //接受第一页的吸收器
  doc.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont ( font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontNamejava.lang.String字体名称。

退货: Font - 字体对象。

findFont(String fontName, boolean ignoreCase)

public static Font findFont(String fontName, boolean ignoreCase)

搜索并返回具有指定字体名称的字体,忽略或区分大小写。


The example demonstrates how to find font and replace the font of text of first page.
 
  //查找字体
  Font font = FontRepository.findFont("Arial", FontStyles.Italic);
  
  //打开文档
  Document doc = new Document("D:\\Tests\\input.pdf");
  //创建 TextFragmentAbsorber 对象以查找所有出现的“hello world”文本
  TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
  
  //接受第一页的吸收器
  doc.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont(font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontNamejava.lang.String字体名称。
ignoreCaseboolean区分大小写

退货: Font - 字体对象。

findFont(String fontFamilyName, int stl)

public static Font findFont(String fontFamilyName, int stl)

搜索并返回具有指定字体名称和字体样式的字体。


The example demonstrates how to find font and replace the font of text of first page.
 
  //查找字体
  Font font = FontRepository.findFont("Arial", FontStyles.Italic);
  
  //打开文档
  Document doc = new Document("D:\\Tests\\input.pdf");
  //创建 TextFragmentAbsorber 对象以查找所有出现的“hello world”文本
  TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
  
  //接受第一页的吸收器
  doc.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont(font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontFamilyNamejava.lang.String字体系列名称。
stlint字体样式值。

退货: Font - 搜索请求参数对应的字体对象。

findFont(String fontFamilyName, int stl, boolean ignoreCase)

public static Font findFont(String fontFamilyName, int stl, boolean ignoreCase)

搜索并返回具有指定字体名称和字体样式的字体,忽略或区分大小写。


The example demonstrates how to find font and replace the font of text of first page.
 
  //查找字体
  
  Font font = FontRepository.findFont("Arial", FontStyles.Italic, true);
  
  //打开文档
  Document doc = new Document("D:\\Tests\\input.pdf");
  //创建 TextFragmentAbsorber 对象以查找所有出现的“hello world”文本
  TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
  
  //接受第一页的吸收器
  doc.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont(font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontFamilyNamejava.lang.String字体系列名称。
stlint字体样式值。
ignoreCaseboolean区分大小写

退货: Font - 搜索请求参数对应的字体对象。

getClass()

public final native Class<?> getClass()

退货: java.lang.Class

getLocalFontPaths()

public static List<String> getLocalFontPaths()

带有实际字体目录的列表副本。

退货: java.util.List<java.lang.String> - 字符串列表

getSources()

public static FontSourceCollection getSources()

获取字体源集合。

退货: FontSourceCollection FontSourceCollection 对象

getSubstitutions()

public static FontSubstitutionCollection getSubstitutions()

获取字体替换策略集合。

退货: FontSubstitutionCollection FontSubstitutionCollection 对象

hashCode()

public native int hashCode()

退货: 整数

isReplaceNotFoundFonts()

public static boolean isReplaceNotFoundFonts()

未找到的字体将替换为标准字体。

退货: boolean - 布尔值

isThreadStaticConfigEnabled()

public static boolean isThreadStaticConfigEnabled()

返回字体源存储配置的状态。 如果为真,则使用 ThreadStatic 并且每个线程都有自己的字体源。 如果为 false,则对所有线程使用全局静态配置。


默认值为真。

退货: boolean - 布尔值

loadFonts()

public static void loadFonts()

加载系统安装的字体和标准 Pdf 字体。此方法旨在加快字体加载过程。默认情况下,在首次请求任何字体时加载字体。使用此方法会在打开任何 Pdf 文档之前立即加载系统和标准 Pdf 字体。

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

openFont(InputStream fontStream, int fontType)

public static Font openFont(InputStream fontStream, int fontType)

使用指定的字体流打开字体。


The example demonstrates how to open font and replace the font of text of first page.
  
  //打开字体
  InputStream fontStream = new FileInputStream("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.getPages().get_Item(1).accept(absorber);
  
      //更改第一个文本出现的字体
      absorber.getTextFragments().get_Item(1).getTextState().setFont ( font);
  
      //保存文件
      doc.save("D:\\Tests\\output.pdf"); 
  }

参数:

范围类型描述
fontStreamjava.io.InputStream字体流。
fontTypeint字体类型值。

退货: Font - 字体对象。

openFont(String fontFilePath)

public static Font openFont(String fontFilePath)

打开具有指定字体文件路径的字体。


The example demonstrates how to open font and replace the font of text of first page.
 
  //打开字体
  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.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).getTextState().setFont ( font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontFilePathjava.lang.String字体文件路径。

退货: Font - 字体对象。

openFont(String fontFilePath, String metricsFilePath)

public static Font openFont(String fontFilePath, String metricsFilePath)

打开具有指定字体文件路径和规格文件路径的字体。


The example demonstrates how to open Type1 font with metrics and replace the font of text of first page.
  
  //打开字体
  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.getPages().get_Item(1).accept(absorber);
  
  //更改第一个文本出现的字体
  absorber.getTextFragments().get_Item(1).sgetTextState().setFont(font);
  
  //保存文件
  doc.save("D:\\Tests\\output.pdf");

参数:

范围类型描述
fontFilePathjava.lang.String字体文件路径。
metricsFilePathjava.lang.String字体规格文件路径。

退货: Font - 字体对象。

reloadFonts()

public static void reloadFonts()

重新加载属性 Sources (#getSources.getSources)

restoreLocalFontPath()

public static void restoreLocalFontPath()

默认恢复标准字体目录列表。

setLocalFontPaths(List newFontPathsList)

public static void setLocalFontPaths(List<String> newFontPathsList)

使用字体路径设置用户列表

参数:

范围类型描述
newFontPathsListjava.util.List<java.lang.String>列表对象

setReplaceNotFoundFonts(boolean value)

public static void setReplaceNotFoundFonts(boolean value)

如果需要用默认字体替换未找到的字体,请设置为 TRUE。默认值为假。

参数:

范围类型描述
value布尔值boolean

setThreadStaticConfigEnabled(boolean isTheadLocal)

public static void setThreadStaticConfigEnabled(boolean isTheadLocal)

用于设置字体源存储配置的选项。 如果为真,则使用 ThreadStatic 并且每个线程都有自己的字体源。 如果为 false,则对所有线程使用全局静态配置。

参数:

范围类型描述
isTheadLocalboolean布尔值

toString()

public String toString()

退货: java.lang.字符串

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

参数:

范围类型描述
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

参数:

范围类型描述
arg0long
arg1int