dima618
dima618

Reputation: 87

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

I am using docfx to create documentation for a library. I have docfx installed as a NuGet package for visual studio and I would like to create PDF documentation from my solution. Every time I build the project, docfx throws an error that states

wkhtmltopdf is a prerequisite when generating PDF. Please install it from https://wkhtmltopdf.org/downloads.html and save the executable folder to %PATH% first. Alternatively you can install it from https://chocolatey.org with choco install wkhtmltopdf.

I have wkhtmltopdf downloaded and added to PATH.

I have the JSON file configured to create a PDF document, and a toc.yml file inside a folder called pdf.

JSON file:

{
  "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 file:

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

My library solution folder structure:

|- _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)

I am expecting a _site_pdf folder to be created upon building the solution, but I am receiving an error stating that wkhtmltopdf is missing, even though it is installed and added to path. I suspect the issue is with either my toc or JSON file but I have very little experience with either so I cannot find the issue.

Upvotes: 1

Views: 1823

Answers (1)

Sachin Tanwar
Sachin Tanwar

Reputation: 11

You will have to add below section in your docfx.json under "pdf" section.

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

Upvotes: 1

Related Questions