10

I am using JS Doc version 3 (https://github.com/jsdoc3/jsdoc). When I run the tool, by default it generates documentation in HTML format. Is it possible to generate doc in PDF format?

Sai
  • 1,691
  • 1
  • 16
  • 26

3 Answers3

7

I would suggest you look at jsPDF. It is pretty cool and easy to use.

The code you download from the mentioned side contains reach examples.

What is jsPDF: A HTML5 client-side solution for generating PDFs. Perfect for event tickets, reports, certificates, you name it!

For example to generate pdf of html, just write following code.

var doc = new jsPDF();

// We'll make our own renderer to skip this editor
var specialElementHandlers = {
    '#editor': function(element, renderer){
        return true;
    }
};

// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('body').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers
});

This is a snapshot of the sample page jsPDF that you get in your download. It contains different example types, codes and pdf generation example.

enter image description here

maytham-ɯɐɥʇʎɐɯ
  • 21,551
  • 10
  • 85
  • 103
4

Currently there is no tool for converting jsdoc directly to PDF, but you can convert it to some intermediate format (markdown in this example), and then convert it to PDF:

  1. Install required tools

    $ npm install -g markdown-pdf
    $ npm install -g jsdoc-to-markdown
    
  2. Generate single markdown file with documentation

    $ jsdoc2md path/to/your/code/** > docs.md
    
  3. Convert markdown file to PDF:

    $ markdown-pdf docs.md
    

You can change how documentation looks using css stylesheets (here you can find an example stylesheet).

qzb
  • 6,363
  • 3
  • 18
  • 27
0

you got html files now, there are so many tools to convert html to pdf (i assume you use node.js)

Alongkorn Chetasumon
  • 2,575
  • 1
  • 20
  • 36