Skip to content

Instantly share code, notes, and snippets.

@jameswquinn
Created January 4, 2018 22:03
Show Gist options
  • Select an option

  • Save jameswquinn/a77abfd1c2e60ad9b5531413b56b958b to your computer and use it in GitHub Desktop.

Select an option

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
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