2017-01-24 89 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的作者。