12

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
  • 2,089
  • 3
  • 19
  • 30

3 Answers3

8

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 Fahmi
  • 31,138
  • 14
  • 118
  • 137
5

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
  • 8,163
  • 3
  • 21
  • 27
0

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

Alongkorn
  • 3,968
  • 1
  • 24
  • 41