211 Star 1.6K Fork 391

dromara / x-easypdf

 / 详情

求助,fop模块怎么使用本地的字体文件作为字体呢。急!!!

待办的
创建于  
2023-12-21 10:19

最新版

评论 (4)

iven98 创建了任务
iven98 修改了描述
展开全部操作日志

可参考如下配置:

<?xml version="1.0"?>

<!-- NOTE: This is the version of the configuration -->
<fop version="1.0">

    <!-- Base URL for resolving relative URLs -->
    <base>.</base>

    <!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
    <source-resolution>72</source-resolution>
    <!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
    <target-resolution>72</target-resolution>

    <!-- Default page-height and page-width, in case value is specified as auto -->
    <default-page-settings width="21cm" height="29.7cm"/>

    <!-- Information for specific renderers -->
    <!-- Uses renderer mime type for renderers -->
    <renderers>
        <renderer mime="application/pdf">
            <version>1.5</version>
            <filterList>
                <!-- provides compression using zlib flate (default is on) -->
                <value>flate</value>
            </filterList>

            <fonts>
                <!-- auto-detect fonts -->
                <auto-detect/>
                <!-- custom fonts-->
                <font kerning="yes"
                      simulate-style="true"
                      embed-url="org/dromara/pdf/fop/font/SourceHanSerifSC-Regular.otf">
                    <font-triplet name="思源宋体" style="normal" weight="100"/>
                    <font-triplet name="思源宋体" style="normal" weight="200"/>
                    <font-triplet name="思源宋体" style="normal" weight="300"/>
                    <font-triplet name="思源宋体" style="normal" weight="400"/>
                    <font-triplet name="思源宋体" style="normal" weight="500"/>
                    <font-triplet name="思源宋体" style="normal" weight="600"/>
                    <font-triplet name="思源宋体" style="normal" weight="700"/>
                    <font-triplet name="思源宋体" style="normal" weight="800"/>
                    <font-triplet name="思源宋体" style="normal" weight="900"/>
                    <font-triplet name="思源宋体" style="italic" weight="100"/>
                    <font-triplet name="思源宋体" style="italic" weight="200"/>
                    <font-triplet name="思源宋体" style="italic" weight="300"/>
                    <font-triplet name="思源宋体" style="italic" weight="400"/>
                    <font-triplet name="思源宋体" style="italic" weight="500"/>
                    <font-triplet name="思源宋体" style="italic" weight="600"/>
                    <font-triplet name="思源宋体" style="italic" weight="700"/>
                    <font-triplet name="思源宋体" style="italic" weight="800"/>
                    <font-triplet name="思源宋体" style="italic" weight="900"/>
                </font>
            </fonts>
        </renderer>
    </renderers>
</fop>

那如果采用对象模式该如何使用思源宋体哪?
使用地点
警告如下
警告
遍历字体文件夹

GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontName = environment.getAvailableFontFamilyNames();
        for (int i = 0; i < fontName.length; i++) {
            System.out.println(fontName[i]);
        }

部分结果如下
字体列表

使用自定义配置即可:
XEasyPdfTemplateDocument document = XEasyPdfTemplateHandler.Document.build().setConfigPath(configPath);

多谢 :smiley:

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(3)
1494292 xsxgit 1585187915
Java
1
https://gitee.com/dromara/x-easypdf.git
git@gitee.com:dromara/x-easypdf.git
dromara
x-easypdf
x-easypdf

搜索帮助