pdf - 运行 gulp 任务“buildFonts”以导出带有 HTML 图标的 PDF 时出现问题
问题描述
我正在使用 WebForms 的 ASP NET 项目中使用 JQuery Datatables (v1.10.18)。 简洁起见,我正在尝试将表格导出为 PDF。它工作正常。我唯一的问题是,在某些表格中,有一些 HTML 图标,如“fa fa-check”,它们没有显示在 PDF 中。
值得一提的是我设置
stripHtml: false,
但是,我不能让它工作。步骤“运行 gulp buildFonts 以创建新的 build/vfs_fonts.js(您可以更新 gulpfile.js 以更改基本目录路径或为 buildFonts 任务添加替代配置)。” 给我带来了问题。
很高兴知道这是我第一次使用“gulp”,所以我通过我在网络上找到的示例以及 gulp 和 pdfmake 的文档来指导自己
我在文件夹“pdfmake-0.1.36”(包含导出为 PDF 所需的 pdfmake.js 和 vfs_fonts.js 脚本的文件夹)中定义了文件“gulpFile.js”。
然后,在 'gulpFile.js' 我定义:
const gulp = require('gulp');
const gulpFont = require('gulp-font');
gulp.task('buildFonts', function () {
console.log('starts');
gulp.src('/examples/fonts/.{ttf,otf}', { read: false })
.pipe(gulpFont({
ext: '.css',
fontface: '/examples/fonts/',
relative: '/examples/fonts/',
dest: '/examples/fonts/',
embed: ['woff'],
collate: false
}))
.pipe(gulp.dest('/examples/fonts/'));
console.log('finishes');
});
在“/examples/fonts/”中放置了“fontawesome”字体,我想用它来导出 HTML 图标。
然后,在 cmd 我转到特定文件夹并执行
gulp buildFonts
它打印出来
starts
finishes
The following tasks did not complete: buildFonts
Did you forget to signal async completion?
这个 gulps 任务应该在新文件夹“pdfmake-0.1.36/build/”中创建一个新的“vfs_fonts.js”,但它没有创建任何东西。
解决方案
const gulp = require('gulp');
const gulpFont = require('gulp-font');
gulp.task('buildFonts', async function () {
console.log('starts');
await gulp.src('/examples/fonts/.{ttf,otf}', { read: false })
.pipe(gulpFont({
ext: '.css',
fontface: '/examples/fonts/',
relative: '/examples/fonts/',
dest: '/examples/fonts/',
embed: ['woff'],
collate: false
}))
.pipe(gulp.dest('/examples/fonts/'));
console.log('finishes');
});
添加 async fo 函数并等待 gulp
推荐阅读
- nginx - nginx emerg SSL_CTX_load_verify_locations
- image - 本地图像以整数形式返回 - React Native
- ruby-on-rails - 调用活动记录对象时,如何根据某些条件返回不同的活动记录?
- jmeter - Chrome 驱动程序配置 - 如何动态设置代理端口?
- excel - 移动形状可见
- oracle - 将 Oracle 提示更改为变量
- mongodb - 如何使用 PyMongo 识别 MongoDB 文本索引
- javascript - 是否可以创建更改 about:config 设置的 Firefox WebExtension?如何?
- wolfram-mathematica - Maple 不将积分视为特殊函数
- android - Crashlytics 每次初始化时都会执行网络设置请求