簡體   English   中英

使用 docfx 從 Visual Studio 生成 pdf 文檔拋出錯誤:“wkhtmltopdf 是生成 PDF 的先決條件”

[英]Generating pdf documentation from visual studio with docfx throws error: "wkhtmltopdf is a prerequisite when generating PDF"

我正在使用 docfx 為庫創建文檔。 我已將 docfx 安裝為 Visual Studio 的 NuGet 包,我想從我的解決方案創建 PDF 文檔。 每次我構建項目時,docfx 都會拋出一個錯誤,指出

wkhtmltopdf 是生成PDF 的前提條件。 請先從https://wkhtmltopdf.org/downloads.html安裝,然后將可執行文件夾保存到 %PATH%。 或者,您可以使用choco install wkhtmltopdfhttps://chocolatey.org安裝它。

我已經下載 wkhtmltopdf 並添加到 PATH。

我將 JSON 文件配置為創建一個 PDF 文檔,以及一個名為pdf的文件夾中的toc.yml文件。

JSON 文件:

{
  "metadata": [
    {
      "src": [
        {
          "files": [
            "*.csproj"
          ],
          "cwd": ".",
          "exclude": [
            "**/obj/**",
            "**/bin/**",
            "_site/**"
          ]
        }
      ],
      "dest": "obj/api"
    }
  ],
  "pdf": {
    "content": [
      {
        "files": [
          "api/**.yml"
        ],
        "exclude": [
          "**/toc.yml",
          "**/toc.md"
        ]
      },
      {
        "files": [
          "articles/**.md",
          "articles/**/toc.yml",
          "toc.yml",
          "*.md",
          "pdf/*"
        ],
        "exclude": [
          "**/bin/**",
          "**/obj/**",
          "_site_pdf/**",
          "**/toc.yml",
          "**/toc.md"
        ]
      },
      {
        "files": "pdf/toc.yml"
      }
    ],
    "resource": [
      {
        "files": [
          "images/**"
        ],
        "exclude": [
          "**/bin/**",
          "**/obj/**",
          "_site_pdf/**"
        ]
      }
    ],
    "overwrite": [
      {
        "files": [
          "apidoc/**.md"
        ],
        "exclude": [
          "**/bin/**",
          "**/obj/**",
          "_site_pdf/**"
        ]
      }
    ],
    "dest": "_site_pdf"
  }
}

toc.yml文件:

- name: Articles
  href: ../articles/toc.yml
- name: Api Documentation
  href: ../api/toc.yml

我的庫解決方案文件夾結構:

|- _site
|- api
   |- index.yml
|- articles
   |- intro.md
   |- toc.md
|- pdf
   |- toc.yml
|- docfx.json
|- toc.yml
|- index.yml
(Other visual studio solution files are in this folder)

我期望在構建解決方案時創建一個 _site_pdf 文件夾,但我收到一個錯誤,指出 wkhtmltopdf 丟失,即使它已安裝並添加到路徑中。 我懷疑問題出在我的 toc 或 JSON 文件上,但我對這兩者的經驗都很少,所以我找不到問題。

您必須在“pdf”部分下的 docfx.json 中添加以下部分。

"wkhtmltopdf": {
  "additionalArguments": "--enable-local-file-access"
},

暫無
暫無

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

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