簡體   English   中英

在 Maven 構建期間從 Markdown 文件生成 PDF 文檔

[英]Generate PDF docs from Markdown files during the Maven build

我有一個帶有 Maven 裝配插件的 Java 項目。 組裝插件構建最終的 ZIP 發布文件,其中包含二進制 (*.war)、配置文件和一些 PDF 文檔。

The documents are written in Markdown and the PDF docs for the release need to be generated manually (ex. with Markdown to PDF online tool ) before I execute the build with Maven. 然后,Assembly 插件獲取 PDF 並將它們放入最終的 ZIP。

幾乎每次我創建發布 ZIP 文件時,我都忘記手動生成 PDF,因此通常最終的 ZIP 包含舊文檔。 這太糟糕了。

我想自動化 PDF 生成。 我已經檢查了四個 MD 到 PDF maven 插件,但它們都不能正常工作。 我找到了一個插件來生成 MD 到 HTML(沒有任何默認樣式表),也許我可以使用另一個插件將 HTML 轉換為 PDF,但它是如此痛苦。

我嘗試了什么:

有沒有什么簡單的方法可以在構建過程中基於 Markdown 文件生成帶有 Maven 的 PDF 文件?

通過這種方式,您可以在 linux 上生成 pdf,如果您還想在 Windows 上運行它,請添加配置文件並在構建時傳遞配置文件。

  <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>pandoc</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>                            
            </executions>
            <configuration>
                <executable>pandoc</executable>
                <workingDirectory></workingDirectory>
                <arguments>
                    <argument>-o</argument>
                    <argument>README.pdf</argument>
                    <argument>README.md</argument>
                </arguments>
            </configuration>
        </plugin>   
    </plugins>
</build>

跑步:

mvn 執行:執行

依賴項:

apt install -y pandoc texmaker

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM