zoukankan      html  css  js  c++  java
  • nodjs html 转 pdf

    var fs = require('fs');
    var pdf = require('html-pdf');//模块
    //读取html 文件
    var html = fs.readFileSync('./static.html', 'utf8');
    // 创建pdf
    var options = { format: 'Letter' };
    pdf.create(html, options).toFile('./export.pdf', function(err, res) {
    if (err) return console.log(err);
    console.log(res); // { filename: '/app/businesscard.pdf' }
    });


    // 如果需要导出 echart 图形
    //获取echart 对象
    var chart_pu= echarts.init(document.getElementById('chartid'));
    //获取 图形数据 包含渲染样式
    var chart_date=chart_pu.getDataURL();
    //将图形数据 作为img 的 src 路径写入html 文件
    var ws1 = fs.createWriteStream(__dirname+'/static_export.html', 'UTF-8');
    ws1.write('<div> <img src="'+chart_date+'"/></div>');

    ws1.end();
    //执行上面 导出步骤

  • 相关阅读:
    Dice 5 ==> dice 7
    Dice 7 ==> dice 5
    100 floors 2 eggs
    Determine overlapping rectangles
    Product of integers
    Maximum profit of stocks
    样式表
    20170508
    2017年05月07
    The second day of school
  • 原文地址:https://www.cnblogs.com/yydown/p/11129314.html
Copyright © 2011-2022 走看看