• 前端学习笔记:angular4中将html导出为pdf


    ngular5中将html导出为pdf
    1.安装pdfmake:
    npm install pdfmake --save
     

    2.在ts文件中导入:
    import * as pdfMake from 'pdfmake/build/pdfmake';
    import * as pdfFonts from 'pdfmake/build/vfs_fonts';
    3.测试pdfmake:
    pdfMake.vfs = pdfFonts.pdfMake.vfs;
    var dd = { content:{text:"HelloWorld!",alignment: 'center',};
    pdfMake.createPdf(dd).download();
     

    4.处理中文问题:
    a.找到需要的字体文件(后缀.ttf);

    b.将pdfmake的源代码克隆或下载到本地,(https://github.com/bpampuch/pdfmake);

    c.进入pdfmake根目录,安装gulp,使用命令为

    npm install gulp --save-dev;
    d.安装pdfmake所需要的依赖包,使用命令:

    npm install;
    e.将自己所需要的字体放在pdfmake目录下的examples/fonts的目录中;

    f.然后在执行:

    gulp buildFonts ;
    g.f步骤完成后会在build 文件夹中找到vfs_fonts.js

    h.用pdfmake项目中的vfs_fonts.js替换原来项目中的vfs_fonts.js

    5.使用字体:(以“微软雅黑”为例)
    pdfMake.fonts = {
        微软雅黑: {
            normal: '微软雅黑.ttf',
            bold: '微软雅黑.ttf',
            italics: '微软雅黑.ttf',
            bolditalics: '微软雅黑.ttf',
        }
    };
    var dd = { content:{text:"HelloWorld!",alignment: 'center',font: '微软雅黑'};
    pdfMake.createPdf(dd).download();
    6.其他操作可以参考官网
    https://juejin.im/

  • 相关阅读:
    ps cc 2018安装
    eclipse 快速添加 set , get 方法
    电脑设置以太网
    C# 获取web.config配置文件内容
    C# @Page指令中的AutoEventWireup,CodeBehind,Inherits
    未能正确加载“Microsoft.VisualStudio.Implementation.EditorPackage”包
    C# 实现MD5加密
    mutex 简单介绍
    select @@IDENTITY
    C# vs2012创建报表
  • 原文地址:https://www.cnblogs.com/ahu666/p/12850887.html
Copyright © 2020-2023  润新知