UPDATE from phantomjs to electroshot

This commit is contained in:
unpregnant 2017-02-05 17:57:23 +01:00
parent 7351c79953
commit a619a5017e
13 changed files with 22 additions and 50 deletions

View File

@ -6,11 +6,6 @@
@darkgrey: #343444;
@main: #E77171;
html {
zoom: 0.75;
-webkit-text-size-adjust: auto;
}
body {
background: @background;
font-family: 'Open Sans', sans-serif;

View File

@ -24,6 +24,7 @@
"@typopro/web-montserrat": "^3.4.9",
"buffer-to-string": "^0.1.0",
"clean-css": "^4.0.4",
"electroshot": "^1.2.0",
"express": "^4.14.1",
"font-awesome": "^4.7.0",
"fs": "0.0.1-security",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -128,22 +128,24 @@
font-size: @fontSize;
.skill-block {
display: flex;
padding-bottom: 10px;
display: inline-block;
.skill {
width: 100px;
color: #616161;
float: left;
}
.skill-bar {
float: right;
background: #E0E0E0;
overflow: hidden;
height: 8px;
flex: 1;
border-radius: 3px;
margin-top: 6.5px;
position: relative;
width: 249px;
.level {
background: #757575;

View File

@ -83,6 +83,7 @@
background: url('person.jpg');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 200px;
width: 200px;
border-radius: 50%;

View File

@ -11,12 +11,8 @@
<body>
{{>content}}
<script>
var userAgent = navigator.userAgent;
if (userAgent.indexOf('PhantomJS') < 0) document.getElementsByTagName('html')[0].style['zoom'] = 1;
</script>
</body>
</html>

View File

@ -3,7 +3,7 @@ const Mustache = require('mustache');
const pdf = require('html-pdf');
const fs = require('fs');
const path = require('path');
var exec = require('child_process').exec;
const dir = path.join(__dirname, '../resumes');
const directories = getDirectories(dir);
@ -12,43 +12,20 @@ function getDirectories(srcpath) {
.filter(file => file.includes('resume-'))
}
function readFileContent(fileName) {
const dir = path.join(__dirname, '../resumes/' + fileName);
return new Promise((res, rej) => {
fs.readFile(dir, 'utf8', (err, template) => {
if (err) rej(err);
else res(template);
});
});
}
function generatePdf(html, fileName) {
const dir = path.join(__dirname, '../pdf/' + fileName);
return new Promise((resolve, rej) => {
pdf.create(html, {
'type': 'pdf',
'format': 'A4',
'base': 'http://localhost:3000'
}).toFile(dir, function(err, res) {
if (err) rej(err);
else resolve();
});
});
}
async function convertToPdf() {
const layoutTemplate = await readFileContent('views/layout.mustache');
for (let resume of directories) {
const resumeTemplate = await readFileContent(resume + '/' + resume + '.mustache');
const html = Mustache.render(
layoutTemplate, {
person: person
}, {
content: resumeTemplate
});
await generatePdf(html, resume + '.pdf');
}
console.log('Generated resumes into /pdf.');
let script = '';
let dir = path.join(__dirname, '../pdf');
directories.forEach(async(resume) => {
script += 'electroshot localhost:3000/' + resume +
' 2481x3508 --pdf-margin none --format pdf --out ' + dir +
' --filename "' + resume + '.pdf" --pdf-background; ';
});
script = script.substring(0, script.length - 2);
exec(script,
(error, stdout, stderr) => {
if (error) console.log(error);
else console.log(stderr);
});
}
convertToPdf();