我找到了解决方案,但我仍然不相信它是理想的。我使用了 Exec Maven 插件并使用 Maven Pdf 插件创建的结果运行 fop。最终解决方案如下所示:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.kosina</groupId>
<artifactId>pdf-generate</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PDF generation</name>
<repositories />
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
<version>1.3</version>
<configuration>
<locales>cs_CZ</locales>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.apache.fop.cli.Main</mainClass>
<arguments>
<argument>-fo</argument>
<argument>.\target\pdf\maven-pdf-plugin.fo</argument>
<argument>-c</argument>
<argument>.\target\pdf\fop.xconf</argument>
<argument>file.pdf</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</project>
fop.xconf:
<?xml version="1.0" encoding="UTF-8"?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="file:///C:/windows/fonts/arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal" />
</font>
</fonts>
</renderer>
</renderers>
</fop>
fop.xconf 存储在 pdf-config.xml 旁边的站点/资源中,并由 maven pdf 插件复制到目标中。