2017-01-24 84 views
0

我需要将现有的ASP.NET MVC Web应用程序转换为Node.JS. 这个现有的.net应用程序有一个生成PDF报告的选项,并设计和生成使用Active Reports for .NET的报告。在Node.js/express Web应用程序中生成PDF报告

我想知道在Node.js/Express Web应用程序中设计和生成PDF报告有哪些选项。

+0

jspdf是一个选项。 https://github.com/MrRio/jsPDF/ – bgth

回答

0

有很多库将html转换为PDF。其中之一是PhantomJS。您可以使用他们的示例rasterize.js来创建PDF。

棘手的部分是让它与NodeJS一起工作。 NodeJs的运行方式与PhantomJs不同。一种解决方案可能是phantomjs-node。你可以做这样的事情example

const phantom = require('phantom'); 

(async function() { 
    const instance = await phantom.create(); 
    const page = await instance.createPage(); 

    await page.property('viewportSize', {width: 1024, height: 600}); 
    const status = await page.open('https://stackoverflow.com/'); 
    console.log(`Page opened with status [${status}].`); 

    await page.render('stackoverflow.pdf'); 
    console.log(`File created at [./stackoverflow.pdf]`); 

    await instance.exit(); 
}()); 

// node --harmony-async-await render.js 

注意你需要节点7使用上面的例子。

声明:我是phantomjs-node的作者。