2016-08-12 71 views
0

由於我的語言中有一些特殊字符,我需要將字體嵌入到PDF文件中。我讀了很多有關FOP的網頁,我想通了,我需要這樣的配置文件:Maven pdf插件:在哪裏把userconfig.xml

<?xml version="1.0"?> 
<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> 

可惜的是,當我運行mvn PDF格式:PDF -X,我看行

[DEBUG] userconfig is null 

哪看起來像配置被加載。我應該在哪裏放置配置文件,以及如何告訴pdf插件,在哪裏看?

回答

1

我發現了溶劑,但我仍然不相信它是理想的。我使用了Exec Maven Plugin,並使用Maven Pdf Plugin創建的結果運行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插件複製到目標中。