Created
January 4, 2018 22:03
-
-
Save jameswquinn/a77abfd1c2e60ad9b5531413b56b958b to your computer and use it in GitHub Desktop.
gulp recipe for html to pdf including icon font and images in base 64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pdf = require('gulp-html-pdf'); | |
| var replace = require('gulp-replace'); | |
| var inlineimg = require('gulp-inline-image-html'); | |
| var cssfont64 = require('gulp-cssfont64'); | |
| gulp.task('pdf',['font64'], function () { | |
| return gulp.src('HTML/Pages/*.html') | |
| .pipe(replace(/<link\b.+href="(?!http)([^"]*)".*>/g, function(s, filename) { | |
| var filepath = path.relative(__dirname , path.resolve(__dirname + '/HTML/css', filename)) | |
| var style = fs.readFileSync(filepath, 'utf8'); | |
| var icons = fs.readFileSync('font64/icons/icons.css', 'utf8'); | |
| return '<style>\n' + icons + '\n' + style + '\n</style>'; | |
| })) | |
| .pipe(inlineimg('HTML/Pages/')) | |
| .pipe(pdf()) | |
| .pipe(gulp.dest('PDF')); | |
| }); | |
| gulp.task('font64', function() { | |
| return gulp.src('HTML/Style Library/fonts/**/*.ttf') | |
| .pipe(cssfont64()) | |
| .pipe(gulp.dest('font64')) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment