Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can JS Doc generate PDF

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?

like image 244
Sai Avatar asked Oct 11 '16 15:10

Sai


2 Answers

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

like image 53
Maytham Avatar answered Oct 25 '22 00:10

Maytham


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

like image 24
qzb Avatar answered Oct 24 '22 23:10

qzb