Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including swagger-spec-to-pdf with all npm packages installed. Try it out:

var swaggerSpecToPdf = require("swagger-spec-to-pdf")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

swagger-spec-to-pdf v1.0.5

Dump swagger json spec into pdf document.


NPM version NPM downloads License


Please DO NOT install this module as a global module. Think this module as a small tool in your project. Install it locally, and use it locally. Several bugs related to global installation, and have not been fixed yet.


usage: swagger2pdf [-h] [-v] [-s SRC] [-o OUTPUT]

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  -s SRC, --src SRC     Swagger spec JSON file.
  -o OUTPUT, --output OUTPUT
                        Output path of the pdf file.


./bin/swagger2pdf -s ./swagger-spec-sample.json -o ./dump/
Wait several seconds


See: ./dump/swagger-spec-sample.pdf


Working Theory

  1. Read source swagger json spec
  2. Convert it into yaml format
  3. Dump yaml into the spec dir of swagger editor
  4. Use electron to render swagger editor page (nicely formatted api page)
  5. Dump the page into pdf

Swagger Editor

Version of swagger editor embedded is: 2.9.9
You can get it from: here
If you want to use some other version:

  • clone the repo
  • replace the editor in ./swagger-editor
  • Add codes below into the bottom of file swagger-editor/index.html
  • npm install .
<script type="text/javascript">
    $("document").ready(function() {
        setTimeout(function() {
            var fileMenuTimer = setInterval(function() {
                // open file menu
                var fileMenu = $("#fileMenu");
                if (fileMenu.length) {

                    // open example selector
                    var exampleButton = $("#open-example");
                    var exampleButtonTimer = setInterval(function() {
                        if (exampleButton.length) {

                            // click open button
                            setTimeout(function() {
                                $(".modal-large .btn-primary").click();
                            }, 1000);
                    }, 300);
            }, 300);
        }, 1000);

Done, just use it.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free