能否使用JS Doc生成PDF文件?

12
我正在使用JS Doc 3版本(https://github.com/jsdoc3/jsdoc)。运行该工具时,默认情况下会生成HTML格式的文档。是否可以生成PDF格式的文档?

2
在你有HTML后,通过http://wkhtmltopdf.org/将它们运行。 - Zoltan Toth
这是http://stackoverflow.com/questions/4014280/jsdoc-to-pdf-renderer提出的解决方案。 - krampstudio
不,单独使用是不行的。像@ZoltanToth建议的那样,使用wkhtmltopdf。 - Aniket Sinha
3个回答

8
我建议你看看jsPDF。它非常酷,易于使用。 从提到的网站下载的代码包含丰富的示例。
引用: 什么是jsPDF:用于生成PDF的HTML5客户端解决方案。非常适合活动门票、报告、证书等!
例如,要生成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
});

这是您下载的jsPDF示例页面的快照。其中包含不同类型的示例、代码和PDF生成示例。

enter image description here


5

目前没有直接将jsdoc转换为PDF的工具,但您可以将其转换为某些中间格式(例如这里使用markdwon),然后将其转换为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
    

您可以使用CSS样式表(这里有一个示例样式表)来更改文档的外观。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接