我正在使用JS Doc 3版本(https://github.com/jsdoc3/jsdoc)。运行该工具时,默认情况下会生成HTML格式的文档。是否可以生成PDF格式的文档?
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
});
目前没有直接将jsdoc转换为PDF的工具,但您可以将其转换为某些中间格式(例如这里使用markdwon),然后将其转换为PDF:
Install required tools
$ npm install -g markdown-pdf
$ npm install -g jsdoc-to-markdown
Generate single markdown file with documentation
$ jsdoc2md path/to/your/code/** > docs.md
Convert markdown file to PDF:
$ markdown-pdf docs.md
您可以使用CSS样式表(这里有一个示例样式表)来更改文档的外观。
你现在有HTML文件了,有很多工具可以将HTML转换为PDF(我假设你使用Node.js)。