Skip to content

Commit

Permalink
Print with Chrome headless
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeGak committed Oct 19, 2018
1 parent 8af0eac commit a8c1b98
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 173 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
To build the CV simply run:
Make sure you have installed:
- yarn
- Google Chrome

To build and print the CV simply run:

```console
yarn install
yarn build
yarn print
```

Caveats:
- The print script is macOS only.
14 changes: 3 additions & 11 deletions assets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ body {
}

@media print {
@page { margin: 0; }
@page {
margin: 0;
}

body {
width: $letter-width;
}

body.phantomjs-fix {
// XXX: PhantomJS 2 wrong size bug
// https://github.com/ariya/phantomjs/issues/12685#issuecomment-89452503
// zoom: 0.75;
}

.page {
margin: 0;
}
}


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"scripts": {
"build": "scripts/build.js"
"build": "scripts/build.js",
"print": "scripts/print.sh"
},
"dependencies": {
"gulp": "^3.9.1",
"html-pdf": "2.1.0",
"node-font-awesome": "^1.0.2",
"node-sass": "^3.13.0",
"nunjucks": "^3.0.0"
Expand Down
18 changes: 0 additions & 18 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var fontAwesome = require('node-font-awesome')
var gulp = require('gulp')
var nunjucks = require('nunjucks')
var path = require('path')
var pdf = require('html-pdf')
var sass = require('node-sass')


Expand Down Expand Up @@ -42,21 +41,4 @@ nunjucks.render('cv.njk', function handleNunjucksRender(err, res) {
var path = 'cv.html'
fs.writeFileSync(path, res)
console.log(path)
generatePdf(path)
})


// -- Generate PDF -------------------------------------------------------------

function generatePdf(htmlPath) {
var html = fs.readFileSync(htmlPath, 'utf8')
var options = {
format: 'Letter',
base: 'file://' + path.resolve(htmlPath)
}

pdf.create(html, options).toFile('cv.pdf', function handlePdfCreate(err, res) {
if (err) { return console.log(err) }
console.log(res)
})
}
3 changes: 3 additions & 0 deletions scripts/print.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
chrome --headless --disable-gpu --print-to-pdf=cv.pdf cv.html
Loading

0 comments on commit a8c1b98

Please sign in to comment.