PDFサポート

ダイアグラムを直接PDF形式で出力する機能の要望が以前からありました。 しかし残念ながら、これは簡単なことではなく、いくつかの外部ライブラリ(BatikFOP)も必要でした。

これは、plantuml.jarが大きくなりすぎないようにして、他の製品との統合を容易にしたいという要望に反するものです。

そこで、ある種の動的リンクを利用して、これらのライブラリがなくてもコンパイルや実行が行えるようにしました。まず、SVGファイルが生成され、その後PDFに変換されます。

PDFエクスポート時には、影の描画について問題がある場合があります。それを無効化する方法が、こちらに書かれています。.

使用方法

デフォルト状態ではPDFの生成はできません。これでも、大多数のユーザのニーズを満たしているでしょう。

PDF機能を使いたい場合、以下のファイルをダウンロードする必要があります:

  • avalon-framework-4.2.0.jar
  • batik-all-1.7.jar
  • commons-io-1.3.1.jar
  • commons-logging-1.0.4.jar
  • fop.jar
  • xml-apis-ext-1.3.04.jar
  • xmlgraphics-commons-1.4.jar

これらのファイルをBatikFOPのウェブサイトからダウンロードします。

テストを目的として、これらのファイルをまとめたzipがこちらにあります。

これらのファイルは、plantuml.jarと同じフォルダに配置する必要があります。

以上の準備を行うと、コマンドラインで-tpdfフラグが使えるようになります:

java -jar plantuml.jar -tpdf diagram.txt

もしくは、Antタスクでformat="pdf"が使えます:

<!-- task definition -->
<taskdef name="plantuml" classname="net.sourceforge.plantuml.ant.PlantUmlTask" classpath="plantuml.jar" />
<!-- process diagram.txt file -->
<target name="images">
<plantuml format="pdf">
<fileset file="diagram.txt" />
</plantuml>
</target>

Installation of the new libraries on a Unix system

The following script will install the new libraries required to convert to PDF. It was tested on a Mac but should work as well on Linux:

#!/usr/bin/env bash

# These libraries will have to go in the same location where plantuml.jar is
PLANT_UML_WITH_PATH=$(awk '{for (i=1; i<=NF; i++) if ($i=="-jar") print $(i+1)}' "$(which plantuml)")
PLANT_UML_DIR=$(dirname "$PLANT_UML_WITH_PATH")

mapfile -t FILES_TO_REMOVE < <(find "$PLANT_UML_DIR" -type f ! -name "plantuml.jar")

if (( ${#FILES_TO_REMOVE[@]} == 0 )); then
    echo "No files to remove."
    #exit 0
else
    echo "The following files will be removed:"
    printf '%s\n' "${FILES_TO_REMOVE[@]}"

    read -p "Do you want to continue? (y/n) " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        find "$PLANT_UML_DIR" -type f ! -name "plantuml.jar" -delete
        echo "Files removed."
    else
        echo "Operation cancelled."
        exit 0
    fi
fi

# plantuml.jar uses these exact filenames in its manifest Class-Path.
curl -fL -o "$PLANT_UML_DIR/batik-all-1.7.jar" https://repo1.maven.org/maven2/org/apache/xmlgraphics/batik-all/1.17/batik-all-1.17.jar
#curl -fL -o "$PLANT_UML_DIR/batik-rasterizer-1.17.jar" https://repo1.maven.org/maven2/org/apache/xmlgraphics/batik-rasterizer/1.17/batik-rasterizer-1.17.jar
curl -fL -o "$PLANT_UML_DIR/fop.jar" https://repo1.maven.org/maven2/org/apache/xmlgraphics/fop-transcoder-allinone/2.9/fop-transcoder-allinone-2.9.jar
curl -fL -o "$PLANT_UML_DIR/xmlgraphics-commons-1.4.jar" https://repo1.maven.org/maven2/org/apache/xmlgraphics/xmlgraphics-commons/2.9/xmlgraphics-commons-2.9.jar
curl -fL -o "$PLANT_UML_DIR/commons-io-1.3.1.jar" https://repo1.maven.org/maven2/commons-io/commons-io/2.15.1/commons-io-2.15.1.jar
curl -fL -o "$PLANT_UML_DIR/commons-logging-1.0.4.jar" https://repo1.maven.org/maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
curl -fL -o "$PLANT_UML_DIR/xml-apis-ext-1.3.04.jar" https://repo1.maven.org/maven2/xml-apis/xml-apis-ext/1.3.04/xml-apis-ext-1.3.04.jar

ls -l "$PLANT_UML_DIR"/*.jar

echo "Script finished successfully."

Example to run the script and convert a file:

chmod +x download_pdf_conversion_libs.sh
./download_pdf_conversion_libs.sh
plantuml -tpdf file_to_convert.wsd


Privacy Policy      Advertise