Maven pdf plugin: Where to put userconfig.xml

536 views Asked by At

Due to some special characters in my language, I need to embed font into PDF file. I read a lot of pages about FOP, and I figured out I need configuration file like this:

<?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>

Unfortunatelly, when I run mvn pdf:pdf -X, I see line

[DEBUG] userconfig is null

Which looks like the config is loaded. Where should I put the configuration file and how I can tell the pdf plugin, where to look?

1

There are 1 answers

0
L. Kosina On

I found out the sollution, but still I am not convinced that it is ideal. I used Exec Maven Plugin and run the fop with the result created from Maven Pdf Plugin. The final solution looks like:

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 is stored in site/resources next to pdf-config.xml and it is copied into target by maven pdf plugin.